I have a 4809 based curiosity nano. I want to blink the user LED. The hardware data sheet says.
So the LED has an external pull-up. In order to blink the LED is it better to (explicitly) toggle the DIR bit or the OUT bit?
Here is code toggling the DIR bit.
#ifdef F_CPU #undef F_CPU #endif #define F_CPU 3333333UL #include <avr/io.h> #include <util/delay.h> int main(void) { _delay_ms(100); PORTF.OUTCLR = PIN5_bm; while (1) { /* LED on 0.5 sec */ PORTF.DIRSET = PIN5_bm; _delay_ms(500); /* LED off 0.1 sec */ PORTF.DIRCLR = PIN5_bm; _delay_ms(100); } }
The other choice is to DIRSET once, and then OUTCLR, OUTSET in the loop.