PDA

View Full Version : An easy way to get bits to byte



longpole001
- 30th October 2015, 14:48
Hi guys i seem to recall there was a simply way to do this but i cant recall how

number is stored as 3 bits to represent 0 -7 value as part of a stored byte
i need display byte to be a bit representation

eg
stored bit0,1,2 = value 0 = display byte- all bits off
stored bit0,1,2 = value 1 = display byte- bit0 on ,display byte bits 1-7 off
stored bit0,1,2 = value 2 = display byte- bit1 on, display byte bit0,2-7 off
stored bit0,1,2 = value 3 = display byte- bit2 on, display byte bit0,1,3-7 off
stored bit0,1,2 = value 4 = display byte- bit3 on, display byte bit0-2,4-7 off
stored bit0,1,2 = value 5 = display byte- bit4 on, display byte bit0-3,5-7 off
stored bit0,1,2 = value 6 = display byte- bit5 on, display byte bit0-4,6-7 off
stored bit0,1,2 = value 7 = display byte- bit6 on, display byte bit0-5,7 off

Jerson
- 30th October 2015, 15:26
Isn't that the DCD command you're talking about?

longpole001
- 30th October 2015, 18:21
yep , could not think of the command , cheers jerson

longpole001
- 31st October 2015, 04:04
trouble is value of 0 turns on bit 0 in the display byte

longpole001
- 31st October 2015, 11:13
val = DCD (((Event_Conf_Byte4 & $1C) >>2) - 1)



this did the job , but the output is always on even if the value = 0 , so just worked arround it for what i need

Art
- 5th November 2015, 18:06
It sounds easier than what you posted above, but I don’t know if I’m reading your first post right.

"
stored bit0,1,2 = value 4 = display byte- bit3 on, display byte bit0-2,4-7 off

Is that the same as saying:
displaybyte.bit3 is set and all other bits are off, so in a different byte, set it’s bits 0,1 & 2 to a binary 4 so the new byte is 00000100 ?

longpole001
- 6th November 2015, 07:04
hi art
for what i really i needed the lowest value was 1 highest was 6 so the -1 option works ok , in this instance using dcd is ok

0 was not a possiblity in this setting
but if the value of 0 was to show nothing then dcd is not going work
cheers

sheldon

BTW hows your light show project going with the neon lights

Art
- 6th November 2015, 11:16
So long as it’s working I suppose you’re happy!

Are you subscribed to me on YouTube? I didn’t think I posted it here.
From what I said on YouTube my ideas have changed a bit, and it’s a bit of financial commitment.
I want to use red, green and blue neon tubes, and dim/blend them for different colours.

Once the switching is sorted out with solid state relays I don’t think it’s a real big project in any way other than paying for it :D