Hi,
I'm new to the atmel ARM series MCU's and I am trying to create a simple program so that when I press the user button,
the led on de board lights up.
(I am using the SAM4s Xplained pro development board)
I want to do this without the ASF functions, but with the GPIO registers like
PIO_OSR, PIO_ODSR, PIO_PDSR etc.
I'm having trouble reading the button.
(so the condition inside the if statement is not correct) --> if((PIO_PDSR_P24) == 1){}
Anyone knows how this statement should be formulated to read out the button via the PDSR register?
I'm new to the atmel ARM series MCU's and I am trying to create a simple program so that when I press the user button,
the led on de board lights up.
(I am using the SAM4s Xplained pro development board)
I want to do this without the ASF functions, but with the GPIO registers like
PIO_OSR, PIO_ODSR, PIO_PDSR etc.
I'm having trouble reading the button.
(so the condition inside the if statement is not correct) --> if((PIO_PDSR_P24) == 1){}
Anyone knows how this statement should be formulated to read out the button via the PDSR register?
Code:
/*
* SAM4S_Xplained_Pro_firstProject.c
*
* Created: 30-8-2015 20:37:29
* Author: embedded_
*/
/*
User switch = PC24
User led = PC23
*/
#include "sam.h"
/**
* \brief Application entry point.
*
* \return Unused (ANSI-C compatibility).
*/
int main(void)
{
/* Initialize the SAM system */
SystemInit();
PIOC->PIO_PER = (PIO_PER_P24 | PIO_PER_P23); //PIO enable
PIOC->PIO_ODR = PIO_ODR_P24; //Input
PIOC->PIO_PUER = PIO_PUER_P24; //pull-up resistor button
PIOC->PIO_OER = PIO_OER_P23; //Output
while (1)
{
if((PIO_PDSR_P24) == 1)
{
PIOC->PIO_SODR = PIO_SODR_P23;
}
else
{
PIOC->PIO_CODR = PIO_CODR_P23;
}
}
}