向端口发送表格值给我错误的值
我正在尝试在PIC18F4550上编写一个程序,其中我的内存中定义了数据,并希望按字符将其发送到Portc字符。我已经这样做了,但是PORTC上显示的值不是Tablat寄存器中显示的值。例如,在我的代码中,字符串“名称”读为“ faee”。我尝试将它们存储在文件寄存器中,并且Wreg和值正确显示。这是港口的正常行为,还是我错过了什么?我正在使用MPLAB v5.30上的模拟器工具
LIST p=18f4550
INCLUDE <p18f4550.inc>
ORG 0x00 ; Program Origin/Start Address
MAIN
CLRF TRISC
MOVLW 0X0
MOVWF TBLPTRL
MOVLW 0X05
MOVWF TBLPTRH
READ
TBLRD*+
MOVF TABLAT, W
BZ EXIT
MOVWF PORTC
GOTO READ
EXIT
GOTO $ ; This Line Is To Keep The Program Running, Not To Terminate
ORG 0x500
NAME DB "NAME",'0'
END ; Program End
I'm trying to write a program on PIC18F4550 where I have data defined in my memory and want to send it to PORTC character by character. I have done so but the values showing on PORTC are not the ones shown in the TABLAT register. For example, in my code, the string "NAME" is read as "FAEE". I have tried storing them in a file register and the WREG and the values show up correctly. Is this normal behaviour for ports, or am I missing something? I'm using the simulator tool on MPLAB V5.30
LIST p=18f4550
INCLUDE <p18f4550.inc>
ORG 0x00 ; Program Origin/Start Address
MAIN
CLRF TRISC
MOVLW 0X0
MOVWF TBLPTRL
MOVLW 0X05
MOVWF TBLPTRH
READ
TBLRD*+
MOVF TABLAT, W
BZ EXIT
MOVWF PORTC
GOTO READ
EXIT
GOTO $ ; This Line Is To Keep The Program Running, Not To Terminate
ORG 0x500
NAME DB "NAME",'0'
END ; Program End
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
C端口上的某些引脚用替代硬件(例如 ccp 和 usb )多路复用。如果相关引脚未正确配置,即使您将其设置为TRISC,这可能会导致行为问题。
CCP2在config中默认用RC1 PIN多路复用。因此,您必须更改该配置位并将其设置为0,以便将CCP2用RB3引脚多路复用。这将释放RC1 PIN用于通用使用IO。我认为您使用MPASM来编译组件。对于这种情况,您需要添加此行才能实现:
usb 如果启用了 ,则可以更改 rc4 和 rc5的TRIS设置引脚。尽管在重置上禁用了USB,但您可以将其禁用以防止在您启动程序时在Portc上进行错误的行为。
Some pins on C port are multiplexed with alternate hardware such as CCP and USB. This may cause behavioural issues if the related pins are not configured correctly even you set them output in TRISC.
CCP2 Is multiplexed with RC1 pin by default in CONFIG. Therefore you have to change that config bit and set it to 0 so that the CCP2 to be multiplexed with RB3 pin. This will free the RC1 pin for general purpose IO usage. I think you use mpasm to compile assembly. For this case you need to add this line to achieve it:
The USB becomes high priority if it is enabled and can alter the tris setting of the RC4 and RC5 pins. Although the USB is disabled on reset you can disable it to prevent erronous behaviours on PORTC when you init your program.