int main(void){ unsigned long status; Switch_Init(); // PA5 is input status = Switch_Input(); // 0x00 or 0x20 status = Switch_Input(); // 0x00 or 0x20 Board_Init(); // initialize PF0 and PF4 and make them inputs // make PF3-1 out (PF3-1 built-in LEDs) GPIO_PORTF_DIR_R |= (RED|BLUE|GREEN); // disable alt funct on PF3-1 GPIO_PORTF_AFSEL_R &= ~(RED|BLUE|GREEN); // enable digital I/O on PF3-1 GPIO_PORTF_DEN_R |= (RED|BLUE|GREEN); // configure PF3-1 as GPIO GPIO_PORTF_PCTL_R = (GPIO_PORTF_PCTL_R&0xFFFF000F)+0x00000000; GPIO_PORTF_AMSEL_R = 0; // disable analog functionality on PF while(1){ status = Board_Input(); switch(status){ // switches are negative logic on PF0 and PF4 case 0x01: LEDS = BLUE; break; // SW1 pressed case 0x10: LEDS = RED; break; // SW2 pressed case 0x00: LEDS = GREEN; break; // both switches pressed case 0x11: LEDS = 0; break; // neither switch pressed default: LEDS = (RED|GREEN|BLUE);// unexpected return value } } }
//------------Switch_Debounce------------ // wait for the switch to be touched // Input: none // Output: none // debounces switch void Switch_WaitForTouch(void){ // wait for release while(Switch_Input()){}; SysTick_Wait(DELAY10MS); // 10ms // wait for touch while(Switch_Input()==0){}; SysTick_Wait(800000); // 10ms }
//------------Switch_Debounce------------ // Read and return the status of the switch // Input: none // Output: 0x02 if PB1 is high // 0x00 if PB1 is low // debounces switch uint32_t Switch_Debounce(void){ uint32_t in,old,time; time = 1000; // 10 ms old = Switch_Input(); while(time){ SysTick_Wait(DELAY10US); // 10us in = Switch_Input(); if(in == old){ time--; // same value }else{ time = 1000; // different old = in; } } return old; }