User Tools

Site Tools


2011:arduino_to_avr_pin_mapping

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
2011:arduino_to_avr_pin_mapping [2011/08/07 10:15] tomgee2011:arduino_to_avr_pin_mapping [2011/10/14 09:34] (current) tomgee
Line 4: Line 4:
  
 {{:2011:arduino_pro-3.jpg|}}\\ {{:2011:arduino_pro-3.jpg|}}\\
 +
 +
 +
 + 
 +
 +
 +
 +
 +Using Port C as digital output (Read 1072 times)
 +
 +
 +Using Port C as digital output
 +03.02.2010 at 16:14:06  
 +
 +It took me a bit of time to extract this info from the docs and the board itself, so I thought I'd post it here so any searchers in the future will get there quicker.
 +
 +This is for the Duemilanove
 +
 +   //Using Port C as digital output
 +
 +In your setup:
 +   // Turn analog inputs to digital outputs
 +   DDRC=0xFF ; // These will be pin numbers 14 .. 19
 +
 +
 +In your loop:
 +   digitalWrite (14, HIGH);  
 +   // ...etc...  
 +   digitalWrite (19, LOW);  
 +Back to top
 + 
 + 
 +View Profile   IP Logged
 +Groove
 +God Member
 +*****
 +
 +Re: Using Port C as digital output
 +Reply #1 - 03.02.2010 at 16:20:51  
 +I don't think there's any need for anything in setup, it's all already done by digitalRead/digitalWrite when you specify the correct pin numbers.
 +Back to top
 + 
 + 
 +View Profile   IP Logged
 +TBAr
 +Senior Member
 +****
 +Offline
 +
 +
 +
 +Posts: 388
 +
 +
 +Re: Using Port C as digital output
 +Reply #2 - 03.02.2010 at 18:54:04  
 +That's true as long as you initialize the pins to OUTPUT before you use digitalWrite().
 +
 + pinMode(14, OUTPUT);
 + pinMode(19, OUTPUT);
 +
 +That's traditionally done in setup().
 +Back to top
 + 
 + 
 +View Profile   IP Logged
 +BenF
 +God Member
 +*****
 +Offline
 +
 +Arduino rocks
 +
 +Posts: 760
 +
 +
 +Re: Using Port C as digital output
 +Reply #3 - 03.02.2010 at 20:09:14  
 +Quote:
 +// Turn analog inputs to digital outputs
 +  DDRC=0xFF ; // These will be pin numbers 14 .. 19
 +
 +The DDRC register determines data direction (input or output) for port-C. 
 +Setting all bits to one (as in your code) will configure the pins for output. It 
 +is not related to switching between analog/digital (no command is needed for 
 +this).
 +
 +Port C includes the RESET pin on PC6 and an undefined pin on PC7. PC0 thru PC5 
 +map to Arduino A0 (14) thru to A5 (19). Forcing RESET to become an output pin 
 +(as would be the case with your statement)  is not something you want to do 
 +unless the ATmega chip is refused to disable/ignore RESET. Also it is not good 
 +practice to force an undefined pin (A7) to any value - rather you should leave 
 +it as is (DDRC|=0x3f would be ok).
 +
 + 
 + 
 +View Profile   IP Logged
 +oransen
 +YaBB Newbies
 +*
 +Offline
 +
 +Arduino rocks
 +
 +Posts: 22
 +
 +
 +Re: Using Port C as digital output
 +Reply #4 - 04.02.2010 at 07:07:14  
 +So, I should actually do:
 +
 + // Turn analog inputs to digital outputs
 + DDRC=0x3F ; // These will be pin numbers 14 .. 19
 +
 +is that right?
 +
 +I posted this because I could not find any clear examples of using these pins.
 +
 +And you say:
 +
 +"PC0 thru PC5 map to Arduino A0 (14) thru to A5 (19)."
 +
 +which I understand, but what is the advised way of naming these pins. 14 ... 19. I can't find the C define for "A0" or PC0.
 +
 +Back to top
 + 
 + 
 +View Profile   IP Logged
 +BenF
 +God Member
 +*****
 +Offline
 +
 +Arduino rocks
 +
 +Posts: 760
 +
 +
 +Re: Using Port C as digital output
 +Reply #5 - 04.02.2010 at 08:17:14  
 +The Arduino way would be as follows:
 +Code:
 +
 +  pinMode(14,OUTPUT); // configure A0 for output
 +  digitalWrite(14,HIGH); // set PORTC pin 0 high
 + 
 +
 +
 +
 +
 +Direct PORT IO is as follows:
 +Code:
 +
 +  DDRC |= _BV(PORTC0); // configure A0 for output
 +  PORTC |= _BV(PORTC0); // set PORTC pin 0 high
 + 
 +
 +
 +
 +Back to top
 + 
 + 
 +View Profile   IP Logged
 +Pages: 1
 +Send Topic | Print
 +Arduino Forum › Hardware › Interfacing
 + ‹ Previous Topic | Next Topic ›
 +
 +Arduino Forum » Powered by YaBB 2.2.3!
 +YaBB © 2000-2008. All Rights Reserved.
 +
 +Valid RSS Valid XHTML Valid CSS Powered by Perl Source Forge
 +
 +
 +
2011/arduino_to_avr_pin_mapping.1312726552.txt.gz · Last modified: 2011/08/07 10:15 by tomgee