updated Tas2-LF.c with CNano button and LED

parent 7f626ddd
...@@ -23,10 +23,10 @@ ...@@ -23,10 +23,10 @@
//Fill in the defines with the information you found on the board/in the user guide. //Fill in the defines with the information you found on the board/in the user guide.
// LED // LED
#define LED0 //Fill in pin number #define LED0 5 //Fill in pin number
// Button // Button
#define SW0 //Fill in pin number #define SW0 6 //Fill in pin number
int main(void) int main(void)
{ {
...@@ -53,9 +53,11 @@ int main(void) ...@@ -53,9 +53,11 @@ int main(void)
* It's your time to do some stuff! Do the following: * It's your time to do some stuff! Do the following:
* 1 - Set LED0 as output * 1 - Set LED0 as output
* 2 - Set SW0 as input * 2 - Set SW0 as input
* 3 - Enable pull-up on button SW0 * 3 - Enable pull-up on button SW0 (Not necessary here as we have an external pull-up, but in case you dont have one in the future, dont forget!).
*/ */
PORTF.DIRSET = (1 << LED0);
PORTF.DIRCLR = (1 << SW0);
//PORTF.PIN6CTRL |= (1<<PORT_PULLUPEN_bp); //Not necessary as the button already had an external pullup.
while (1) while (1)
{ {
/* /*
...@@ -75,6 +77,14 @@ int main(void) ...@@ -75,6 +77,14 @@ int main(void)
* 2 - if so, turn the LED on * 2 - if so, turn the LED on
* 3 - if not, turn the LED off * 3 - if not, turn the LED off
*/ */
if(!(PORTF.IN & (1<<SW0)))//Check if SW0 is pressed
{
PORTF.OUTCLR = (1<<LED0);//Set LED0 high
}
else
{
PORTF.OUTSET = (1<<LED0);//Set LED0 low
}
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment