Search code examples
cpicmplabxc8

use of undeclared identifier 'RD16'


I am trying to set the TMR1 T1CON register for a PIC18F4550 but I am getting an error related to the RD16 bit.I am getting :

config.c:17:1: error: use of undeclared identifier 'RD16'
RD16 = 1;
^
1 error generated.

Acording to datasheet :

RD16: 16-Bit Read/Write Mode Enable bit

1 = Enables register read/write of Timer1 in one 16-bit operation

0 = Enables register read/write of Timer1 in two 8-bit operations

I read some posts and it should be correct.Im ussing XC8 and MPLab

my config.c complete code :

#include <xc.h>
void configPIC(void){
    T3CCP2:T3CCP1 = 01;   //TMR1 para CCP1    
    CCP1M0 = 0;           //Captura flancos de subida
    CCP1M1 = 1;
    CCP1M2 = 0;
    CCP1M3 = 1;
    CCP1IF = 0 ;          //Bandera de Captura CCP1
}

void timer1config(void){
    //TMR1 Config Registros   
    TMR1ON = 1;
    RD16   = 1;
    T1RUN  = 0;     //Usar reloj interno
    TMR1CS = 0;     // FOSC / 4
    T1CKPS1:T1CKPS0 = 00;
    T1OSCEN = 0;
}

Solution

  • RD16 bit is inside T1CON byte / register. The xc.h header specifies it as a bitfield member inside T1CONbits structure like this, taken from here:

    extern volatile near union {
      struct {
        unsigned TMR1ON:1;
        unsigned TMR1CS:1;
        unsigned T1SYNC:1;
        unsigned T1OSCEN:1;
        unsigned T1CKPS0:1;
        unsigned T1CKPS1:1;
        unsigned T1RUN:1;
        unsigned RD16:1;
      };
      struct {
        unsigned :2;
        unsigned NOT_T1SYNC:1;
      };
    } T1CONbits;
    

    You should use it like this:

    T1CONbits.RD16 = 1;
    

    as all the other bits inside any register on PICs devices. Inspect the p18f4500.h header to find out the names for all registers.

    PS. Anyway, I would like to add, that if you are using PIC18 for a custom project using free xc8 compiler or sdcc compiler, don't do it, put all your pic devices into the trash bin and buy cheaper, faster, better and simpler STM32 devices. Unless you are using paid xc8 compiler or working for a project where PICs are a must, don't waste your time.