This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Is there a way access the hardware registers in 'C' level?



I am trying various approaches to make a elegant in-line asm and C combination. But I am facing few stumbling blocks in any which way I try to progress?

Is there not a way to access the hardware register from 'C' level. Earlier, in PC, Boralnd C used to provide such a feature as custom extension that I found extremely useful.

Any thoughts?

Sayee

  • The simplest approach is to use a #define to cast an address to a pointer like this

    #define REG_NAME (*((unsigned char*)0x1234)) // register at address 0x1234

    This assumes the register is a one byte sized register.  If it is of a different size or you want to refer to it as a signed type, simply use the appropriate C data type when casting it as a pointer to that type.

    Now you can use it like any variable as in

    REG_NAME = 5; // assign 5 to register at address 0x1234

    unsigned char my_var = REG_NAME; // read value of register at address 0x1234

    There are other more complicated ways allowing you to seperate bitfields within the register to use as variables but this should get you started.

    Jim Noxon

  • As a complement, you can find some nice notes here:

    http://www.ti.com.cn/cn/lit/an/spra250/spra250.pdf