Author Topic: atmega8 port programming  (Read 13028 times)

0 Members and 1 Guest are viewing this topic.

Offline pomprockerTopic starter

  • Supreme Robot
  • *****
  • Posts: 1,431
  • Helpful? 16
  • Sorry miss, I was giving myself an oil-job.
    • Nerdcore - Programming, Electronics, Mechanics
atmega8 port programming
« on: July 13, 2008, 07:35:59 PM »
How would you change a pin on portc from analog input to digital i/o on an atmega8 using C programming (avrlib/winavr)?



Offline bens

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 335
  • Helpful? 3
Re: atmega8 port programming
« Reply #1 on: July 13, 2008, 07:49:22 PM »
The port C pins are digital I/Os (you don't have to do anything special to use them as such).  It just so happens that you can also internally connect them to the mega8's ADC.  For example, it's possible to use the ADC to read the analog voltage on pin PC0 while using PC0 as a digital output.  The result probably wouldn't be very interesting or useful, but you could do it.

So in short, if you want to use the pins on port C as digital I/Os, do the same thing you'd do for the pins on port D or port B.  If you want to use them as analog inputs, set them as digital inputs and configure the ADC module appropriately.

- Ben

Offline pomprockerTopic starter

  • Supreme Robot
  • *****
  • Posts: 1,431
  • Helpful? 16
  • Sorry miss, I was giving myself an oil-job.
    • Nerdcore - Programming, Electronics, Mechanics
Re: atmega8 port programming
« Reply #2 on: July 13, 2008, 08:01:57 PM »
I didn't mention this but I'm fairly new to this, and I'm starting from the $50 robot code where I believe the C ports are set to analog inputs, so i want to set just ONE of those pins to digital I/O because I am trying to interface the parallax ping sonar which operates using PWM which is digital right?



Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,703
  • Helpful? 173
    • Society of Robots
Re: atmega8 port programming
« Reply #3 on: July 20, 2008, 09:14:39 AM »
This was meant for the Axon, but its almost exactly the same:
http://www.societyofrobots.com/robotforum/index.php?topic=4536.0
http://www.societyofrobots.com/axon/axon_function_list.shtml#digital_input
(that will make a digital input, but if you turn off the pull-up, it will be an output)

Look at SoR_Utils.h in the Axon source code:
http://www.societyofrobots.com/axon/downloads/Axon_Source_070408.zip

and read the comments for port configuration.

Let us know if its still confusing after reading through this material.

 


data_list