完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
大家好,我想用一个中断来打开一个LED当一个开关是使用汇编,但我似乎不能让中断工作。当调试时,我发现在按下开关时,正在设置更改中断标志,但处理器不会进入ISR。有人能帮忙吗?编辑:我想我需要建立IVT。我现在的问题是,如何使用汇编直接向输入更改中断向量写入GOTO指令?
以上来自于百度翻译 以下为原文 Hi everyone, I'm trying to use an interrupt to turn on an LED when a switch is pressed using assembly but I can't seem to get the interrupt to work. When debugging, I found that the change interrupt flag is being set when the switch is pressed but the processor won't enter the ISR. Can anyone please help? EDIT: I've figured out that I need to set up the IVT. My question now is; how do I write a GOTO instruction directly to the input change interrupt vector using assembly? ;******************************************************************************* .include "p24fj64ga002.inc" .global __reset .text __reset: ;******************************************************************************* ;Clear WREG CLR WREG ;Configure input and output pins BSET TRISB,#5 ;Set RB5 as input BCLR TRISB,#15 ;Clear RB15 as output BSET PORTB,#15 ;Set LED4 LOW ;Enable input change notification for CN27 BSET CNEN2,#11 ;Configure interrupt control registers BSET INTCON1,#15 ;Set NSTDIS control bit to disable nested interrupts MOV #0x7000,W0 IOR IPC4 ;Set input change notification priority to highest BCLR IFS1,#3 ;Clear input change notification flag BSET IEC1,#3 ;Set input change notification interrupt enable ;******************************************************************************* ;Clear WREG. WREG is used to compare PORTB values to see if the input ;has actually changed. CLR WREG ;Move PORTB value into W1 register since PORTB,#5 will initially be high MOV PORTB,WREG LOOP: GOTO LOOP .global __CNIInterrupt __CNIInterrupt: BCLR IFS1,#3 CPB PORTB BTSC SR,#1 BTG PORTB,#15 RETFIE .end |
|
相关推荐
19个回答
|
|
难道你不需要设置一个IVT(中断向量表)来使用PIC24上的中断吗?对于阅读按钮来说,用一个定时器中断来查询按钮实际上是更好的,这可以让你很容易地实现软件去抖动。使用切换按钮来阅读按钮会在你得到快速切换弹跳时造成严重破坏。
以上来自于百度翻译 以下为原文 Don't you have to set up an IVT (Interrupt Vector Table) to use interrupts on a PIC24? For reading pushbuttons, it's actually much nicer to poll the button with a timer interrupt, which lets you easily implement software debouncing. Using change interrupts for reading pushbuttons can cause havoc when you get rapid switch bounce. |
|
|
|
我记得读过,你必须在向量地址上编程一个“Goto ISR”命令,但是你怎么做呢?我之所以使用这个中断是因为我只是想学习如何使用和编程中断。
以上来自于百度翻译 以下为原文 I remember reading that you have to program a 'GOTO ISR' command at the vector address but how do you do this? The reason I'm using an interrupt for this is because I'm just trying to learn how to use and program interrupts. |
|
|
|
AsMun:你不需要用绝对地址跳跃来创建头痛,尽管它很容易完成,因为CN中断向量(α19)位于90003AH(IVT)和0013AH(AIVT)。你只需要从向量名中删除一个额外的“i”,而不是你的错误。享受ErMOSER:不要教别人你绝对不知道的事情。
以上来自于百度翻译 以下为原文 asmeng: You do not need to create a headache with absolute address jump, although it's done easily since the CN interrupt vector (#19) is located at 00003Ah (IVT) and 00013Ah (AIVT). You just need to remove an extra "I" from the vector name - __CNInterrupt instead of your wrong __CNIInterrupt. Enjoy ermoser: Do not teach others the things you have absolutely no idea about. |
|
|
|
不需要修改IVT,除非你需要在运行时这样做,而不是在编译时,因为GULLα-CNC中断会导致链接器写入IVT.8BIT与此无关。
以上来自于百度翻译 以下为原文 Easy typo. You don't don't have to modify the IVT unless you need to do that at runtime, not at compile time since the .globl __CNInterrupt will cause the linker to write the ivt. 8bit is not relevant to this. |
|
|
|
IVT不包含“Gotos”或任何其他指令,只是跳转的地址。
以上来自于百度翻译 以下为原文 IVT doesn't contain "gotos" or any other instructions, just addresses of where to jump. |
|
|
|
α-cNIdBase: BCR IFS1,3πBCR IFS1,αCNCNCPB PORTB将PORTB与WRG进行比较,为什么?WRGG/W0包含一个随机的ValueBTSC SR,1个BTSC SR,αZ,为什么要复制一个测试?BTG PORTB,{15TrimFixMults并不意味着杰克。包括“XC.H”
以上来自于百度翻译 以下为原文 __CNIInterrupt: BCLR IFS1,#3 bclr IFS1,#CNIF CPB PORTB compare portb to wreg with borrow, why? wreg/w0 contains a random value BTSC SR,#1 btsc SR,#Z, why replicate a test ? BTG PORTB,#15 RETFIE Numbers don't mean Jack. include "xc.h" |
|
|
|
BSET PORTB,第15页;设置LeD4 LoWi,我对此一无所知。我一直在阅读“使用LAT作为输出和端口用于输入”。这也适用于汇编代码吗?
以上来自于百度翻译 以下为原文 BSET PORTB,#15 ;Set LED4 LOW I'm no expert at this. I keep reading "use LAT for outputs and PORT for inputs". Does this apply to assembly code as well? |
|
|
|
|
|
|
|
MBedder:我对代码进行了更改,现在它正在使用模拟器,而不是在实际开发板上。在板上,中断标志被设置,但它仍然不会进入ISR。
以上来自于百度翻译 以下为原文 MBedder: I made this change to my code and it's now working with the simulator but not on the actual development board. On the board the interrupt flag is getting set but it still won't enter the ISR. |
|
|
|
LAT和端口寄存器都用于I/O引脚,它们具有不同的功能。通常情况下,您不必使用LAT寄存器进行任何操作。TIS寄存器用于将引脚配置为输入或输出。端口寄存器位是读或写的,如果它们分别是输入或输出。
以上来自于百度翻译 以下为原文 The LAT and PORT registers are both used for the I/O pins, they just have different functions. Normally you won't have to use the LAT register for anything. The TRIS register is used to configure the pins as inputs or outputs. The PORT register bits are either read from or written to if they're inputs or outputs respectively. |
|
|
|
编写/更改端口的单个位会导致RMW问题,因此使用LAT代替。如果没有这些问题,就可以完成整个端口的编写和修改,你是如何发现的呢?你是否按照GoRT2015建议修改ISR代码?
以上来自于百度翻译 以下为原文 Writing/altering the individual bits of PORT causes the RMW problems, so use LAT instead. Writing/altering the entire PORT can be done without these problems. How did you discover that? Did you fix your ISR code as Gort2015 suggested? |
|
|
|
你是怎么发现的?你是否按照GoRT2015建议修改ISR代码?我唯一改变的是把额外的“我”从CNIInterrupt带走。这是我当前的代码,我在两种情况下都使用那个调试器来监视寄存器。
以上来自于百度翻译 以下为原文 How did you discover that? Did you fix your ISR code as Gort2015 suggested? The only thing I changed was taking that extra 'I' out of CNIInterrupt. Here's my current code, ; .include "p24fj64ga002.inc" .global __reset .text __reset: ;******************************************************************************* ;Clear WREG CLR WREG ;Configure input and output pins BSET TRISB,#5 ;Set RB5 as input BCLR TRISB,#15 ;Clear RB15 as output BSET PORTB,#15 ;Set LED4 LOW ;Enable input change notification for CN27 BSET CNEN2,#11 ;Configure interrupt control registers BSET INTCON1,#15 ;Set NSTDIS control bit to disable nested interrupts MOV #0x7000,W0 IOR IPC4 ;Set input change notification priority to highest BCLR IFS1,#3 ;Clear input change notification flag BSET IEC1,#3 ;Set input change notification interrupt enable ;******************************************************************************* ;Clear WREG. WREG is used to compare PORTB values to see if the input ;has actually changed. CLR WREG ;Move PORTB value into W1 register since PORTB,#5 will initially be high MOV PORTB,WREG LOOP: GOTO LOOP .global __CNInterrupt __CNInterrupt: BCLR IFS1,#3 CPB PORTB BTSC SR,#1 BTG PORTB,#15 RETFIE .end I used that debugger in both cases to watch the registers. |
|
|
|
这是错误的、错误的、错误的。请不要驳斥好的建议。一旦你了解了BSF和BCF指令的读修改、写性质,你就会明白为什么只有写在LAT寄存器上,而不是端口寄存器是很好的建议。
以上来自于百度翻译 以下为原文 This is wrong, wrong, wrong. Please do not refute good advice. Once you have learnt about the read-modify-write nature of the BSF and BCF instructions, you will see why it is very GOOD advice to only write to the LAT registers, not the PORT registers. |
|
|
|
如前所述,首先修复您的BUGY ISR代码。
以上来自于百度翻译 以下为原文 Fix your buggy ISR code first as suggested above. |
|
|
|
在输入ISR时,不要假定WRGG/W0包含一个值。W1不是您的注释中的WRG。在使用CN时,不需要检查PORTB是否已经改变。您仍然没有使用来自“XC.Inc”的等值。你希望人们如何理解你的代码?
以上来自于百度翻译 以下为原文 On entering the isr, do not assume that wreg/w0 contains a value. W1 is not wreg that you have in your comment. You don't need to check if portb has changed when you are using CN. You are still not using the equate values from, "xc.inc". How do you expect people to understand your code? |
|
|
|
我添加了相等的名字,改变了我的读写,并简化了ISR,但是我仍然有同样的问题,即PC不会进入ISR。我把我更新的代码放在下面。
以上来自于百度翻译 以下为原文 I added the equate names, changed my read and writes to LATB, and simplified the ISR however I'm still having the same problem where the PC won't enter the ISR. I placed my updated code below. .include "p24fj64ga002.inc" .global __reset .text __reset: ;******************************************************************************* ;Clear WREG CLR WREG ;Configure input and output pins BSET TRISB,#RB5 ;Set RB5 as input BCLR TRISB,#RB15 ;Clear RB15 as output BSET LATB,#LATB15 ;Set LED4 LOW ;Enable input change notification for CN27 BSET CNEN2,#CN27IE ;Configure interrupt control registers BSET INTCON1,#NSTDIS ;Set NSTDIS control bit to disable nested interrupts MOV #0x7000,W0 IOR IPC4 ;Set input change notification priority to highest BCLR IFS1,#CNIF ;Clear input change notification flag BSET IEC1,#CNIE ;Set input change notification interrupt enable ;******************************************************************************* ;Clear WREG. WREG is used to compare PORTB values to see if the input ;has actually changed. CLR WREG LOOP: GOTO LOOP .global __CNInterrupt __CNInterrupt: BCLR IFS1,#CNIF BTG LATB,#LATB15 RETFIE .end |
|
|
|
RTFM:当发生CN中断时,用户应该读取与CN PIN相关的端口寄存器。这将清除不匹配条件,并设置CN逻辑来检测下一个PIN变化(FRM,DS9711B页12~20)。
以上来自于百度翻译 以下为原文 RTFM: When a CN interrupt occurs, the user should read the PORT register associated with the CN pin(s). This will clear the mismatch condition and set up the CN logic to detect the next pin change (FRM, DS39711B-page 12-20) |
|
|
|
CN27不共享任何其他类似于模拟?你应该包括“XC.Inc”而不是芯片设备。
以上来自于百度翻译 以下为原文 CN27 not sharing with anything else like analogue? You should include "xc.inc" instead of the chip device. |
|
|
|
PGED3/ASDA1/RP5/CN27/PMD7/RB5NO类似物。使用中的SDA?
以上来自于百度翻译 以下为原文 PGED3/ASDA1/RP5/CN27/PMD7/RB5 No analogue. Alt. SDA in use? |
|
|
|
只有小组成员才能发言,加入小组>>
5158 浏览 9 评论
1997 浏览 8 评论
1926 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3169 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2222 浏览 5 评论
724浏览 1评论
607浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
495浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
621浏览 0评论
520浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-19 16:42 , Processed in 1.911005 second(s), Total 114, Slave 97 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号