/* I/O PORT B, DATA DIRECTION REGISTER (0 -> in, 1 -> out) */ #define DDRB (*(volatile unsigned char *)(0x17 + 0x20)) /*#define DDRB (*(volatile unsigned char *)(0x04 + 0x20))*/ /*for ATMEGA328p*/ /* I/O PORT B, DATA REGISTER */ #define PORTB (*(volatile unsigned char *)(0x18 + 0x20)) /*#define PORTB (*(volatile unsigned char *)(0x05 + 0x20))*/ /*for ATMEGA328p*/ void delay() { unsigned int count = 0xffff; asm volatile ("1: sbiw %0,1 \n" " brne 1b \n" : "=w"(count) : "0"(count)); } int main(void) { /* Set the whole port (all bits) to "output" */ DDRB = 0xff; while(1) { /* Turn on all leds connected to port B */ PORTB = 0x00; /* Delay */ delay(); /* Turn off all leds connected to port B */ PORTB = 0xff; /* Delay */ delay(); } return 0; }