完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
电子发烧友论坛|
我在组装PIC16F18854时发现了一些不寻常的东西。我已经把PUTB设置成所有的数字输入。(在16F18854的情况下,PORTB是RB0通过RB7。)通常在其他PICS上,下面的代码很好地读取所讨论的端口的所有引脚:问题是,当我使用上面的代码时,RB5(PIN 26)被误读。即使我用这个代码(只是为了测试),它也会被误读:但是当我手动检查PORTB中每个引脚的状态时,什么都没有被误读,问题被解决了(请忽略坏的间距——在我的实际代码中,间隔是正确的):我很高兴我有一个解决方案,但是我不明白为什么要移动。整个端口到W,然后RAM导致误读引脚。你们有人知道吗?(再一次,PUTB通过tiSISB设置为所有输入,ANSELB被清除,使引脚数字。)谢谢。
以上来自于百度翻译 以下为原文 I've discovered something unusual while programming a PIC16F18854 in Assembly. I have PORTB set to be all DIGITAL INPUTS. (In the case of the 16F18854, PORTB is RB0 through RB7.) Normally on other PICs, the following code works just fine to read all pins of the port in question: banksel PORTB ; [Bank 0] movf PORTB, W ; Move state of PORTB input pins to W register. movwf RAMa ; Save W in RAM (0x077, RAM common to all banks) The problem is that when I use to above code, RB5 (pin 26) is misread. It is misread even when I use this code (just for a test): banksel PORTB ; [Bank 0] movf PORTB, W ; Move state of PORTB input pins to W register. movwf RAMa ; Save W in RAM nop nop nop nop movf PORTB, W ; Move state of PORTB input pins to W register. movwf RAMa ; Save W in RAM nop nop nop nop movf PORTB, W ; Move state of PORTB input pins to W register. movwf RAMa ; Save W in RAM But when I manually check the state of every pin in PORTB, nothing is misread and the problem is solved (please ignore the bad spacing -- spacing is correct in my actual code): banksel PORTB ; [Bank 0] clrf RAMa btfsc PORTB, RB0 bsf RAMa, 7 btfsc PORTB, RB1 bsf RAMa, 6 btfsc PORTB, RB2 bsf RAMa, 5 btfsc PORTB, RB3 bsf RAMa, 4 btfsc PORTB, RB4 bsf RAMa, 3 btfsc PORTB, RB5 bsf RAMa, 2 btfsc PORTB, RB6 bsf RAMa, 1 btfsc PORTB, RB7 bsf RAMa, 0 I'm pleased I have a solution, but I don't understand why moving the entire PORT to W and then to RAM causes a misread pin. Do any of you know? (And again, PORTB is setup via TRISB to be all INPUTS, ANSELB is cleared, making the pins DIGITAL.) Thanks. |
|
相关推荐
19个回答
|
|
|
你从不提“误读”的意思。这是不是意味着“总是高”,“总是低”,“随机”?你怎么知道它被误读了?您所显示的代码与此无关。您是否正在调试调试器中的变量?
以上来自于百度翻译 以下为原文 You never mention what you mean by "misread". Does this mean "always high", "always low", "random" ? How do you know it is misread? The code you show does nothing with it. Are you watching the variables in the debugger? |
|
|
|
|
|
HII,我是新的这里和PIC编程我写了5次拨号LED的程序,但是它是一个切换连续逻辑,包括:和PIC16F1936。h & gt;定义xTalthFlq 1200 000空缺延迟(){int b(b=0;b & lt;10000;b++);}空格主(){TrISB= 0x00;Potb= 0x00;int A;(a=0;a & lt;5;a++){PtBr= 0xFF;Delay-();端口。B= 0x00;Delay.(;)}帮助
以上来自于百度翻译 以下为原文 Hii, i m new here and pic programming i write program of toggle LED for 5 time but it is toggle continue my logic is #include #define _XTAL_FREQ 12000000 void delay() { int b for(b=0;b<10000;b++); } void main() { tri***=0x00; portb=0x00; int a; for(a=0;a<5;a++) { portb=0xff; delay(); portb=0x00; delay(); } } plzz help |
|
|
|
|
|
我有8个外部上拉电阻在端口B的每一个输入,拉它们到5 V。然后,使用一个8开关DIP连接到每一个输入,以拉动他们个别地切换时的地面。即使输入的问题切换到地上,PIC认为它是HI,当且仅当我做一个PoBB读。但是正如我在我的开头所说的,如果我逐一阅读每一个输入,问题输入正确地显示LO。真奇怪。思想?
以上来自于百度翻译 以下为原文 I have 8 external pull-up resistors on each of the inputs of Port B, pulling them up to 5 V. I then use an 8-switch DIP connected to each of those inputs to pull them individually to ground when switched. Even though the input in question is switched to ground, the PIC thinks it's HI, if and only if I do a PORTB read. But like I said in my opening post, if I read each input individually, the input in question correctly shows LO. It's strange. Thoughts? |
|
|
|
|
|
你不可能有其他代码(特别是一个中断处理程序)可以写在0x77中吗?GP
以上来自于百度翻译 以下为原文 You don't, by any chance, have other code (specifically an interrupt handler) that might write in 0x77? GP |
|
|
|
|
|
没有中断处理程序写入RAM。此外,如果你看一下ASM代码,在我原来的文章中,你会看到我也写同样的RAM没有问题。因此,如果它是中断处理程序或任何其他程序也写入到同一RAM,并造成问题,逻辑规定,我将有相同的问题,无论我用什么代码。
以上来自于百度翻译 以下为原文 No interrupt handler writes that RAM. Besides, if you look at the ASM code that works properly in my original post, you will see I also write to that same RAM without problem. As such, if it was interrupt handler or any other routine that was also writing to the same RAM and causing problems, logic dictates I would have the same problem no matter what code I used. |
|
|
|
|
|
我仍然怀疑一个软件错误。你能尝试一个只读取PoBB的最小程序吗?
以上来自于百度翻译 以下为原文 I still suspect a software bug. Could you try a minimal program which only reads PORTB? |
|
|
|
|
|
请注意,第二个代码段以第一个代码段的相反顺序读取位。
以上来自于百度翻译 以下为原文 Notice your second snippet read the bits in reverse order that of the first snippet. |
|
|
|
|
|
嗨,小心初始化代码……不要和旧PIC16比较。新PIC16F1XXXX在I/OS上有很多选项:上拉/下拉、开漏、转换率……从我的经验来看,5或6个寄存器需要适当初始化以获得预期的行为。MCC插件,在CREGARDS中生成代码
以上来自于百度翻译 以下为原文 Hi, Be careful to the initialization code...do not compare to old PIC16 The new PIC16F1xxxx have lots of options on I/Os : pull-up / pull-down, open drain, slew rate,... From my experience 5 or 6 registers need to be initialized properly to have the expected behaviour. This is easily visible if you use MCC plugin which generates code in C Regards |
|
|
|
|
|
可能:PORTB具有模拟能力和默认的POR到模拟模式,清除ANSELB寄存器设置为数字输入模式。既然你不显示你的所有代码,我猜在这里…
以上来自于百度翻译 以下为原文 Possibly: PORTB has analog capability and defaults on POR to analog mode, clear the ANSELB register to set to digital input mode. Since you do not show all your code I am guessing here.... |
|
|
|
|
|
那不是真的。中断处理程序的时间可以改变它的效果。你暗示你有一个中断处理程序,是吗?你说它不写“那个”RAM。我们不能在没有看到IH代码的情况下验证它。因为在某个地方有一个bug,而你没有显示所有的代码,所以很难帮助定位BUGGP。
以上来自于百度翻译 以下为原文 That's not true. Timing of the interrupt handler can vary its effects. You imply you do have an interrupt handler, do you? You say it doesn't write to "that" RAM. We can't verify that without seeing the IH code. Since there is a bug somewhere and you don't show all the code, it's difficult to help locating the bug. GP |
|
|
|
|
|
如果问题是RAMA损坏,那么您的新代码(最后一个代码段)会损坏RB2而不是RB5。是吗?
以上来自于百度翻译 以下为原文 If the problem is with RAMa corruption, then your new code (last snippet) should corrupt RB2 instead of RB5. Does it? |
|
|
|
|
|
回到QHB的原始问题。使用调试器吗?操作时使用RB6和RB7。
以上来自于百度翻译 以下为原文 Back to qhb's original question. Are you using the debugger? It uses RB6 and RB7 when operating. |
|
|
|
|
|
我已经尝试了我的代码稍微削减版本,没有中断处理程序和中断所有禁用,但问题仍然发生。如果我从零开始,什么也不做,只有一个端口读取,那么它工作。但是在这种情况下(我从头开始),NCO被禁用了,但实际上我需要NCO在我的主代码中运行。我知道比特顺序颠倒。由于某种原因,我发现这是真的:PoBr= RB7 RB6 RB5 RB4 RB3 RB2 RB2 RB1 RB0在“MOVF PORTB,W”,然后“MOVWF DIPMEM”,我们得到这样的顺序:DIPMEM=RB0RB1 RB2 RB3 RB4 RB4 RB5 RB6 RB7为什么位颠倒超出我。有人知道吗?它不能是“罗摩腐败”,因为正如我所说的,只有一个PoBB读取导致问题,但是如果我从PoBB读取每一个比特,那么就没有问题,证明没有“RAM损坏”。我不使用调试器。我用P3编程PIC,然后把PDIP放进我的电路板,测试,然后删除,重新编程,再测试等等。……TREISB是B’11111111在复位,但我也手动写这个值到TISISB在我的init例程,毫无疑问地确保所有的Purb是S。每一个8个输入(包括引脚26)都有一个外部100K欧姆上拉到5V。此外,还有一个8开关DIP连接到8个输入中的每一个,当接通时会将个别输入接地。所以问题是,当我的DIP SW连接到Pi-26时。要在地上,PIC仍然认为Pi-26是关闭的/ 5V的,是的,我用DMM验证了,在我的DIP SW和电压电平上根本没有问题。ILVLB在复位时是B’11111111’,但我也用它手动测试到0,没有用。WPUB在复位时被设置为0,并且在R上也使用CLRF。我的代码中的EGISTER以确保内部的上拉电阻是不合格的。ODCONB在复位时设置为0,它不重要,因为它涉及到输出引脚上的电流或下沉电流——所有的端口引脚都被定义为输入。在任何情况下,我将该寄存器的默认值为0.SLRCONB设置为B’11111。在复位时,111′(“限制”)。我通常是这样的。但是根据您的请求,我在其init例程中使用了CLRF,但是问题仍然存在——改变转换速率没有正面影响。ANSELB在复位时是B’11111111’,但是在我的init例程中,我使用CLRF来确保所有引脚都是数字I/O。我不使用LATB,因为这与输出有关。以上都是与PORTB相关的寄存器,如表B 12-3所给出的修订B数据表的第196页:HTTP:/WW1.MICCHIP.COM/DeLoSs/En/DeVICEDC/OC0401826B.PDFand,虽然我确实有ISR,但它不做。调用任何写入RAM的例程(在0x077)。此外,当我写入RAM时,中断被禁用。
以上来自于百度翻译 以下为原文 I've tried a slightly cut-down version of my code, with no interrupt handler and interrupts all DISABLED, but the problem still occurs. If I start from scratch and do nothing but a PORTB read, then it works. But in that case (where I start from scratch), the NCO is disabled, but I actually need the NCO running in my main code. I am aware about the bit order reversal. For some reason I have found this is true: PORTB = RB7 RB6 RB5 RB4 RB3 RB2 RB1 RB0 After "movf PORTB, W" and then "movwf DIPmem" we get this order: DIPmem = RB0 RB1 RB2 RB3 RB4 RB5 RB6 RB7 Why the bits are reversed is beyond me. Anyone know? It cannot be "RAMa corruption" because like I said, only a PORTB read causes the problem, but if I read each and every bit from PORTB, then there is no problem, proving no "RAM corruption." I am NOT using a debugger. I am programming the PIC with a PM3, then putting the PDIP into my breadboard, testing, then removing, reprogramming, retesting, etc. More info for you... TRISB is b'11111111' at Reset, but I also manually write that value into TRISB in my init routine, ensuring without a doubt that all of PORTB is set to INPUTS. Each of those 8 inputs (including pin 26) each have an external 100k-ohm pull-up to 5V. Furthermore, there is an 8-switch DIP connected to each of those 8 INPUTS that when switched ON will short the individual INPUTS to Ground. So the problem is that when I have my DIP SW tied to pin-26 to be ON/Ground, the PIC still thinks pin-26 is OFF/5V. And yes, I verified with a DMM that there are no problems at all with my DIP SW and voltage levels. INLVLB is b'11111111' at Reset, but I also tested with it manually set to 0, to no avail. WPUB is set to 0 at Reset, and I also use clrf on that register in my code to ensure internal pullups are Disabled. ODCONB is set to 0 at Reset, and it shouldn't matter since it pertains to sourcing or sinking current on OUTPUT pins -- all my PORTB pins are defined as INPUTS. In any case, I leave that register at its default of 0. SLRCONB is set to b'11111111' ("limited") at Reset. I normally leave it that way. But per your request, I used clrf on it in my init routine, but the problem remains -- changing slew rate has no positive impact. ANSELB is b'11111111' at Reset, but I use clrf on it in my init routine to ensure all pins are DIGITAL I/O. I do NOT have any analog pins. I don't use LATB because that pertains to Outputs. The above are all the registers associated with PORTB, as per TABLE 12-3 given on page 196 of the Revision B datasheet: http://ww1.microchip.com/downloads/en/DeviceDoc/40001826B.pdf And although I do have an ISR, it does not make calls to any routine that writes to my RAM (at 0x077). Furthermore, when I do write to that RAM, interrupts are disabled. |
|
|
|
|
|
我重新检查了数据表只是为了确定,但不,没有位反转可在这个PIC!好吧,以上这些都很奇怪…
以上来自于百度翻译 以下为原文 I rechecked the datasheet just to be sure, but no, no bit reversal is available on this PIC! So well, the above would be really strange... |
|
|
|
|
|
那么你是如何检查“RAMA”和/或“DIPMEM”的内容的?
以上来自于百度翻译 以下为原文 Then how are you examining the content of "RAMa" and/or "DIPmem"? |
|
|
|
|
|
相信我,在RAM中,端口位确实以相反的顺序保存。为什么,我不知道。但在PIC16F1508上也是如此。实际上,我最初在16F1508上编写了代码,它的工作完美无瑕,而且代码是基于事实在BRAM中以相反的顺序保存的。我需要更多的I/O引脚,所以我把ASM代码移植到16F1854。除了我提到的一个故障之外,代码也在PIC上工作得很好。如果这些比特被保存在正常的顺序中,它将不起作用。下面是我的代码的一个缩减版本,那里没有ISR。我提到的问题仍然存在。跳转到我的代码中的“BigdipPLE”来读取问题的详细描述。http://gist.GITHUB.COM/J.6D92B1894E9C4E2E405C.谢谢。
以上来自于百度翻译 以下为原文 Trust me, the PORTB bits are indeed saved in reverse order in RAM. Why, I don't know. But it's also true on the PIC16F1508. I actually wrote the code originally on the 16F1508 and it works flawlessly -- and that code was written based on the fact PORTB bits are saved in reverse order in RAM. I needed more I/O pins so I ported the ASM code to the 16F18554. Except for the one glitch I mentioned, the code works well on that PIC too. It wouldn't work at all if the bits were saved in normal order. Below is a cut-down version of my code, where there is no ISR. The problem I mentioned remains. Jump to "BIGdipper" in my code to read a detailed description of the problem. https://gist.github.com/J...6d392b18944e9c4e2e405c Thanks. |
|
|
|
|
|
在这里,您的DIPSW1CHK反转从PoBB读取的DIPMEM内容。
以上来自于百度翻译 以下为原文 DIPSW1CHK ; Routine takes 13 cycles, including CALL & RETURN. call BIGdipper ; Returns in Bank 0 movf DIPmem, W ; (All HI means All SW = OFF) xorlw b'11111111' ; (Affects Status reg., which is available in all banks.) return ; BIGdipper banksel PORTB ; [Bank 0] ; For some reason the next 2 lines don't work properly. ; The problem is RB5 is being misread in the "DIP Checks" section of Tone6_1. ; More specifically, when DIP SW3 (RB5) & SW6 (RB2) are both ON (Ground) and sound is playing ; through the speaker, if I switch OFF DIP SW6 while Tone6 is still playing, it will ; continue to play forever. In other words, Tone6_1 loops forever instead of sensing ; DIP SW#3 is ON and changing to Tone3_1. But if I leave DIP SW3 & SW6 ON, then those tones ; will play just fine, switching between each other properly. ; Checking RB0 thru RB7 individually (instead of the next 2 lines) solves the problem, but ; I don't understand why. movf PORTB, W ; (HI = SW is OFF) movwf DIPmem ; Save RB0 to RB7 values in RAM. return ; Returns in Bank 0. Here your DIPSW1CHK inverts the content of DIPmem read from PORTB. |
|
|
|
|
|
|
|
|
|
|
|
逆。如果OP真的在倒车,那么我想他只是把DIP开关反向连接了。
以上来自于百度翻译 以下为原文 Inverse. If OP really is getting reverse, then I think he just got the DIP switches wired in reverse. Smile: |
|
|
|
|
只有小组成员才能发言,加入小组>>
MPLAB X IDE V6.25版本怎么对bootloader和应用程序进行烧录
454 浏览 0 评论
5793 浏览 9 评论
2334 浏览 8 评论
2224 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3529 浏览 3 评论
1121浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
1095浏览 1评论
我是Microchip 的代理商,有PIC16F1829T-I/SS 技术问题可以咨询我,微信:A-chip-Ti
872浏览 1评论
MPLAB X IDE V6.25版本怎么对bootloader和应用程序进行烧录
466浏览 0评论
/9
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2025-12-1 17:52 , Processed in 0.998314 second(s), Total 74, Slave 67 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191

淘帖
1665