Its the first time i see this, i usually do
while(1) {}
Delay works fine but note that if you have any kind of interrupt then the delay stops, the interrupt code executes and then the delay resumes.
And
return 1 is not needed, actually you can safely use
void main(void)
Everything else seems to be fine.
There are some ways that make your work easier, i like these defines
Code:
#define SETBIT(ADDRESS,BIT) (ADDRESS |= (1<<BIT))
#define CLEARBIT(ADDRESS,BIT) (ADDRESS &= ~(1<<BIT))
#define FLIPBIT(ADDRESS,BIT) (ADDRESS ^= (1<<BIT))
#define CHECKBIT(ADDRESS,BIT) (ADDRESS & (1<<BIT))
#define WRITEBIT(RADDRESS,RBIT,WADDRESS,WBIT) (CHECKBIT(RADDRESS,RBIT) ? SETBIT(WADDRESS,WBIT) : CLEARBIT(WADDRESS,WBIT))
After these defines you can:
SETBIT(PORTA,2) turns on PORTA bit2
CLEARBIT(PORTB,0) turns off PORTB bit0
FLIPBIT(PORTB,0) inverts PORTB bit0 (if it was 1 it becomes 0 and the opposite)
CHECKBIT(PORTB,0) returns 1 if the specified bit has a value of 1
WRITEBIT(PINA,0,PORTB,1) read the value of PINA bit0 and writes it to PORTB bit1
I forgot to mention that the above work with any of PORTX, DDRX, PINX
Also when you want to change only some of the bits and not the entire port you can do
PORTA = PORTA | 0b10001001 this will turn on bits 0,3,7 without changing the other bits (they keep the previous value)
PORTA = PORTA & 0b01110110 this will turn off bits 0,3,7 without changing the other bits (they keep the previous value)
It is not difficult to remember these since any bit
ORed with 1 has the result of 1 and any bit
ANDed with 0 has a result of 0.
Hope these help
Alex