完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
扫一扫,分享给好友
在学习M3时中断所遇到的问题,在网上找了些例程自己做时总进不了中断,
主程序 #include "hw_ints.h" #include "hw_memmap.h" #include "hw_nvic.h" #include "hw_types.h" #include "debug.h" #include "gpio.h" #include "interrupt.h" #include "systick.h" #include "sysctl.h" #define PINS GPIO_PIN_5 void delay(int d)//延时函数 [ for( ; d; --d); ] int main(void) [ SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_6MHZ);//配置系统时钟, SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);//使能外设GIOPB GPIODirModeSet(GPIO_PORTB_BASE, GPIO_PIN_0, GPIO_DIR_MODE_OUT);// SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC); // 使能 KEY所在的GPIO端口 //GPIOPinTypeGPIOInput(GPIO_PORTC_BASE, GPIO_PIN_4); GPIOPadConfigSet(GPIO_PORTC_BASE, GPIO_PIN_4, GPIO_STRENGTH_2MA,GPIO_PIN_TYPE_STD_WPU); GPIODirModeSet(GPIO_PORTC_BASE,GPIO_PIN_4,GPIO_DIR_MODE_IN); // 设置 KEY所在管脚为输入 GPIOIntTypeSet(GPIO_PORTC_BASE, GPIO_PIN_4, GPIO_LOW_LEVEL); //低电平中断 // 设置 KEY管脚的中断类型 GPIOPinIntEnable(GPIO_PORTC_BASE, GPIO_PIN_4); // 使能处理器中断 IntMasterEnable(); // 使能 KEY所在管脚的中断 IntEnable(INT_GPIOC); //好像程序进到这里就走不下去了 GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_0, 0XFF); //因为IntEnable(INT_GPIOC);所以没有被执行了,放在它前面就可以 while(1) [ GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_0, 0);//输出高电平 delay(20000);//延时 GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_0, 0XFF);//输出低电平 delay(20000);//延时 ] ] // GPIOD 的中断服务函数 void GPIO_Port_C_ISR(void) [ unsigned char ucVal; unsigned long ulStatus; ulStatus = GPIOPinIntStatus (GPIO_PORTC_BASE, true); // 读取中断状态 GPIOPinIntClear(GPIO_PORTC_BASE, ulStatus); // 清除中断状态,重要 if (ulStatus & GPIO_PIN_4) // 如果 KEY的中断状态有效 [ ucVal = GPIOPinRead(GPIO_PORTC_BASE, GPIO_PIN_5); // 翻转LED GPIOPinWrite(GPIO_PORTC_BASE, GPIO_PIN_5, ~ucVal); SysCtlDelay(300000); // 延时约 10ms,消除按键抖动 while (GPIOPinRead(GPIO_PORTC_BASE, GPIO_PIN_4) == 0x00); // 等待 KEY抬起 SysCtlDelay(300000); // 延时约 10ms,消除松键抖动 ] ] 中断注册 // Enable the IAR extensions for this source file. // //***************************************************************************** #pragma language=extended //***************************************************************************** // // Forward declaration of the default fault handlers. // //***************************************************************************** void ResetISR(void); static void NmiSR(void); static void FaultISR(void); static void IntDefaultHandler(void); //***************************************************************************** // // External declarations for the interrupt handlers used by the application. // //***************************************************************************** extern void GPIO_Port_C_ISR(void); //***************************************************************************** // // The entry point for the application startup code. // //***************************************************************************** extern void __iar_program_start(void); //***************************************************************************** // // Reserve space for the system stack. // //***************************************************************************** static unsigned long pulStack[64] @ ".noinit"; //***************************************************************************** // // A union that describes the entries of the vector table. The union is needed // since the first entry is the stack pointer and the remainder are function // pointers. // //***************************************************************************** typedef union [ void (*pfnHandler)(void); unsigned long ulPtr; ] uVectorEntry; //***************************************************************************** // // The vector table. Note that the proper constructs must be placed on this to // ensure that it ends up at physical address 0x0000.0000. // //***************************************************************************** __root const uVectorEntry __vector_table[] @ ".intvec" = [ [ .ulPtr = (unsigned long)pulStack + sizeof(pulStack) ], // The initial stack pointer ResetISR, // The reset handler NmiSR, // The NMI handler FaultISR, // The hard fault handler IntDefaultHandler, // The MPU fault handler IntDefaultHandler, // The bus fault handler IntDefaultHandler, // The usage fault handler 0, // Reserved 0, // Reserved 0, // Reserved 0, // Reserved IntDefaultHandler, // SVCall handler IntDefaultHandler, // Debug monitor handler 0, // Reserved IntDefaultHandler, // The PendSV handler IntDefaultHandler, // The SysTick handler IntDefaultHandler, // GPIO Port A IntDefaultHandler, // GPIO Port B // IntDefaultHandler, // GPIO Port c GPIO_Port_C_ISR, // GPIO Port C IntDefaultHandler, // GPIO Port D IntDefaultHandler, // GPIO Port E IntDefaultHandler, // UART0 Rx and Tx IntDefaultHandler, // UART1 Rx and Tx IntDefaultHandler, // SSI0 Rx and Tx IntDefaultHandler, // I2C0 Master and Slave IntDefaultHandler, // PWM Fault IntDefaultHandler, // PWM Generator 0 IntDefaultHandler, // PWM Generator 1 IntDefaultHandler, // PWM Generator 2 IntDefaultHandler, // Quadrature Encoder 0 IntDefaultHandler, // ADC Sequence 0 IntDefaultHandler, // ADC Sequence 1 IntDefaultHandler, // ADC Sequence 2 IntDefaultHandler, // ADC Sequence 3 IntDefaultHandler, // Watchdog timer IntDefaultHandler, // Timer 0 subtimer A IntDefaultHandler, // Timer 0 subtimer B IntDefaultHandler, // Timer 1 subtimer A IntDefaultHandler, // Timer 1 subtimer B IntDefaultHandler, // Timer 2 subtimer A IntDefaultHandler, // Timer 2 subtimer B IntDefaultHandler, // Analog Comparator 0 IntDefaultHandler, // Analog Comparator 1 IntDefaultHandler, // Analog Comparator 2 IntDefaultHandler, // System Control (PLL, OSC, BO) IntDefaultHandler, // FLASH Control IntDefaultHandler, // GPIO Port F IntDefaultHandler, // GPIO Port G IntDefaultHandler, // GPIO Port H IntDefaultHandler, // UART2 Rx and Tx IntDefaultHandler, // SSI1 Rx and Tx IntDefaultHandler, // Timer 3 subtimer A IntDefaultHandler, // Timer 3 subtimer B IntDefaultHandler, // I2C1 Master and Slave IntDefaultHandler, // Quadrature Encoder 1 IntDefaultHandler, // CAN0 IntDefaultHandler, // CAN1 IntDefaultHandler, // CAN2 IntDefaultHandler, // Ethernet IntDefaultHandler, // Hibernate IntDefaultHandler, // USB0 IntDefaultHandler, // PWM Generator 3 IntDefaultHandler, // uDMA Software Transfer IntDefaultHandler, // uDMA Error IntDefaultHandler, // ADC1 Sequence 0 IntDefaultHandler, // ADC1 Sequence 1 IntDefaultHandler, // ADC1 Sequence 2 IntDefaultHandler, // ADC1 Sequence 3 IntDefaultHandler, // I2S0 IntDefaultHandler, // External Bus Interface 0 IntDefaultHandler // GPIO Port J ]; //***************************************************************************** // // This is the code that gets called when the processor first starts execution // following a reset event. Only the absolutely necessary set is performed, // after which the application supplied entry() routine is called. Any fancy // actions (such as making decisions based on the reset cause register, and // resetting the bits in that register) are left solely in the hands of the // application. // //***************************************************************************** void ResetISR(void) [ // // Call the application's entry point. // __iar_program_start(); ] //***************************************************************************** // // This is the code that gets called when the processor receives a NMI. This // simply enters an infinite loop, preserving the system state for examination // by a debugger. // //***************************************************************************** static void NmiSR(void) [ // // Enter an infinite loop. // while(1) [ ] ] //***************************************************************************** // // This is the code that gets called when the processor receives a fault // interrupt. This simply enters an infinite loop, preserving the system state // for examination by a debugger. // //***************************************************************************** static void FaultISR(void) [ // // Enter an infinite loop. // while(1) [ ] ] //***************************************************************************** // // This is the code that gets called when the processor receives an unexpected // interrupt. This simply enters an infinite loop, preserving the system state // for examination by a debugger. // //***************************************************************************** static void IntDefaultHandler(void) [ // // Go into an infinite loop. // while(1) [ ] ] |
|
相关推荐
1个回答
|
|
fanhuaming :
ROM_SysCtlPeripheralEnable(); //使能端口 ROM_GPIOPadConfigSet(); //设置PAD模式 ROM_GPIODirModeSet(); //设置管脚工作模式 ROM_GPIOIntTypeSet(); //中断优先级 ROM_GPIOPinIntEnable() //使能管脚中断 ROM_IntEnable() //使能端口中断 ROM_IntMasterEnable(); //总中断 另建议别贴大段代码,把自己分析的认为有问题的代码贴出即可 |
|
|
|
只有小组成员才能发言,加入小组>>
392 浏览 2 评论
NA555DR VCC最低电压需要在5V供电,为什么用3.3V供电搭了个单稳态触发器也使用正常?
712 浏览 3 评论
MSP430F249TPMR出现高温存储后失效了的情况,怎么解决?
619 浏览 1 评论
对于多级放大电路板,在PCB布局中,电源摆放的位置应该注意什么?
1082 浏览 1 评论
780 浏览 0 评论
请问下tpa3220实际测试引脚功能和官方资料不符,哪位大佬可以帮忙解答下
189浏览 20评论
请教下关于TAS5825PEVM评估模块原理图中不太明白的地方,寻求答疑
153浏览 14评论
两个TMP117传感器一个可以正常读取温度值,一个读取的值一直是0,为什么?
22浏览 13评论
在使用3254进行录音的时候出现一个奇怪的现象,右声道有吱吱声,请教一下,是否是什么寄存器设置存在问题?
138浏览 13评论
TLV320芯片内部自带数字滤波功能,请问linein进来的模拟信号是否是先经过ADC的超采样?
132浏览 12评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-5 11:45 , Processed in 4.174134 second(s), Total 79, Slave 63 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号