Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stm32f4xx.h"
- unsigned int buftime;
- unsigned int waittime;
- int delay;
- int check;
- float timer;
- void SystemInit() {
- //enable clocking
- RCC->AHB1ENR|= 0x00000008; //for Port D (RCC_AHB1ENR) led
- RCC->AHB1ENR|= 0x00000001; //for Port A (RCC_AHB1ENR) Button
- //setup direction for PD12 (GPIOx_MODER)
- GPIOD->MODER|= 0x55000000; // output of port D
- GPIOA->MODER|= 0x00000000; // input of port A pin 0
- }
- int wait(unsigned int ms); // just delay
- //#define delay your_number_of_ms
- unsigned long GlobalTime;
- #define MAXGLOBALTIME 0x10000000
- void Input()
- {
- int inp=0;
- while (1)
- {
- if (inp==0)
- {
- buftime=2000000;
- waittime=2000000;
- delay=100;
- check=0;
- return;
- }
- }
- }
- void Output()
- {
- return;
- }
- void GreatWork()
- {
- if (( GPIOA->IDR & 0x00000001) == 0)
- {
- if (check==1)
- {
- waittime=buftime;
- check=0;
- buftime=400000;
- }
- GPIOD->ODR|= 0x00003000;
- wait(waittime*(delay/100));
- GPIOD->ODR &= ~0x00003000;
- wait(waittime);
- GPIOD->ODR|= 0x0000C000;
- wait(waittime*(delay/100));
- GPIOD->ODR &= ~0x0000C000;
- wait(waittime);
- }
- if (( GPIOA->IDR & 0x00000001) == 1)
- {
- check=1;
- buftime=buftime+100000;
- GPIOD->ODR|= 0x00003000;
- wait(waittime);
- GPIOD->ODR &= ~0x00003000;
- wait(waittime*(delay/100));
- GPIOD->ODR|= 0x0000C000;
- wait(waittime);
- GPIOD->ODR &= ~0x0000C000;
- wait(waittime*(delay/100));
- }
- }
- int main () {
- while (1)
- {
- }
- }
- void * const Tasks[ ] __attribute__((at(0x08001000))) = {
- Input,
- Output,
- GreatWork,
- 0
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement