Frequently Asked Questions

How do I directly read/write to internal registers?

A hardware register may be mapped to a C variable to allow direct read and write capability to the register. The following is an example using the TIMER0 register:

#BYTE timer0 = 0x01 
timer0= 128; //set timer0 to 128 
while (timer0 ! = 200); // wait for timer0 to reach 200

Bits in registers may also be mapped as follows:

#BIT T0IF = 0x0B.2 
while (!T0IF); //wait for timer0 interrupt

Registers may be indirectly addressed as shown in the following example:

printf ("enter address:"); 
a = gethex (); 
printf ("\r\n value is %x\r\n", *a);

The compiler has a large set of built-in functions that will allow one to perform the most common tasks with C function calls. When possible, it is best to use the built-in functions rather than directly write to registers. Register locations change between chips and some register operations require a specific algorithm to be performed when a register value is changed. The compiler also takes into account known chip errata in the implementation of the built-in functions. For example, it is better to do set_tris_A(0); rather than *0x85=0;