向端口发送表格值给我错误的值

发布于 2025-02-03 08:44:19 字数 1033 浏览 4 评论 0原文

我正在尝试在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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

静谧 2025-02-10 08:44:19

C端口上的某些引脚用替代硬件(例如 ccp usb )多路复用。如果相关引脚未正确配置,即使您将其设置为TRISC,这可能会导致行为问题。
CCP2在config中默认用RC1 PIN多路复用。因此,您必须更改该配置位并将其设置为0,以便将CCP2用RB3引脚多路复用。这将释放RC1 PIN用于通用使用IO。我认为您使用MPASM来编译组件。对于这种情况,您需要添加此行才能实现:

__CONFIG _CCP2MX_OFF_3H

usb 如果启用了 ,则可以更改 rc4 rc5的TRIS设置引脚。尽管在重置上禁用了USB,但您可以将其禁用以防止在您启动程序时在Portc上进行错误的行为。

CLRF    UCON ; Set all UsbCONtrol register bits to zero

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:

__CONFIG _CCP2MX_OFF_3H

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.

CLRF    UCON ; Set all UsbCONtrol register bits to zero
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文