A problem about how to "combine the respective bits"
Hello everyone !!
I encountered a problem which about how to "combine the respective bits" by 6 bits.
Example :
I want to display the 6bit as "010101" at a time !
How to do it ??
Are there any answers or suggesstions ?
Thanks a lot !!
I encountered a problem which about how to "combine the respective bits" by 6 bits.
Example :
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
VAR long Value[6]
OBJ
Debug: "FullDuplexSerialPlus"
PUB Main
Value[0] := 1
Value[1] := 0
Value[2] := 1
Value[3] := 0
Value[4] := 1
Value[5] := 0
Display
PUB Display
Debug.start(31, 30, 0, 57600)
Debug.tx(16)
repeat
Debug.str(string("Display_Value_By_6Bit:", 13))
Debug.Bin(Value[6],6)
Debug.str(string(13))
waitcnt(clkfreq/2 + cnt)
I want to display the 6bit as "010101" at a time !
How to do it ??
Are there any answers or suggesstions ?
Thanks a lot !!
Comments
pub main term.start(RX1, TX1, %0000, 115_200) waitcnt(clkfreq / 1000 + cnt) value := 0 value := putbit(value, 0, 1) value := putbit(value, 1, 0) value := putbit(value, 2, 1) value := putbit(value, 3, 0) value := putbit(value, 4, 1) value := putbit(value, 5, 0) term.str(string("Value = ")) term.bin(value, 6) repeat waitcnt(0) pub putbit(target, pos, bitval) '' writes bitval.0 to target.pos if (bitval & 1) return target | (1 << pos) else return target & !(1 << pos)
Note that you don't need to re-start FDS every time you need it -- just set it up at the top of your program.
PUB putbit(target, pos, bitval) dirb := target dirb[pos] := bitval return dirb
The question have been solved !!