Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define SW1 (*((volatile unsigned long *)0x40025040))
- #define SW2 (*((volatile unsigned long *)0x40025004))
- int count;
- uint32_t button_state1;
- uint32_t button_state2;
- uint32_t pushbuttons_1(void)
- {
- //Return the state of the buttons
- return SW1;
- }
- uint32_t pushbuttons_2(void)
- {
- //Return the state of the buttons
- return SW2;
- }
- void SysTick_Init(void)
- {
- button_state1=0;
- button_state2=0;
- count = 0;
- //Initialize Systick with interrupts every 1 ms
- NVIC_ST_CTRL_R = 0; // disable SysTick during setup
- NVIC_ST_RELOAD_R = 16000 - 1; // set reload value n = 16000
- NVIC_ST_CURRENT_R = 0; // Reset counter value
- NVIC_SYS_PRI3_R = (NVIC_SYS_PRI3_R&0x00FFFFFF) | 0x40000000; // priority 2
- NVIC_ST_CTRL_R = 0x00000007; // enable SysTick with interrupts
- }
- void SysTick_Handler(void)
- {
- if((count % 50) == 0)
- {
- button_state1 = pushbuttons_1();
- button_state2 = pushbuttons_2();
- if(button_state1 == 0)
- {
- if((count % 250) == 0)
- {
- GPIO_PORTF_DATA_R ^= 0x02; // toggle red LED
- }
- }
- if(button_state2 == 0)
- {
- if((count % 500) == 0)
- {
- GPIO_PORTF_DATA_R ^= 0x02; // toggle red LED
- }
- if((count % 2000) == 0)
- {
- GPIO_PORTF_DATA_R ^= 0x04; // toggle blue LED
- }
- }
- if((button_state1 == 0) && (button_state2 == 0))
- {
- if((count % 5000) == 0)
- {
- GPIO_PORTF_DATA_R ^= 0x08; // toggle green LED
- }
- if((count % 250) == 0)
- {
- GPIO_PORTF_DATA_R ^= 0x02; // toggle red LED
- }
- if((count % 1000) == 0)
- {
- GPIO_PORTF_DATA_R ^= 0x04; // toggle blue LED
- }
- }
- }
- count = count + 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement