Added the for loop for debouncing.

This commit is contained in:
Rajput R Vikramsingh Vikramsingh 2024-09-19 10:21:37 +05:30
parent 23858cec19
commit cd5afe526b
1 changed files with 17 additions and 17 deletions

30
lab5.c
View File

@ -2,7 +2,6 @@
#include <stdbool.h> #include <stdbool.h>
#include "tm4c123gh6pm.h" #include "tm4c123gh6pm.h"
void GPIOIntHandler(void);
int main(void) int main(void)
{ {
SYSCTL_RCGC2_R |= 0x00000020; /* enable clock to GPIOF */ SYSCTL_RCGC2_R |= 0x00000020; /* enable clock to GPIOF */
@ -11,29 +10,30 @@ int main(void)
GPIO_PORTF_DEN_R = 0x1F; /* set PORTF pins 5 pins*/ GPIO_PORTF_DEN_R = 0x1F; /* set PORTF pins 5 pins*/
GPIO_PORTF_DIR_R = 0x0E; /* set PORTF0 PORTF4 pin as input user switch pin */ GPIO_PORTF_DIR_R = 0x0E; /* set PORTF0 PORTF4 pin as input user switch pin */
GPIO_PORTF_PUR_R = 0x11; /* PORTF4 PORT0 is pulled up */ GPIO_PORTF_PUR_R = 0x11; /* PORTF4 PORT0 is pulled up */
GPIO_PORTF_IM_R = 0x11; /*Masking the ports*/ NVIC_EN0_R |= (1<<30); //Starting NVIC as all the interrupt goes through it
GPIO_PORTF_IM_R = 0x00; /*Masking the ports*/
GPIO_PORTF_IS_R = 0x00; GPIO_PORTF_IS_R = 0x00;
GPIO_PORTF_IBE_R = 0x00;
GPIO_PORTF_IEV_R = 0x00; /*detects the falling edge of the switch*/ GPIO_PORTF_IEV_R = 0x00; /*detects the falling edge of the switch*/
GPIO_PORTF_IBE_R = 0x00 GPIO_PORTF_ICR_R = 0x11;
} GPIO_PORTF_IM_R = 0x11;
while(1) while(1)
{ {
GPIO_PORTF_DATA_R = 0x04; //GPIO_PORTF_DATA_R = 0x02;
}
} }
void GPIOIntHandler(void) void GPIOIntHandler(void)
{ {
switch(z) int i=0;
for(i=0;i<1000;i++);
if((GPIO_PORTF_DATA_R & 0x11)== 0x11){}
else
{ {
case 0: GPIO_PORTF_DATA_R = 0x02; GPIO_PORTF_DATA_R ^= 0x02;
break;
case 1: GPIO_PORTF_DATA_R = 0x00;
break;
default : GPIO_PORTF_DATA_R = 0xFF;
} }
GPIO_PORTF_ICR_R = 0x11;
} }