View previous topic :: View next topic |
Author |
Message |
Somkiat
Joined: 30 Mar 2004 Posts: 8
|
How to declare variable like this |
Posted: Tue Jul 20, 2004 1:33 am |
|
|
I have array
BYTE Dout[4];
I want to declare bit 5 in Dout[2] is VP for use like this
VP=1;
or
VP=0;
How can I declare VP ?
Thanks |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Jul 20, 2004 2:56 am |
|
|
If you don't want to use a union and bitfields, then you
can use the method shown below. Compile this program
and look at the assembly listing (.LST file) to see that it works.
Code: | #include <16F877.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 4000000)
BYTE Dout[4];
#byte Dout2 = Dout + 2
#bit VP = Dout2.5
//====================================
void main()
{
VP = 1;
while(1);
} |
|
|
|
rnielsen
Joined: 23 Sep 2003 Posts: 852 Location: Utah
|
|
Posted: Tue Jul 20, 2004 8:34 am |
|
|
Would this also work?
bit_set(Dout[2], 5);// sets bit 5 of Dout[2]
or
bit_clear(Dout[2], 5);// clears bit 5 of Dout[2]
Ronald |
|
|
Neutone
Joined: 08 Sep 2003 Posts: 839 Location: Houston
|
|
Posted: Tue Jul 20, 2004 8:46 am |
|
|
I'm sure that works but it does not read as well as this;
VP=1;
or
VP=0; |
|
|
|