完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
家里的好兄弟。我最近在PIC项目上遇到了一个问题,它是堆栈溢出的问题。我已经尽了最大的努力来克服这个挑战,但是我的最好的解决不了这个问题。根据PIC设备的数据表(PIC16F87A),芯片的硬件堆栈只有8个字节。Ls很深,但这对我的程序来说是不够的。由于这个硬件限制,我决定使用一个软件实现的“调用堆栈”。这就是我尝试的地方。这就是我所尝试的:如果我想分支到一个子程序,而不是使用“调用”指令,我会使用“Goto”指令来最小化硬件堆栈的使用。但是在执行GOTO之前,我会手动将返回地址存储在一个已知RAM位置,然后T。当执行子程序时,存储的返回地址将被加载到PC寄存器中。但是,据我所知,PC寄存器的高字节在不使用PCLASE寄存器的情况下是不可写入的。因为在Lo.4:3GT位是GOTO指令中唯一可写的/可使用的,所以我不可能将存储的返回地址加载回PC……我怎样才能解决这个问题?
以上来自于百度翻译 以下为原文 Good day Big bros in the house. I've got a problem with my PIC project recently, and it's the problem of stack overflow. I've tried my possible best at overcoming this challenge, but my best is not sufficient to solve the problem. According to the datasheet of this PIC device(PIC 16F877A), the chip's hardware stack is only 8- levels deep, but this is insufficient for my program. Because of this hardware limitation, I decided to use a software implemented "call stack". And this is where I got stuck. This is what I've tried: If I want to branch to a subroutine, instead of using the "call" instruction, I would the "goto" instruction to minimize hardware stack usage. But before I execute the goto, I would store the return address manually in a know RAM location, then the goto will be executed. When the subroutine is through with its job, The stored return address would then be loaded into the PC register. But as far as I know, the high byte of the PC register is not writeable without using the PCLATH register. Since the <4:3> bits are the only writeable/usable during a goto instruction, it's not possible for me to load the stored return address back into the PC... How can I solve this problem? |
|
相关推荐
10个回答
|
|
XC8应该能够为你的PIC实现编译堆栈,所以…它的生成代码可能值得一看。
以上来自于百度翻译 以下为原文 XC8 should be able to implement Compiled Stack for your PIC too, so... it may be worth taking a look at its generated code |
|
|
|
为什么?您必须使用一些非常低效的代码,如果您需要深入7个级别(您总是需要第八级才能服务中断),这是一个合理的方法,如果您真的需要保持这样的级别。这是您的错误。每一部分PC。这意味着你的方法应该按你想要的那样工作。再看一下PIC数据表中PCLASE寄存器的描述。这是一个强大的芯片,二十年前。现在,PIN兼容PIC16F1XXX芯片比16F87A更便宜,更快,更容易使用。一个好处是,堆栈大小现在增加了一倍,如果你溢出堆栈,你可以选择陷阱。
以上来自于百度翻译 以下为原文 Why? You must be using some very inefficient code if you need to go more than 7 levels deep (you always need the 8th level to be able to service interrupts) This is a reasonable approach if you REALLY need to keep so may levels. Here is your mistake. Writing to the PCL register ALSO copies PCLATH to the upper part of PC. This means your method should work exactly as you want. Have another look at the description of the PCLATH register in the PIC datasheet. Just as a matter of interest, why are you using a PIC16F877A at all? That was a mighty chip, twenty years ago. Now, there are pin compatible PIC16F1xxx chips that are cheaper, faster, and much easier to work with than the 16F877A. One bonus is that the stack size is now doubled, AND you have the option of traps if you overflow the stack. |
|
|
|
试试这些宏:用法:编辑:使用LGOTO,而不是写PCL。
以上来自于百度翻译 以下为原文 Try these macros: scall macro addr, stack local retaddr movlw low (retaddr) movwf stack+0 movlw high(retaddr) movwf stack+1 lgoto addr retaddr: endm sreturn macro stack movf stack+1,w movwf PCLATH movf stack+0,w movwf PCL endm Usage: scall sub, stack_var ... sub: ; sub code here sreturn stack_var Edit: Use LGOTO instead of writing to PCL. |
|
|
|
谢谢你的快速回复@达里奥吉目前无法访问PC(和XC8),我所有的都是Android手机。我刚刚用(SL4A)QPython应用程序编写了一个“简单”编译器。@ QuiB.自从我的电子学开始以来,我一直使用的是ARDUNO。所以这是我第一次使用PIC做项目,我甚至不知道这个路障,直到我得到2的这些芯片。
以上来自于百度翻译 以下为原文 Thanks for your speedy replies @DarioG I don't have access to PC (& XC8) as of now, all I have is an Android phone. I just used (sl4a) Qpython app to write a "simple" compiler. @qɥb Since the beginning of my electronics, all I've been using is an Arduino. So this is my first time using pic for projects, I ain't even aware of this roadblock until I got 2 of these chips. |
|
|
|
我忘了说我用的是我自己写得很差的汇编程序,我对宏不太了解,但我会研究你的代码,当我完成时,我会通知你的。谢谢。
以上来自于百度翻译 以下为原文 @1and0 I've forgotten to say that I'm using my own poorly written assembler,and I don't know a lot about macro, but I'll study your code, when I'm through, I'll inform you. Thanks. |
|
|
|
如果您编写了自己的汇编器,那么创建一个不使用任何RAM的宏(我认为MPASM也可以这样做),例如
以上来自于百度翻译 以下为原文 If you've written your own assembler, then create a macro that does not use any RAM (I think MPASM can do this too) such as lgoto Sub SubRet ; ... Sub ; sub code here lgoto SubRet |
|
|
|
…如果子程序只从一个地方调用,那么,为什么要麻烦它使它成为子程序呢?
以上来自于百度翻译 以下为原文 ... only useful if the subroutine is only called from one place, in which case, why bother making it a subroutine? |
|
|
|
哈哈,同意了,这里已经很晚了。我想宏一定会通过返回标签,所以它可以用来分支,因为OP正在创建自己的汇编器。正如你所说,OP有低效的代码。他应该改写它,这样它不会溢出堆栈,或者使用更新的图片。
以上来自于百度翻译 以下为原文 Haha, agreed, it's very late here. I was thinking the macro would pass the return label somehow, so it can be used to branch back, since OP is creating his own assembler. As you've said, OP has inefficient code. He should rewrite it so it does not overflow the stack, or use newer PICs. |
|
|
|
我已经通过了宏代码,现在我明白了它是如何工作的。你帮我找出了一个我没有注意到的重要信息——因为我一直在读这个数据表。非常感谢你…事实上,也许我应该叫你们这里的人-魔术师:
以上来自于百度翻译 以下为原文 I've gone through the macro code, and now I understand how it works. You helped me to figure out a vital information that I haven't pay attention to - since I've been reading this data sheet. Thank you very much... in fact, maybe I should call you people here - magicians :) |
|
|
|
哈哈,同意了,这里已经很晚了。我想宏一定会通过返回标签,所以它可以用来分支,因为OP正在创建自己的汇编器。正如你所说,OP有低效的代码。他应该重写它,这样它不会溢出堆栈,或者使用更新的图片。这是真的,我的代码是低效的。但是由于我不能访问像C这样的高级编译器,所以我编写了一个简单的编译器(或翻译器),把一个“基本的”源代码翻译成PIC汇编,从PIC程序集到HEX。因为我的主要目标是先有一个工作编译器,这就是为什么我的代码写得不好。现在你们这里的人已经解决了这个问题(我一直在忙着解决),我会为整理节目而努力。再次感谢你们,我真的很感激。
以上来自于百度翻译 以下为原文 Haha, agreed, it's very late here. I was thinking the macro would pass the return label somehow, so it can be used to branch back, since OP is creating his own assembler. As you've said, OP has inefficient code. He should rewrite it so it does not overflow the stack, or use newer PICs. Its true that my code is inefficient. But since I don't have access to High level compilers like C, I wrote a simple compiler( or translator) that translates a "BASIC-like" source code to PIC assembly, and from PIC assembly to hex. Since my primary aim is to have a working compiler first, that's why my code is inefficiently written. Now you people here has gotten the problem (that's been tying my hands for so long) solved, I'll work towards tidying up the program. Thanks once again, am really grateful. |
|
|
|
只有小组成员才能发言,加入小组>>
5184 浏览 9 评论
2005 浏览 8 评论
1932 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3179 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2230 浏览 5 评论
739浏览 1评论
626浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
511浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
637浏览 0评论
535浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-28 11:24 , Processed in 1.310741 second(s), Total 95, Slave 78 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号