Accessing Multiple SFR Register Bits

mikroC, mikroBasic and mikroPascal PRO for Microchip’s 8-bit PIC MCUs.
Post Reply
Author
Message
roys29
Posts: 106
Joined: 13 Oct 2009 15:09

Accessing Multiple SFR Register Bits

#1 Post by roys29 » 19 May 2022 05:12

Is it possible to create a variable that has 8 bits (byte?) so that each bit accesses a different SFR register bit? For example, I want to access PORTA bits 0-3 and PORTB bits 0-3. So, if I set the variable to %00010001 RA0 and RB0 would set. I know I could do it with a subroutine by passing a byte variable and setting the appropriate register bits, but I just wonder if there is an easy way? Thanks in advance for your help.

User avatar
filip
mikroElektronika team
Posts: 11874
Joined: 25 Jan 2008 09:56

Re: Accessing Multiple SFR Register Bits

#2 Post by filip » 19 May 2022 09:12

Hi,

You can do this using bit fields/union if I'm correct.

Regards,
Filip.

roys29
Posts: 106
Joined: 13 Oct 2009 15:09

Re: Accessing Multiple SFR Register Bits

#3 Post by roys29 » 20 May 2022 02:03

I'm not sure how the union works. Can you give me an example? Thanks.

Soumitrab
Posts: 156
Joined: 08 Jan 2012 07:28

Re: Accessing Multiple SFR Register Bits

#4 Post by Soumitrab » 23 May 2022 18:39

Lets say your var is X (byte / unsigned int)
so the easiest way is

Code: Select all

X.B0 := PORTA.B0
...X.B3 := PORTA.B3
X.B4 := PORTB.B0
...X.B7 := PORTB.B3

Post Reply

Return to “PIC PRO Compilers”