完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
电子发烧友论坛|
大家好。我正在使用PIC16F83。我正在尝试编写一个越来越重要的程序,并用十进制显示计数器,在7个段的显示器上。对于我来说,我无法理解为什么它不能工作。疯狂的是,当我执行代码时,它工作,但当我运行代码时,它拒绝工作。当我执行代码时,我可以看到寄存器在观察窗口中的变化,但是当我运行它时…我不知道它在做什么。在运行代码时,你有什么调试的窍门吗?我怎么能看到正在运行的是什么?我希望我能在某些时候停顿一下,告诉我在那些时刻所有的记录里有什么。这将是一个很大的帮助。我不是真的寻求帮助的代码,因为这意味着我将不得不张贴在这里。这里有很多代码,每个人的标准都是草率的。
以上来自于百度翻译 以下为原文 Hello everyone. I'm using a PIC16F883. I'm trying to write a program that counts increasingly and displays the counter, in decimal, across some 7-segment displays. For the life of me I can't figure out why it doesn't work. The crazy thing is that it works when I step the code, but refuses to work when I run it. When I step the code I can see the registers change in the watch window, but when I run it.... I have no idea whats it's doing. Do you have any tips on debugging while running code? How I can see what's going on while it's running? I wish I could have it pause at certain points and show me whats in all the registers at those moments. That would be a big help. I'm not really looking for help with the code, because that means I would have to post it here. There's a lot of code and it's sloppy by the standards of everyone here. |
|
相关推荐
15个回答
|
|
|
首先猜测(不看883细节):1。延迟回路不能正常工作?这可能导致不工作的外观。2。在不考虑RMW的情况下写入PORTX寄存器。3。看门狗?建议:添加一个LED,与每个7段LED的更新(可能只使用小数点之一)切换。
以上来自于百度翻译 以下为原文 First guesses (without looking into the '883 details): 1. Delay loop(s) not working properly? This might give the appearance of not working. 2. Writing to PORTx registers without taking RMW into account. 3. Watchdog? Suggestion: add an LED that gets toggled with each update of the 7-segment LED's (maybe just use one of the decimal points). |
|
|
|
|
|
你可以通过串口发送感兴趣的寄存器内容,并用一个终端APP。2)非常快的定时,你可以使用测试输出引脚并用示波器观察它们。
以上来自于百度翻译 以下为原文 Some ideas 1.) You could send the register contents of interest by serial port and watch with a terminal app. 2.) For very fast timing you could use test output pins and observe them with an oscilloscope. |
|
|
|
|
|
在一个范围或逻辑分析仪上切换引脚和观看是一种方式。通过UART发送调试消息是另一回事。现在对你来说已经太晚了,但是编写一个小增量的程序并进行测试是避免这种情况的方法。
以上来自于百度翻译 以下为原文 Toggling pins and watching on a scope or logic analyzer is one way. Sending debug messages through UART is the other. Too late for you now, but writing a program in small increments and testing as you go is the way to avoid such situations. |
|
|
|
|
|
我终于弄清出了什么问题。我花了好几天才找到它。这太荒谬了,我的延迟回路工作正常。当我开始执行代码时,一切都很好。问题是,当要解码一个新的二进制数时,我没有重置变量。有一次,我发现它终于开始用小数进行计数。当我看着它数数时,出现了一个新问题。一旦它击中了70号…显示器将变成空白。如果我在70开始二进制计数器,它将增加到71,然后显示将变成空白。它也不会显示任何3位数字。我不知道为什么,我有一个单独的项目,同一个代码,除了在这个项目中,它编码只转换一个数字一次。我可以输入(在代码中)任何24位数字,它可以显示在七个7个SEG显示器上,并且它将解码和显示完美。在这个新项目中我要做的是在下一个数字之后解码一个数字。我现在定期进行解码。如果我只解码一个数字,它会周期性地解码那个数字。我不会显示70或任何3位数字。我把头发拔出来。我想如果它的工作数高达69只是罚款,…计算过去不应该有问题。哦,我得把它放到一边去。我用它浪费很多时间。我还有其他我需要做的作业。无论如何…这不是关于我的代码。这是关于调试技术的。
以上来自于百度翻译 以下为原文 I finally figured out what was wrong. It took me days to find it. This ridiculous. My delay loops are working fine. Everything was working great on its own when I stepped the code. The problem was that I wasn't resetting a variable when a new binary number was to be decoded. Once I found that out it finally started counting in decimal. As I'm watching it count up, a new problem arose. Once it hit the number 70.... the display would go blank. LOL. If I start the binary counter at 70, it will increase to 71 and then the display will go blank. It won't show any 3 digit numbers either. I have no idea why. I have a separate project with the same code, except in this project its coded to only convert one number once. I can enter (in code) any 24 bit number, that can be displayed on a seven 7-seg displays, and it will decode and display flawlessly. What I'm trying to do in this new project is have it decode one number after the next. I have it decoding periodically now. If I have it decoding only one number, it will decode that number over and over periodically. I won't display 70 or any 3 digit number. LOL. I'm pulling my hair out here. I'm thinking that if it worked counting up to 69 just fine,..... it shouldn't have a problem counting past that. OMG. I have to put this off to the side. Im wasting to much time with it. I have other homework I need to do. Anyways.... this is not about my code. This is about debugging techniques. |
|
|
|
|
|
我以小增量进行测试。当我把所有东西都一起工作的时候,它开始给我带来麻烦。我甚至没有想过使用逻辑分析仪。去年我买了一个600美元的萨利埃分析仪,我还没用过。
以上来自于百度翻译 以下为原文 I did test as in small increments. It's when I had everything working together, that it started giving me problems. I didn't even think about using a logic analyzer. I bought a $600 Saleae analyzer last year that I have yet to use. |
|
|
|
|
|
即使你的代码不整洁,你也会得到更多的帮助:
以上来自于百度翻译 以下为原文 you will get more help even if your code is sloppy :) post some of it |
|
|
|
|
|
这很容易——问题是你在最后一次增值过程中所做的任何改变。
以上来自于百度翻译 以下为原文 Then it's easy - the problem is in whatever changes you made during the last increment. |
|
|
|
|
|
你会得到更多的帮助,即使你的代码是草率:)张贴一些ito附加我的ASM文件在一点,所以你可以看看它。我现在把它放下,因为我的其他工作落后了。最后,我打算把它重新写得更有效率。我希望一旦我那样做,我就会发现问题所在。
以上来自于百度翻译 以下为原文 you will get more help even if your code is sloppy :) post some of it Ill attach my asm file in a bit so you can have a look at it. I put it off for now because im behind with my other work. Eventually im goin going to recode it to be more efficient. Im hoping that once I do that ill find the problem. |
|
|
|
|
|
我附上我的ASM文件,如果有人想弄清楚为什么它停止显示数字后69。我不知道,它可能还在往上数。它可能只是不显示数字。我不知道。它也不会显示3位数字。当我编写代码并测试它时,所有代码都工作了。我可以手动输入任何24位数字,它会解码并在显示器上显示我。祝你好运。我知道代码是草率的。你不必提醒我。
以上来自于百度翻译 以下为原文 I attached my ASM file if anyone wants to take a crack at figuring out why it stop displaying numbers after 69. It might be still counting upward, I don't know. It might be just not displaying the numbers. I don't know. It wont display 3 digit numbers as well. When I was writing the code and testing it as I went, all the code worked. I could manually enter just about any 24 bit number and it would decode and show me on the display. Good luck. I know the code is sloppy. You don't have to remind me. Attachment(s) ELT-226-01_Lab9_Se...nt LED Display.asm (21.15 KB) - downloaded 30 times |
|
|
|
|
|
我不会提醒你的代码效率。你的“RLZZART启动”最终会溢出堆栈,但这不是一个问题,因为PIC16上的硬件堆栈是圆形的;也就是说,最好重写这个例程,以免溢出堆栈。您是否没有将ISR内的页面设置为第0页,因此在您的上下文保存后立即添加此页。
以上来自于百度翻译 以下为原文 I'm not going to remind you on the efficiency of your code. Your "RLZ_Start" will overflow the stack eventually, but that is not an issue since the hardware stack on a PIC16 is circular; that said, it's better to rewrite this routine so not to overflow the stack. The cause of your issue at the moment is you did not set the page inside your ISR to page 0, so immediately after your context saving ; CONTEXT SAVING ;***************************************************** MOVWF SI_WREG ; WORKING register saved. SWAPF STATUS, W ; Save the STATUS register. MOVWF SI_STATUS ; STATUS register saved. BCF STATUS, 6 ; Bank 0. BCF STATUS, 5 MOVFW PCLATH ; Save the PCLATH register. MOVWF SI_PCLATH ; PCLATH saved. add this CLRF PCLATH ; Page 0. |
|
|
|
|
|
天哪,你跑得太快了!你真棒!在我的ISR里,我完全错过了。好的捕捉。我不明白为什么RLZX启动代码会溢出堆栈。我认为如果您有超过8个嵌套调用,您只能溢出堆栈。RLZSART启动后的调用没有嵌套。在下一次通话之前有一个电话和一个回程。我现在甚至不打算修复代码。明天我有一个考试。如果我这样做,我会花上几个小时的时间来解决这个问题。今年夏天我计划做大量的编码。我要学会更高效地编码。当我开始时,我会寻求建议和意见。
以上来自于百度翻译 以下为原文 Oh my god you're fast! You're good! I totally missed the PCLATH in my ISR thing. Good catch. I don't understand why the RLZ_Start code would overflow the stack. I thought that you could only overflow the stack if you had more than 8 nested calls. The calls after RLZ_Start aren't nested. There's a call and a return before the next call. I'm not even going to fix the code right now. I have a test tomorrow. If I do it, I'll end up spending hours messing around with it. This summer I plan I doing a lot of coding. I'm going to learn to code more efficiently then. I'll be seeking advice and opinions when I get started. |
|
|
|
|
|
拥有超过8个嵌套调用是PIC16上的硬件堆栈溢出的一种方式。堆栈溢出的另一种方法是当数据被推到堆栈上,而不是从堆栈中弹出数据;也就是说,有更多的调用而不是返回。这里是您的例程(我没有修复这个论坛混乱的代码格式):“RLZJOST”调用“RLZZEnter”,在那里它的正常执行PA。TH是返回,但是当零位被清除时它执行GOTO。这个Goto Do Nojl弹出由调用推动的堆栈;因此在8次这样的调用之后,硬件堆栈将溢出。
以上来自于百度翻译 以下为原文 Having more than 8 nested calls is one way the hardware stack on a PIC16 can overflow. Another way the stack can overflow is when data is pushed onto the stack more than data is popped from the stack; that is, there's more calls than returns. Here's your routine (I'm not fixing the code format that this forum messes up with): RLZ_Start MOVFW BD_Dig6 CALL RLZ_Remove MOVWF BD_Dig6 MOVFW BD_Dig5 CALL RLZ_Remove MOVWF BD_Dig5 MOVFW BD_Dig4 CALL RLZ_Remove MOVWF BD_Dig4 MOVFW BD_Dig3 CALL RLZ_Remove MOVWF BD_Dig3 MOVFW BD_Dig2 CALL RLZ_Remove MOVWF BD_Dig2 MOVFW BD_Dig1 CALL RLZ_Remove MOVWF BD_Dig1 RLZ_Remove SUBLW 0x3F BTFSC STATUS, Z RETLW 0x00 GOTO Main "RLZ_Start" calls "RLZ_Remove" where its normal execution path is to return, but it executes a GOTO when the Zero bit is cleared. This GOTO does _not_ pop the stack pushed there by the CALL; so after 8 such calls the hardware stack will overflow. |
|
|
|
|
|
好啊。我不知道,但根据你所说的,它仍然不会溢出,因为它只执行GOTO一次。GOTO是停止调用和返回的。这部分代码从MSD开始,并检查它是否为零。如果它是0,它将返回0x00,如果它检测到其他的和零,它将停止调用RLZY-Relev.HMM。我只是想,但是我每次都做这个过程来解码一个二进制数。所以它会为它解码的二进制数做一次GOTO。这会在一个二进制数解码过程中溢出堆栈?每次解码一个数字时,如何清除或重置堆栈?我知道我可以编写完整的代码来删除没有代码部分的前导零点,但是,每次启动时都有清除堆栈的方法吗?
以上来自于百度翻译 以下为原文 Ok. I didn't know that, but according to what you're saying it still wont overflow, because it will only execute the GOTO once. The GOTO is to stop the calls and returns. This portion of code starts with the MSD and checks if its a zero. If it's a zero it will return a 0x00 and if it detects something other and a zero its will stop calling RLZ_Remove. Hmmm. I just thought, but I does this whole process once every time to decodes a binary number. So it will do a GOTO once for every binary number it decodes. That will over flow the stack over a course of binary numbers being decoded? How can I clear or reset the stack every time I decode a number? I know I can write the overall code to remove leading zeros without that portion of code, but still, is there a way to clear the stack every time it starts over? |
|
|
|
|
|
你明白了。在PIC16设备上无法通过软件清除硬件堆栈。正如我所说的,硬件堆栈在PIC16上是圆形的,所以只要调用GOTO分支到主循环,代码就可以工作。另外,正如我前面说过的,最好修复它,这样它就不会溢出。
以上来自于百度翻译 以下为原文 You got it. There is no way to clear the hardware stack by software on a PIC16 device. Like I said, the hardware stack is circular on a PIC16, so the code will work as long as the |
|
|
|
|
|
我同意。它应该是固定的,它是固定的。谢谢你的帮助。你真是个专家。
以上来自于百度翻译 以下为原文 I agree. It should be fixed and it will be fixed. Thanks for your help. You're a real pro at this. |
|
|
|
|
只有小组成员才能发言,加入小组>>
MPLAB X IDE V6.25版本怎么对bootloader和应用程序进行烧录
503 浏览 0 评论
5812 浏览 9 评论
2350 浏览 8 评论
2237 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3544 浏览 3 评论
1161浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
1122浏览 1评论
我是Microchip 的代理商,有PIC16F1829T-I/SS 技术问题可以咨询我,微信:A-chip-Ti
890浏览 1评论
MPLAB X IDE V6.25版本怎么对bootloader和应用程序进行烧录
508浏览 0评论
/9
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2025-12-14 12:25 , Processed in 1.335371 second(s), Total 104, Slave 86 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191

淘帖
509