Home > Enterprise >  Sending TABLAT value to a port gives me the wrong value
Sending TABLAT value to a port gives me the wrong value

Time:06-02

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
            


CodePudding user response:

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
  • Related