how to address a register - PIC :)

Started by
3 comments, last by cavemanbob 16 years, 6 months ago
So I have my new PIC to play with :)) Its got all sorts of control registers in addition to memory. So if one of the control registers was actually just a byte in memory, I imagine it's declared in C as
void* CTL_REG = 0x400;
or whatever. But what if it's actually a register - how is it exposed to C?
Advertisement
This would also be a good place to ask if there are any books or online tutorial documentation that I should read to get good at this stuff fast, as opposed to just hacking it out myself from the datasheet. Not just your standard googletard tutorials, but like a really good or standard reference like C :: K&R.
Quote:Original post by thedustbustr
So I have my new PIC to play with :))

Its got all sorts of control registers in addition to memory.

So if one of the control registers was actually just a byte in memory, I imagine it's declared in C as
void* CTL_REG = 0x400;
or whatever. But what if it's actually a register - how is it exposed to C?


If it's a memory-mapped register, do like the above (only use the proper type, not void*). In fact, given that C was original designed to program hardware, you could use advanced features like bitfields in packed structures so you can toggle individual bits in control registers and so on. Scads of fun, a guaranteed laugh a minute.

However, if you're looking at talking to individual registers on the PIC, you'll have to go outside of the language. That means dropping down to assembly.

Sorry.

Stephen M. Webb
Professional Free Software Developer

eewwwwww. thanks.
On PIC processors virtually all the registers are memory mapped. Look in the memory organization section of the data sheet for your processor and it'll provide you with the addresses for them. You can access them from C just as Bregma suggested, the type will always be an unsigned char as long as you aren't messing with the PIC24 line of products.

This topic is closed to new replies.

Advertisement