 |
| Author |
Message |
|
|
Posted: Apr 22, 2012 - 11:28 AM |
|

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 |
|
|
| |
|
|
|
|
|
Posted: Apr 22, 2012 - 11:44 AM |
|


Joined: Mar 27, 2002
Posts: 18599
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). |
|
|
| |
|
|
|
|
|
Posted: Apr 22, 2012 - 11:55 AM |
|

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. |
|
|
| |
|
|
|
|
|
Posted: Apr 22, 2012 - 05:27 PM |
|


Joined: Sep 04, 2002
Posts: 21276
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
|
| |
|
|
|
|
|
|
|