Prerequisites
Workflow
main.c
file
by clicking File → New File... or by using Ctrl+N shortcut, as shown in Figure 6.main.c
file
with the following code snippet:int main (void)
{
/* Configure SW0 as input */
PORTC.DIRCLR = PIN4_bm;
/*Enable internal pull up for SW0*/
PORTC.PIN4CTRL = PORT_PULLUPEN_bm;
/* Configure LED0 pin as output */
PORTB.DIRSET = PIN7_bm;
while (1)
{
/* Check the status of SW0 */
/* 0: Pressed */
if (!(PORTC.IN & (PIN4_bm)))
{
/* LED0 off */
PORTB.OUTSET = PIN7_bm;
}
/* 1: Released */
else
{
/* LED0 on */
PORTB.OUTCLR = PIN7_bm;
}
}
}