Tuesday, May 31, 2011

A Simple Sample Code!

The code below can turn on a LED connected to pin4 of PORTB which means PB4. I found it very promising and encouraging as a starting point in both OS (Windows and Ubuntu).

#include

int main (void)
{
PORTB = 0x10; // Toggle the LED
DDRB = 0x10; // Set LED as output
return 0;
}

PORTB is an 8 bits register that represent the port B in ATmega128. to have 1 in fifth bit which stands for PB4 (start from 0), I put 0x10 in hex that is equal to 16 in decimal and 0b00010000 in binary. All of them give you same result. Have fun :)




No comments:

Post a Comment