Jump to content
  • Advertisement
Sign in to follow this  
thedustbustr

how to address a register - PIC :)

This topic is 4097 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!