control microcontroller outputs with array

Thread Starter

ecka333

Joined Oct 1, 2009
76
It is possible to control pic microcontroller outputs easy with array? For example, i want to control RA0, RA1 and RA2 outputs only and set RA0 to 0, RA1 to 0 and RA2 to 1. I will create variable:

unsingned short int PORT[3]={PORTA.B0, PORTA.B1, PORTA.2}.

Is any way simply to set desired RA0, RA1 and RA2 low or high, like:

PORT[3]={0, 0, 1}.

or i must to set each output separately, like:

PORT[0]=0;
PORT[1]=0;
PORT[2]=1;
 

t06afre

Joined May 11, 2009
5,934
You can use bitwise operations in C. To clear a bit you and the corresponding bit with "0" and to set a bit. The bit you want unchanged you use the value "1". You or the corresponding bit you want to set with "1", and use the value "0" for the rest. As an example your problem
Rich (BB code):
PORTA=PORTA & 0b11111100 //clear bit 0 and 1
PORTA=PORTA | 0b0000100   //set bit 2
With two operations you can set and clear any bit you want in any integer type value
You can read more about here http://www.vipan.com/htdocs/bitwisehelp.html
If the changes need to appear at the same time. You will have to read the port into a dummy value. Then make the changes on the dummy value. And write the dummy value back to port
 

Thread Starter

ecka333

Joined Oct 1, 2009
76
Yes, i know things about what you talking. But my question was about possibility simply to control microcontroller outputs using ARRAY.
 
Top