|
/*************************************** STM32 Tutorial v.2015 |
|
Authors: Julio Alexander Aguilar Angulo. [email protected] |
|
Elodie Pauly. [email protected] |
|
|
|
(c) ISEN-TOULON. 2015. www.isen.fr/toulon/ |
|
*******************************************************************************/ |
|
/**** Tuto 001b: Using Buttons **********/ |
|
/******************************************************************************/ |
|
#include "stm32l1xx.h" // prototypes and intrinsic declarations |
|
/* Testboard: STM32L152 NUCLEO */ |
|
/******* Hardware to use on this Tutorial: Onboard Led and Button ***********/ |
|
//------ User Button => PC13 User Led => PA5 |
|
/*** Variable declarations ************************************************/ |
|
const uint16_t myLed = 1<<5; |
|
const uint16_t myButton= 1<<13; |
|
|
|
int i,j,tmp; |
|
void Initsyst(void); |
|
/* Code Starts Here!! ********************************************************/ |
|
/* note: iar internals configure the system clock to 32 MHz */ |
|
void main() |
|
{ |
|
Initsyst(); |
|
GPIOA->ODR &= ~myLed;// turn off led as initial condition |
|
while (1) |
|
{ |
|
tmp=GPIOC->IDR & myButton; |
|
if (tmp==myButton) |
|
{ |
|
GPIOA->ODR &=myLed; // do nothing |
|
} |
|
else |
|
{ |
|
GPIOA->ODR ^=myLed; // blink the led |
|
j=200000; |
|
for(i=0;i<=j;i++) // debounce using Software Delay |
|
{ |
|
} |
|
} |
|
} |
|
} |
|
/***** Private Functions Definition **********************************/ |
|
void Initsyst(void) |
|
{ |
|
RCC->AHBENR|=0x05;// affect clock to GPIOA,C ( xxxxxxxxxxxx101) |
|
GPIOA->MODER|=0x5555;// output mode |
|
GPIOA->OTYPER&=0x0000; // push pull |
|
GPIOA->OSPEEDR|=0xFFFF;// High speed out |
|
GPIOA->PUPDR&=0x0000; // no pullup |
|
GPIOC->MODER&= 0x0000;// userbtn input mode |
|
GPIOC->PUPDR&=0x0000; // no pullup |
|
} |