Absolute addresing to TMR1 in 14bit PICs

  • DenJohX

    DenJohX - 2010-09-02

    I have a Debian testing GNU/Linux machine with sdcc installed and working well.

    ~$ sdcc -v
    SDCC : mcs51/gbz80/z80/avr/ds390/pic16/pic14/TININative/xa51/ds400/hc08 2.9.0 #5416 (Jan 10 2010) (UNIX)

    I want to declare an unsigned short variable to have direct access to TMR1L and TMR1H (low and high nibbles of TMR1 register).

    I've tried this:

    void main() {
        unsigned short at 0x00e tempo1;
        // ... some stuff here
        tempo = 0; // direct reset of timer 1
        // ...more stuff

    0x00e is the address of TMR1L, but the generated .asm code is not declaring the tempo1 variable to the especified addres, instead it declares it like any other variable:

    ; compiler-defined variables
    UDL_project_0   udata
    r0x1001 res 1
    r0x1002 res 1

    r0x1001 and r0x1002 are the registers generated to be used in the tempo1 variable, but they aren't assigned to the 0x00e address.

    ¿So, is it possible to declare an absolute addressed variable this way or i'm missing something?


    PD. Sorry for my bad english, it isn't my first language.

  • Oliver Sedlacek

    Oliver Sedlacek - 2010-09-02

    The way to declare a special function register like TMR1L is:

    extern __sfr __at 0x000E TMR1L;

    I would not declare them in my project as they are all declared in header files that are included with SDCC. All you need to do is #include <pic16cxxx.h> and you should be in business.

  • DenJohX

    DenJohX - 2010-09-02

    Tanks for your answer.

    But thats not what i mean, i know that including the specific heades gives me the complete set of memory declared with their respective names.

    What i want is a fast-cheap instruction to load and read data to TMR1L and TMR1H, which are the two 8bit nibbles of the 16bit register TMR1, so i can do things like this:

    unsigned short at 0x00e timer1; // declaring a 16 bit variable in the address of TMR1L (so it contains TMR1H too)
    unsigned short temp; // another 16 bit variable
    // some stuff...
    timer1 = 0; //handy reset, without doing it indivdually for TMR1L and TMR1H
    // some stuff...
    timer1 = 36210; // handy direct set, without dealing whit confusing numbers in TMR1L and TMR1H
    // some stuff..
    temp = timer1; // direct read, without loading variable "temp" nibble per nibble
    // an so on...

    The idea is to take advantage of the short (16 bit) C type and get rid of complex 8bit operations.


Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks