1
完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
HI论坛,我有一个奇怪的问题与我的PIC16F87,无论我写什么给波尔塔反转。如果我写0引脚高,如果我写1引脚低。我已经在数据表上过了好几次,但都不知道什么样的寄存器或位我错过了设置/清除我使用一个非常简单的代码来设置POTA:它调用下面的查找表:当滚动查找表时,代码工作正常。但不是1高引脚和7低,我有1低引脚和7高。这不是什么大问题,因为我可以在使用波尔塔之前使用反相W,但是让我感到沮丧的是我看不到我错过了什么。有人有答案吗?
以上来自于百度翻译 以下为原文 Hi Forum, I have a strange issue with my PIC16F887 where whatever I write to PORTA gets inverted. If i write 0 the pin goes high, if i write 1 the pin goes low. I've been over the datasheet several times but can't figure out what register or bit i missed to set/clear I'm using a very simple code to set PORTA: SetLeds bcf STATUS, RP0 bcf STATUS, RP1 movf currentOctA,w call GetLedPort movwf PORTA return which call the following lookup table: GetLedPort andlw b'00000111' movwf lookuptemp movlw HIGH tblLeds movwf PCLATH movfw lookuptemp addlw LOW tblLeds btfsc STATUS,C incf PCLATH, F movwf PCL tblLeds dt b'00000001' dt b'00000010' dt b'00000100' dt b'00001000' dt b'00010000' dt b'00100000' dt b'01000000' dt b'00000000' The code works as expected when scrolling through the lookup table. But instead of 1 high pin and 7 low, I have 1 low pin and 7 high. It's no big issue since I can use invert W before writing to PORTA, but it's frustrating that I can't see what I am missing. Anyone has the answer ? |
|
相关推荐
16个回答
|
|
你是真的测量引脚上的电压还是说LED是开/关?如果你在谈论LED,它们是连接到GND还是VCC?
以上来自于百度翻译 以下为原文 Are you really measuring the voltage at the pin or are you talking about LED is on/off ? If you are talking about the LEDs, are they connected to GND or VCC ? |
|
|
|
嗨,罗迪姆,我在测量引脚的电压。LED通过电阻连接到GND,我想是440R。
以上来自于百度翻译 以下为原文 Hi rodims, I'm measuring the voltage at the pin. The leds are connected to GND via resistor, 440r I think. |
|
|
|
如果你不使用,会发生什么?
以上来自于百度翻译 以下为原文 what happens if instead of movf currentOctA,w call GetLedPort movwf PORTA you use MOVLW B’00000001’ movwf PORTA |
|
|
|
现在试一试。正如预期的那样,引脚7至1的高和引脚0是低的。
以上来自于百度翻译 以下为原文 Tried it now. As expected, Pin 7 to 1 high and pin 0 is low. |
|
|
|
从你的其他答案,我假设在同一时间,这意味着,LED 0关闭,另一个LED 1…7是开着的?
以上来自于百度翻译 以下为原文 From your other answers I assume that at the same time this means, LED 0 is OFF and the other LED 1..7 are ON ? |
|
|
|
|
|
|
|
PIC内的数据没有反转。数据表清楚地描述了PARTA1=端口PIN & GT;VIH(2.0V)0=端口PIN & lt;VIL(0.8V),如果可以,尝试从Prt0分离,例如ReD0并再次检查(伏特计),这是什么样的板?自制,原型,购买开发板?这是一个原型PCB,从上面的答案中给出你的答案图,我假设它看起来像这样,但是用PATA而不是PoBHTHTPSE//www. mikROE.COM/eBooSs/PIC-微控制器编程-c/Expple -4。
以上来自于百度翻译 以下为原文 There is no inversion of the data inside the PIC The data sheet clearly states for PortA 1 = Port pin is > VIH (2.0V) 0 = Port pin is < VIL (0.8V) If you can, try detaching e.g. LED0 from PORTA0 and check again (Voltmeter) What kind of board is this ? Selfmade, prototyping, purchased development board ? Is this a prototyping PCB post your schematic for the LEDs From your answer above I assume it looks something like this, but with PORTA instead of PORTB https://www.mikroe.com/ebooks/pic-microcontrollers-programming-in-c/example-4 |
|
|
|
你能做一个简单的演示程序,并发布整个程序吗?我怀疑一个银行选择错误是让你把数据写到TrISA而不是PoTA,但是你在这里发布的代码中没有任何东西支持这个想法。
以上来自于百度翻译 以下为原文 Can you make a simple demonstration program, and post the entire program? My suspicion is a bank selection error is making you write the data to TRISA rather than PORTA, but there's nothing in the code you have posted here to support that idea. |
|
|
|
上面的代码使PATA变低了。清除端口使管脚变高。芯片是在一个电路板上,我正在测量完整的VDD作为PIN GO高。
以上来自于百度翻译 以下为原文 LIST p=16F887 include "P16F887.inc" errorlevel -302 __CONFIG _CONFIG1, _FOSC_INTRC_NOCLKOUT & _WDTE_OFF & _PWRTE_ON & _MCLRE_ON & _CP_OFF & _CPD_OFF & _BOREN_ON & _IESO_ON & _FCMEN_ON & _LVP_OFF __CONFIG _CONFIG2, _BOR4V_BOR40V & _WRT_OFF RES_VECT CODE 0x0000 GOTO START START bcf STATUS, RP1 bcf STATUS, RP0 ; Bank 0 clrf PORTA ; Init PORTA bsf STATUS, RP0 ; Bank 1 movlw b'00000000' ; movwf TRISA ; all output bsf STATUS, RP0 ; Bank 3 bcf CM1CON0,7 ; turn off comp bcf CM2CON0,7 movlw b'00000000' movwf ANSEL ; All digital bcf STATUS, RP1 ; bank 0 movlw b'00000000' movwf PORTA LOOP goto LOOP END The above code makes PORTA go low. Clearing PORTA makes the Pins go high. Chip is on a breadboard and i'm measuring full VDD as pin go high. |
|
|
|
不,您通过设置RP0然后清除RP1返回银行0来改变银行3吗?我看起来不对劲。你的银行选择对我来说是错误的。
以上来自于百度翻译 以下为原文 nope, you change to bank 3 by setting RP0 then clear RP1 to back to bank 0? doesn't look right to me. START bcf STATUS, RP1 bcf STATUS, RP0 ; Bank 0 <---- both RP0 and RP1 low clrf PORTA ; Init PORTA bsf STATUS, RP0 ; Bank 1 <---- RP0 high and RP1 low movlw b'00000000' ; movwf TRISA ; all output bsf STATUS, RP0 ; Bank 3 <---- RP0 high and RP1 low bcf CM1CON0,7 ; turn off comp bcf CM2CON0,7 movlw b'00000000' movwf ANSEL ; All digital bcf STATUS, RP1 ; bank 0 <---- RP0 high and RP1 low movlw b'00000000' movwf PORTA LOOP goto LOOP END Your bank selects look wrong to me. maybe use the banksel macro? |
|
|
|
这应该是
以上来自于百度翻译 以下为原文 This bsf STATUS, RP0 ; Bank 3 should be bsf STATUS, RP1 ; Bank 3 |
|
|
|
试试这个:
以上来自于百度翻译 以下为原文 Try this: START banksel PORTA clrf PORTA ; Init PORTA banksel ANSEL clrf ANSEL ; All digital banksel TRISA clrf TRISA ; all output banksel PORTA movlw b'00000000' movwf PORTA LOOP goto LOOP |
|
|
|
作品!谢谢!将通过我的主要代码银行更改。谢谢!
以上来自于百度翻译 以下为原文 Works!, thanks! Will go through the bank changes in my main code. Thanks a lot! |
|
|
|
好的,所以在总结(1)中,这是一个银行选择问题,正如我猜想的那样。(2)BoSSE-Grac宏比在查询一个奇怪的问题时手动地复制你的真实代码更安全,而不是你认为你的代码在做什么的“示例”……
以上来自于百度翻译 以下为原文 ok, so in summary [1] It WAS a bank selection problem, as I guessed. [2] The BANKSEL macro is much safer than twiddling the RPx bits manually [3] Post your real code when asking about a strange problem, not an "example" of what you think your code is doing... |
|
|
|
是的,有帮助,但它确实需要一些冒险,你不觉得吗?眨眼:眨眼:
以上来自于百度翻译 以下为原文 Yes, helpful but it does take some of the adventure out of it, don't you think? wink: wink: |
|
|
|
理解!但一切都好,结局好吗?)我现在有非常好的状态LED用于我的PWM代码:
以上来自于百度翻译 以下为原文 Understood! But...all is well that ends well ? :) I've got really nice status leds for my PWM-code now :) |
|
|
|
只有小组成员才能发言,加入小组>>
5238 浏览 9 评论
2028 浏览 8 评论
1950 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3204 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2253 浏览 5 评论
778浏览 1评论
666浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
595浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
677浏览 0评论
576浏览 0评论
小黑屋| 手机版| Archiver| 德赢Vwin官网 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-23 07:15 , Processed in 2.221961 second(s), Total 107, Slave 91 queries .
Powered by 德赢Vwin官网 网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
德赢Vwin官网 观察
版权所有 © 湖南华秋数字科技有限公司
德赢Vwin官网 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号