完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
电子发烧友论坛|
我需要在C项目中嵌入一个时间关键汇编程序(MPLABX 3.5,XC8(当前在PRO模式下为1.41))。这个例程需要进行一个论证,并且还将从循环中调用。我首先尝试了一个非常特殊的方法。但在新的编纂之后,这种行为不时地发生变化。(首先它帮助从PRO模式转变为标准模式,但最后一次甚至失败了)所以我决定遵循手册的建议方式,把汇编程序部分放在一个单独的.ASM文件中。在不同的KANTSI的几个错误消息现在有了一个变体之后,它成功地建立起来了。问题是,它似乎什么都不做……为了简单起见,我把它剥离成只调用汇编程序的程序,它在一个循环中切换两个端口引脚。(最好说,它应该切换…)C文件:汇编文件:附上完整的项目。希望有人能在这里帮忙,Soenke。
以上来自于百度翻译 以下为原文 I need to embed a time critical Assembler routine in a C-Project (MPLABX 3.5, XC8 (currently 1.41 in PRO mode)). This routine needs to take an argument and will be furthermore called also from loops. I first tried the #asm/#endasm Version, which worked in a very special way. But the behaviour changed from time to time after new compilation. (First it helped to change from PRO to standard mode and back, but last time even that failed) So I decided to follow the suggested way of the manual and put the Assembler Portion in a separate .asm-file. After several error messages of different kinds I now have a variant, that builds successfully - the problem is, it seems to do nothing... For simplicity I stripped it down to a Programm that only calls an Assembler Routine, that Switches two port Pins in a Loop. (Better say, it should switch...) The C-file: #include #include extern void tp(void); int pause; void main(void) { long ctr; TRISBbits.TRISB6 = 0; TRISBbits.TRISB7 = 0; while(1){ tp(); for(ctr = 0; ctr < 100000; ctr++); } } The assembler-file: #include GLOBAL _tp GLOBAL _pause PSECT myspace, local, class = CODE, delta = 2 _tp: BSF LATB, 6 // TP0 BCF LATB, 7 // TP1 MOVLW 99 MOVWF _pause mloop: DECFSZ _pause, F GOTO mloop BCF LATB, 6 // TP0 BSF LATB, 7 The complete Project is attached. Hope that anybody can help here, Soenke Attachment(s) Ass_Test.X_running.zip (338.37 KB) - downloaded 100 times |
|
相关推荐
18个回答
|
|
|
编辑您的程序集文件:将delta值更改为1。在结尾添加一个返回指令。&编辑;编辑您的C文件:删除γ包含和lpIC18f8k90.h & gt;变量暂停可以是类型的无符号字符。
以上来自于百度翻译 以下为原文 Edit your assembly file:
Edit your C file:
|
|
|
|
|
|
我注意到大会上没有银行指示。是否知道“暂停”将在接入银行?你可以通过使用W寄存器来避免这个问题。
以上来自于百度翻译 以下为原文 I note there's no banking instructions in the assembly. Is it known that "pause" will be in the access bank? You could avoid the problem by using the W register instead. MOVLW 99 MOVWF _WREG mloop: DECFSZ _WREG, F GOTO mloop |
|
|
|
|
|
这应该是WREG,没有领先的下划线。@ OP:你的配置位在哪里?
以上来自于百度翻译 以下为原文 That should be WREG, without the leading underscore. @OP: Where are your config bits? |
|
|
|
|
|
我认为,在这种情况下,MOVWF WREG是多余的,MOVLW 99已经将值放在WRGG中,不是吗?
以上来自于百度翻译 以下为原文 I think in this case the MOVWF WREG is redundant, MOVLW 99 already puts the value in WREG does it not? |
|
|
|
|
|
是的,确实如此,DEFFSZ指令的目的位可以是F或W;
以上来自于百度翻译 以下为原文 Yes, it does, and the destination bit for the DECFSZ instruction can be either F or W. ;) |
|
|
|
|
|
哦。想把它当作通用寄存器来处理太多了。:)
以上来自于百度翻译 以下为原文 D'oh. Was thinking too much about treating it like a general purpose register. :) |
|
|
|
|
|
哈哈,这只是增加了一个单词和一个周期的延迟——就像在延迟循环中使用GOTO而不是胸罩。
以上来自于百度翻译 以下为原文 Haha, it's just adding one word and one cycle to the delay -- just like the usage of GOTO instead of BRA in that delay loop. |
|
|
|
|
|
如果我可以问一个与delta值有关的问题。在XC8用户指南中,我们有:是否包含所需的ReLoc值(默认值为1?)如果是这样,在运行时会有什么症状呢?我还没有深入研究汇编和C混合,我对这一点还不确定。我知道有信息在XC8手册,但我有点困惑在这一点。编辑:好的,我读的章节在PSECTS再次,我得到它好一点。一个ReLoc=1(默认值)将尝试在一个字节FangDrand上对齐指令,这在18F系列部分上是不可能的。因此,它不能编译,链接或不运行?很抱歉问这么多,但我目前没有机会试用它。
以上来自于百度翻译 以下为原文 If I could ask a question related to the delta value. In the XC8 user guide we have: Is the inclusion of the reloc value required (does it default = 1?)? If so what could be the symptoms during runtime? I have not delved into mixing assembler and c much yet and I am unsure of this point. I know there is info in the XC8 manual but I am a little confused on this point. EDIT: Ok I read the section on PSECTs again and I get it a little better. a reloc = 1 (the default) would try to align the instructions on a byte boundry which is not possible on an 18F series part. So does it fail to compile or link or just not run? Sorry to ask so much but I do not have access to trying it currently. |
|
|
|
|
|
根据XC8用户指南,“PIC18指令必须是字对齐的,所以对于任何包含可执行代码的PIC18 PSECT,必须使用2的ReLoc值。”默认的ReLoc值是1。我只是尝试了具有2和1的RoLc值的OP代码,并且两个ReLoc值都建立成功并生成I。十六进制文件。这就是说,我想最好是添加一个ReLoc=2标志,以便PSTECT内容在单词边界上对齐。也许杰夫(MaDyc)会掉下来,并对此提出一些启发。
以上来自于百度翻译 以下为原文 According to the XC8 User's Guide, "PIC18 instructions must be word aligned, so a reloc value of 2 must be used for any PIC18 psect that contains executable code." The default reloc value is 1. I just tried OP's code with reloc values of 2 and 1, and both reloc values build successful and generate identical hex files. That said, I guess it would be best adding in a reloc=2 flag so that the psect content is aligned on a word boundary. Perhaps Jeff (mad_c) will drop by and shed some light on this. |
|
|
|
|
|
对于PIC18代码,ReLoc必须是2。有一个很好的机会,代码将对齐一个Word边界,但如果有一个奇数大小的块const数据对象在程序存储器之前的代码段,这可能会推动代码偏离正确的对齐方式。这是设备的要求,但这不是中档的情况,所以中档可以使用默认的ReLoc标志1。然而,中距离设备不使用字节寻址程序存储器,因此它们必须具有2.jjf的非默认delta值。
以上来自于百度翻译 以下为原文 For PIC18 code, the reloc must be 2. There is a good chance that the code will align on a word boundary, but if there was an odd-sized block of const data objects in program memory before a code section, that might push the code off the correct alignment. This is a requirement of the device, but this is not the case for mid-range, so mid-range can use the default reloc flag of 1. However, the mid-range devices do not use byte-addressed program memory, so they must have the non-default delta value of 2. Jeff. |
|
|
|
|
|
幸亏我没想到如此激烈地讨论我的问题微笑:因为大部分原因是阅读手册太差了。我认为Delta确实是Reloc应该做的。所以“PSECT聚友网,本地,类=代码,ReLoc=2”。另一个建议是:丢失的“返回”可能是致命的,但是由于我没有得到任何错误,并且没有返回任何值,所以我假设编译器为我做了正确的事情。R TrIS寄存器的定义(甚至更多的是在原始程序中)——变量停顿太大,但可能除了浪费内存之外没有做任何坏的事情(没有检查编译器是否聪明地应该减少)-由于项目减少,配置丢失了——它们应该是定义的在那里(Apple仍然正确地在设备上)使用计数器变量/W-Reals/Boo:在原始的源代码中,我使用W-Realver进行另一个任务,所以没有选择。我的计划是使用未使用的LCD寄存器来避免银行切换问题,但QHB可能指出了我的一个核心问题:在C部分中声明变量停顿-我怎么知道,编译器把它放在哪里(除了检查汇编程序列表)?或者编译器首先处理汇编器,然后把变量放在同一个银行中?我不想告诉编译器,在哪里放什么(甚至更不知道怎么做)。
以上来自于百度翻译 以下为原文 Thanks to all - I didn't expect such an intense discussion on my ProblemSmile: As mostly, the reason was poor reading of the manual. I thought Delta did, what Reloc should do. So "PSECT myspace, local, class = CODE, reloc = 2" did it. On the other suggestions: - The missing "RETURN" could be fatal, but as I didn't get an error and don't return any value, I assume that the Compiler did it right for me. - The #include is neccessary for the Definition of the TRIS-Register (and even more in the original program) - Variable pause is too large, but probably not doing any bad other than wasting Memory (Didn't check if the Compiler was clever enought to reduce anyway) - ConfigBits were lost due to Project reduction - they should definitely be there (Apperantely they still remained correctly on the device) Usage of the counter variable/w-Register/Banking: In the original source I use the w-Register for another task, so no option. My plan was to use the unused LCD-Registers to avoid Bank-Switching-Issues, but qhb probably pointed to one of my core Problems: The variable pause is declared in the C-Portion - how do I know, where the Compiler puts it (other than checking the Assembler-listing)? Or does the Compiler first process the Assembler and then put the variables in the same bank? I don't want to tell the Compiler, where to put what (and even more don't know how to). |
|
|
|
|
|
为了把变量放在指定的位置,你可以这样做:char暂停@ 0x02;我经常使用它来在Access Bank中放置变量,这样我就不用担心汇编代码中的银行业务了。我一直在使用PIC18使用C和汇编(使用ASMα-EnEASM),没有任何问题。由于定时要求,我经常编辑QueE。如果您使用PRO优化,请确保您不选中复选框来优化ASM代码(我想这就是它所调用的,就我所能记得的)。只留下选中的-优化生成的程序集。您总是可以将汇编中编写的代码与已编译的代码进行比较,以查看编译器是否更改了代码。
以上来自于百度翻译 以下为原文 To place the variable at the specified location you can do it like this: char pause @0x02; I use it often to place variables in Access Bank so I don't have to worry about banking in assembly code. I have been using C and assembly (using #asm #endasm) with pic18 and didn't have any problems. I usedit quie a lot because of timing requirements. If you are using PRO optimisation, make sure that you uncheck checkbox to optimise asm code (I think that's what it is called, as far as I can remember). Leaving checked only - optimise generated assembly. You can always compare your code written in assembly with the disassembled compiled code to see if it was changed by the compiler. |
|
|
|
|
|
若要在访问RAM中放置变量,请使用近似限定符,并确保将编译器响应设置为需要的地址限定符(或默认限定符将被忽略)。
以上来自于百度翻译 以下为原文 To place variables in the Access RAM, use the near qualifier and make sure to set the compiler response to address qualifiers to REQUIRED (or the near qualifier will be ignored by default). |
|
|
|
|
|
虽然ReLoc=2应该用于PIC18,但是您的bug是2的delta值(默认值是1,所以可以省略它)。不,编译器不会自动为您添加返回。不需要包含& PIC18F8K90.H&G.包括& lt;xc8. h & gt;将为你这样做。不,编译器不是那么聪明。最好包括所有配置位。查找并读取XC8用户指南中的“内存分配”部分。
以上来自于百度翻译 以下为原文 While reloc=2 should be used for PIC18, your bug was the delta value of 2 (default is 1 so can omit it). No, the compiler does not automatically add the RETURN for you. There is no need to #include No, the compiler is not that smart. It's best to include ALL config bits. Look up and read the "Memory Allocation" section in the XC8 User's Guide. |
|
|
|
|
|
这就是我所怀疑的。谢谢你跳进来。:)
以上来自于百度翻译 以下为原文 That is what I suspected. Thanks for jumping in. :) |
|
|
|
|
|
再次感谢大家!我标出了线程“解决”,并用修正后的项目文件替换-也许它可以帮助其他人开始。
以上来自于百度翻译 以下为原文 Once again Thank You all! I marked the thread 'solved' and replaced the Project-file with the corrected one - Maybe it can help somebody else to get started. |
|
|
|
|
|
使用正确的变量位置,您可能可以使用原始的内联方法来完成此操作。
以上来自于百度翻译 以下为原文 With the variable location correctly specified, you probably could have done this using the original inline method. |
|
|
|
|
|
是的,也许。无论如何,我喜欢现在解决的方法。这似乎是一个非常干净的方式。
以上来自于百度翻译 以下为原文 Yes, probably. Anyway, I like the way it is solved now. It appears to be a very clean way. |
|
|
|
|
只有小组成员才能发言,加入小组>>
MPLAB X IDE V6.25版本怎么对bootloader和应用程序进行烧录
473 浏览 0 评论
5793 浏览 9 评论
2334 浏览 8 评论
2224 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3530 浏览 3 评论
1124浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
1095浏览 1评论
我是Microchip 的代理商,有PIC16F1829T-I/SS 技术问题可以咨询我,微信:A-chip-Ti
873浏览 1评论
MPLAB X IDE V6.25版本怎么对bootloader和应用程序进行烧录
475浏览 0评论
/9
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2025-12-2 04:48 , Processed in 1.092853 second(s), Total 106, Slave 89 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191

淘帖
4690