Commit 7f626ddd authored by Johan Vaarlid - M19939's avatar Johan Vaarlid - M19939
Browse files

New LF with new buttons for CNano

parent bb2eb46f
Loading
Loading
Loading
Loading
+10 −19
Original line number Diff line number Diff line
@@ -15,21 +15,25 @@
#include <util/delay.h>

/*
* Check out the ATtiny4809 datasheet to find the correct ports and pins 
 * Take a look at the Atmega4809 Curiosity Nano board and locate "SW0" and "LED0".
 * Right below each of them you can see which pin they are connected to. For example, if it said PD5, this would mean Port D and Pin 5.
 * This info can also be found in the ATmega4809 Curiosity Nano Hardware User Guide here: http://ww1.microchip.com/downloads/en/DeviceDoc/ATmega4809-Curiosity-Nano-HW-UG-DS50002804A.pdf to find the correct ports and pins 
 */

//Fill in the defines with the information you found on the board/in the user guide.

// LED
#define LED0 4 //On port D
#define LED0  //Fill in pin number

// Button
#define SW0 2 //On port C
#define SW0  //Fill in pin number

int main(void)
{
	/*
	 * We want to send signals to the LEDs, in order to turn it off and on.
	 * We also want to be able to read the switches.
	 * This is done by setting bits in the PORTx.DIR register (in this case PORTD.DIR and PORTC.DIR)
	 * This is done by setting bits in the PORTx.DIR register (in this case PORTF.DIR)
	 * PORTx.DIR: 1 is output, 0 is input
	 * LED: 1 LED is off, 0 LED is on
	 * Button: 1 Button is open, 0 button is pressed
@@ -41,7 +45,7 @@ int main(void)
	/**
	 * In order to read from the switches, we need to give it a ground reference, via a pull-up resistor.
	 * If we don't, the switch will have a floating ground, and hence its value will be undefined.
	 * On the ATtiny4809, we enable pull-up by setting the "PORT_PULLUPEN" flag in "PORTx.PINnCTRL" high.
	 * On the ATmega4809, we enable pull-up by setting the "PORT_PULLUPEN" flag in "PORTx.PINnCTRL" high.
	 * See datasheet section 15 (I/O-ports).
	 */
    
@@ -52,11 +56,6 @@ int main(void)
	 * 3 - Enable pull-up on button SW0
	 */
	
	PORTD.DIR |= (1 << LED0); // Set LED0 as output
	PORTC.DIR &= ~(1 << SW0); //Set SW0 as input
	
	PORTB.PIN2CTRL |= (1 << PORT_PULLUPEN_bp); //Enable pull-up on button SW0 (pin5)
	
    while (1) 
    {
    	/*
@@ -77,13 +76,5 @@ int main(void)
		* 3 - if not, turn the LED off
		*/
		
		if(!(PORTC.IN & (1 << SW0))){ // If button is pressed (0 - LOW
			PORTD.OUT &= ~(1 << LED0); // Sets output to 0, turns LED0 on
		}
		
		else{
			PORTD.OUT |= (1 << LED0); // Sets output to 1, turns LED off
		}
		
    }
}