Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Array of pointers to 16 series port SFRs.

Status
Not open for further replies.

Pommie

Well-Known Member
Most Helpful Member
I need an array of pointers to SFRs in a 16 series chip. The only way I've found so far that doesn't give me warnings is,
Code:
uint8_t * ports[8]={(uint8_t *)&LATB,(uint8_t *)&LATB,(uint8_t *)&LATB,(uint8_t *)&LATB,
                    (uint8_t *)&LATC,(uint8_t *)&LATC,(uint8_t *)&LATC,(uint8_t *)&LATC};
Is there a simpler way to achieve the same thing?

I know there are other ways to code this but eventually it'll have to be an array of pointers.

Thanks,

Mike.
 
Aren't there more than 256 registers in a 16-series chip? So Uint8_t does not have enough bits to identify the register (with bank).

also, aren't the LATB and LATC registers sequential so you only need one of each or, one overall since the LATC registers are next to the LATB registers?

and all possible values of LATC or LATB or LATA are one register (address). What exactly are you trying to do?

0244C84A-A85B-4D8C-9C44-5E084E8DECE1.jpeg
 
Last edited:
It's a pointer to a uint8_t and will be 16 (or 14) bit. I used LAT as an example, the actual SFRs I'm writing to are the RBnPPS & RCnPPS registers and I didn't want people to get distracted by the actual registers. The above code seems a little long winded and I was wondering if there was a simpler way.

Mike.
Edit, in case someone comes across this in the future, to place the array in flash and not ram requires the const keywork after the *.
I.E.
Code:
uint8_t * const ports[8]={(uint8_t *)&LATB,(uint8_t *)&LATB,(uint8_t *)&LATB,(uint8_t *)&LATB,
                    (uint8_t *)&LATC,(uint8_t *)&LATC,(uint8_t *)&LATC,(uint8_t *)&LATC};
 
Last edited:
Sorry Mike.. Only just seen this..

I usually go straight to the header file.. Herein lies many pointers to SFR's so I normally copy what they have done...

Everything in the header is normally typedef'd anyway... But they scope the pointers with "attribute section" so You seem to have helped me out..
 
It's actually making sense now as &PORTB is just a 16 bit address so the compiler needs to know it's a uint8_t pointer. However, I thought it was obvious I was defining an array of uint8_t pointers. To be fair, it did compile but gave lots of pointer conversion type warnings. I don't like any warnings now and try to get rid of them as in the past I've missed actually errors due to them being obscured by warnings. Also not sure why the const has to be placed after the *.

Mike.
 
The const puts the array of ram pointers in flash (program memory). Remove the const and ram usage goes up by 16 bytes.

Mike.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top