Forum Menu




 


Log in Problems?
New User? Sign Up!
AVR Freaks Forum Index

Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Author Message
unwrittenovel
PostPosted: Apr 22, 2012 - 11:28 AM
Newbie


Joined: Apr 22, 2012
Posts: 5


hey there im new to ATMEGA programming( C language) so, i would like to kno how do you define ports in ATMEGA (like it was P2^1, P2^3 etc in 8051)....

thank you
 
 View user's profile Send private message  
Reply with quote Back to top
JohanEkdahl
PostPosted: Apr 22, 2012 - 11:44 AM
10k+ Postman


Joined: Mar 27, 2002
Posts: 18585
Location: Lund, Sweden

It would depend slightly on the compiler.

E.g. for the avr-gcc compiler (that comes with AVR Studio) there are part-specific include files that gets included if you do

#include <avr/io.h>

and have the correct AVR model selected (in e.g. AVR Studio).
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
MBedder
PostPosted: Apr 22, 2012 - 11:55 AM
Raving lunatic


Joined: Nov 02, 2009
Posts: 3239
Location: Zelenograd, Russia

For WinAVR (GCC) look here. In CodeVision AVR the bits can be accessed as PORTB.3, PORTD.7 etc.
 
 View user's profile Send private message  
Reply with quote Back to top
bobgardner
PostPosted: Apr 22, 2012 - 05:27 PM
10k+ Postman


Joined: Sep 04, 2002
Posts: 21272
Location: Orlando Florida

In any other ansi c compiler, just read the PIN register, use the AND and OR c bit operators to isolate the bit you want, then test for 0 or not 0. Eaxmple: MySwitchIsPressed = (PINB & 0x03)==0; if(PowerIsOn) PORTD |= 0x04; else PORTD &= ~0x04; If its easier to remember the bit number rather than the bit mask, you can use the expression (1 << bitposition) as a memory jogger. Doesnt add any instructions.

_________________
Imagecraft compiler user
 
 View user's profile Send private message Send e-mail Visit poster's website 
Reply with quote Back to top
Display posts from previous:     
Jump to:  
All times are GMT + 1 Hour
Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Powered by PNphpBB2 © 2003-2006 The PNphpBB Group
Credits