* The LED0 on the ATtiny4809 main board is connected to pin 4 on port D.
* The LED0 on the ATmega4809 main board is connected to pin 4 on port D.
* Check the datasheet to find out which pins on which ports the different LEDs and buttons are connected to.
* Check the datasheet to find out which pins on which ports the different LEDs and buttons are connected to.
*/
*/
...
@@ -39,17 +39,17 @@ int main(void){
...
@@ -39,17 +39,17 @@ int main(void){
/**
/**
* We want to send signals to the LEDs, in order to turn the off and on.
* We want to send signals to the LEDs, in order to turn the off and on.
* In the AVR world we have the following:
* In the AVR world we have the following:
* PORTx.DIR: 1 is output, 0 is input
* PORTx.DIR: 1 is output, 0 is input.
* LED: 1 LED is off, 0 LED is on, this is called active-low
* LED: 1 LED is off, 0 LED is on, this is called active-low.
* Button: 1 button is open, 0 button is pressed, this is called active-low
* Button: 1 button is open, 0 button is pressed, this is called active-low.
*
*
* Remember bit set logic:
* Remember bit set logic:
* Set to 1: FLAG |= ( 1 << BIT_POS ) - using 'or' so we only change the one we want and leave the others untouched
* Set to 1: Register |= ( 1 << BIT_POS ) - using the 'or'('|') operator so we only change the one we want and leave the others untouched.
* Set to 0: FLAG &= ~( 1 << BIT_POS ) - same thing here but using 'and', find paper and a logic-table, and try it out if you want to know how it works
* Set to 0: Register &= ~( 1 << BIT_POS ) - same thing here but using the 'and'('&') and 'not'('~') operators, find paper and a logic-table, and try it out if you want to know how it works.
* Toogle bit: FLAG ^= ( 1 << BIT_POS ) - using bitwise xor, toogles the bit at BIT_POS
* Toogle bit: Register ^= ( 1 << BIT_POS ) - using bitwise the 'xor'('^') operator, toogles the bit at BIT_POS.
*/
*/
PORTD.DIR|=(1<<LED0);// Set LED0 as output - Using "D" in PORTx.DIR since the LED is connected to port D on the microcontroller
PORTD.DIR|=(1<<LED0);// Set LED0 as output - Using "D" in PORTx.DIR since the LED is connected to port D on the microcontroller.
/*
/*
* The usual way to run microcontrollers is using a simple infinite loop
* The usual way to run microcontrollers is using a simple infinite loop