完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
嗨,我有一个非常简单的代码来测试使用我的PIC外部中断。该代码只具有一个LED,并且在发生外部中断的情况下将被关闭(在这种情况下,推动连接到RA2的开关,这是PIC16F690上的INT引脚)。但是,当我按下开关时,什么也没有发生。可能是什么问题?下面的代码
以上来自于百度翻译 以下为原文 Hi, I got a very simple code to test the use of external interrupts with my pic. The code simply has an led that is on, and will be turned off in case an external interrupt occurs (in this case, pushing a switch connected to RA2 which is the INT pin on the PIC16f690.) When I push the switch though, nothing happens. What could be the problem? Code below list p=16f690 #include "p16f690.inc" ; CONFIG ; __config 0xFCF1 __CONFIG _FOSC_XT & _WDTE_OFF & _PWRTE_OFF & _MCLRE_ON & _CP_OFF & _CPD_OFF & _BOREN_OFF & _IESO_ON & _FCMEN_ON ORG 0x00 ; processor reset vector GOTO START ; go to beginning of program ORG 0x04 ; interrupt vector GOTO ISR ; go to interrupt service routine START BANKSEL TRISA BSF TRISA, 2 ;set RA2(INT PIN) as input BCF TRISA, 0 ;SET RA0 AS AN OUTPUT (led) BANKSEL INTCON ;go to INTCON REGISTER MOVLW b'10010000' MOVWF INTCON ;Global interrupt enabled, External interrupt enabled GOTO MAIN ;Interrupt service routine-------------------------------------------------------- ISR BCF INTCON, GIE ;Disable all interrupts inside interrupt service routine BCF PORTA,0 ;clear RA0 BCF INTCON,INTF ;Clear external interrupt flag bit BSF INTCON, GIE ;Enable all interrupts on exit GOTO MAIN ;Main routine--------------------------------------------------------------------- MAIN BSF PORTA,0 ;Set RA.0 GOTO MAIN ;Loop END |
|
相关推荐
2个回答
|
|
你的中断服务程序有几个错误,但是主要的错误是,即使发生中断,一旦你关闭了LED,你就跳回main,使它再次打开这么快,你不可能看到它!
以上来自于百度翻译 以下为原文 There are several things wrong with your interrupt service routine, but the main bug is that even if an interrupt does occur, as soon as you turn the LED off, you jump back to MAIN which turns it back on again so quickly you could not possibly see it! |
|
|
|
现在,什么是“几件事错了”?(1)不要触摸中断服务中的GIE标志。这是错误的、错误的、错误的,并且会导致真正中断的主要问题。当ISR开始运行时,GIE已经被禁用。ISR应该以ReFie指令退出,该指令以安全的方式设置GIE。在执行返回之前设置GIE将导致错误。(2)ISR必须在它可以做任何事情之前保存状态和W寄存器。在PIC16F690数据表中读取“中断期间的14.4上下文保存”。当ISR开始运行时,它也不能假设银行0被选中。位置4的结构。把实际的ISR放在那里。你可以在小程序中逃脱它,但是一旦你开始使用所有的程序内存,位置4的GOTO会导致崩溃。现在就开始做,以后你就不会有神秘的问题了。
以上来自于百度翻译 以下为原文 Now, what are the "several things wrong" ? [1] Do NOT touch the GIE flag inside your interrupt service. That is WRONG, WRONG, WRONG, and will cause major issues with real interrupts. GIE is already disabled when the ISR starts running. An ISR should exit with a RETFIE instruction, which sets GIE in a safe manner. Setting GIE before the return is executed will cause bugs. [2] Your ISR must save the STATUS and W register before it can do anything. Read "14.4 Context Saving During Interrupts" in your PIC16F690 datasheet. It also cannot assume bank 0 is selected when the ISR starts running. [3] Do NOT put a GOTO instruction at location 4. Put the actual ISR there. You can get away with it in small programs, but once you start using all the program memory, a GOTO at location 4 WILL cause crashes. Start doing it right now, and you won't have mysterious problems later. |
|
|
|
只有小组成员才能发言,加入小组>>
5234 浏览 9 评论
2026 浏览 8 评论
1950 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3201 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2253 浏览 5 评论
771浏览 1评论
659浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
588浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
670浏览 0评论
571浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-20 13:56 , Processed in 1.397655 second(s), Total 79, Slave 63 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号