PDA

View Full Version : Individual Variable bits



tazntex
- 31st January 2008, 14:40
Good Morning to All,
I was wondering if I declared a variable such as, train var byte, then I had another variable, car var byte, in which if there was a car car.0[0] =1 and I wanted to send to portb the bits in train 1,2,3,4,5,6,7 to make portb pins 1-7 high or low depending on how the bits are set in train but I wanted portb.0 to be high or low depending on the value of car. In this way I could have portb pin 0 showing a car is there and portb pins 1-7 providing high or low outputs to control other things. How could I do this together? The Pic I am using is a 16f628a.

skimask
- 31st January 2008, 15:11
Alias...
In the manual...
Read and learn...

tazntex
- 31st January 2008, 15:37
Thanks for steering me in the right direction. I will try it.

sayzer
- 31st January 2008, 15:44
Here is what you need.


http://www.picbasic.co.uk/forum/showthread.php?t=3753


If you still have questions, post it to that thread.

paul borgmeier
- 31st January 2008, 18:27
Good Morning to All,
I was wondering if I declared a variable such as, train var byte, then I had another variable, car var byte, in which if there was a car car.0[0] =1 and I wanted to send to portb the bits in train 1,2,3,4,5,6,7 to make portb pins 1-7 high or low depending on how the bits are set in train but I wanted portb.0 to be high or low depending on the value of car. In this way I could have portb pin 0 showing a car is there and portb pins 1-7 providing high or low outputs to control other things. How could I do this together? The Pic I am using is a 16f628a.


If I understand you correctly, you want PORTB to be equal to bit0 from CAR and bits1-7 from TRAIN?



SETB VAR BYTE

' In your program somewhere

SETB = TRAIN
SETB.0 = CAR.0 ' redefine bit0 to match that of Car's bit 0
PORTB = SETB ' set PORTB equal to the desired values of bit 0 from Car and bits 1-7 from train

This could also be easily done with boolean (bitwise) algebra if speed or program size is of importantance.