利用板上自带按钮(PC4)做外部引脚中断,改变7个LED灯泡发光
[复制链接]
//利用板上自带按钮(PC4)做外部引脚中断,改变LED灯泡发光 //***************************************************************************** #include "hw_ints.h" #include "hw_memmap.h" #include "hw_types.h" #include "debug.h" #include "gpio.h" #include "interrupt.h" #include "sysctl.h" //*****************************************************************************
unsigned char pc4_int_flag; //软件中断标志 //*****************************************************************************
#ifdef DEBUG void __error__(char *pcFilename, unsigned long ulLine){} #endif //*****************************************************************************
void delay(unsigned long delay_clok) { while(delay_clok)delay_clok--; } //*****************************************************************************
void GPIOCIntHandler(void) //中断服务程序中 { delay(2000); //消除抖动 while(GPIOPinRead(GPIO_PORTC_BASE, GPIO_PIN_4)==0) { GPIOPinWrite(GPIO_PORTC_BASE, GPIO_PIN_5,GPIO_PIN_5); } GPIOPinWrite(GPIO_PORTC_BASE, GPIO_PIN_5,~GPIO_PIN_5); GPIOPinIntClear(GPIO_PORTC_BASE, GPIO_PIN_4);//清除硬件中断标志,重要 pc4_int_flag ^= 0x1;//软件中断标志取反,重要 delay(2000); //消除抖动 } //*****************************************************************************
int main(void) //主 { // 设置从晶振运行时钟不PLL SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_6MHZ);
// 设置5个发光管引脚为输出 SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB | SYSCTL_PERIPH_GPIOC | SYSCTL_PERIPH_GPIOD | SYSCTL_PERIPH_GPIOE); GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE, GPIO_PIN_0 | GPIO_PIN_1); GPIOPinTypeGPIOOutput(GPIO_PORTC_BASE, GPIO_PIN_5 ); GPIOPinTypeGPIOOutput(GPIO_PORTD_BASE, GPIO_PIN_0 | GPIO_PIN_1); GPIOPinTypeGPIOOutput(GPIO_PORTE_BASE, GPIO_PIN_0 | GPIO_PIN_1);
// 设置按钮为输入引脚,作为外部引脚中断,下降沿触发 GPIOPinTypeGPIOInput(GPIO_PORTC_BASE, GPIO_PIN_4); GPIOIntTypeSet(GPIO_PORTC_BASE, GPIO_PIN_4, GPIO_FALLING_EDGE); GPIOPinIntEnable(GPIO_PORTC_BASE, GPIO_PIN_4); IntEnable(INT_GPIOC);
//软件中断标志清0 pc4_int_flag = 0;
//循环 while(1) { IntEnable(INT_GPIOC); if(pc4_int_flag) { GPIOPinWrite(GPIO_PORTE_BASE, GPIO_PIN_1,GPIO_PIN_1); GPIOPinWrite(GPIO_PORTE_BASE, GPIO_PIN_0,GPIO_PIN_0); GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_1,GPIO_PIN_1); GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_0,~GPIO_PIN_0); GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_1,~GPIO_PIN_1); GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_0,~GPIO_PIN_0); } else { GPIOPinWrite(GPIO_PORTE_BASE, GPIO_PIN_1,~GPIO_PIN_1); GPIOPinWrite(GPIO_PORTE_BASE, GPIO_PIN_0,~GPIO_PIN_0); GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_1,~GPIO_PIN_1); GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_0,GPIO_PIN_0); GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_1,GPIO_PIN_1); GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_0,GPIO_PIN_0); } } }
没注意到这个问题,编译时要用startup_rvmdk.S文件代替startup.S
startup_rvmdk.rar
(2.08 KB, 下载次数: 10)
|