hippy
Ex-Staff (retired)
PICAXE-18X Firmware 8.1, Editor 4.1.4
It's probably going to be argued as not a bug, but PEEK and READ behaviour is not what I'd expected, not clearly explained in the manual, nor consistant with other PICAXE statements ...
- w0 = $1234
- POKE $50,$AB
- PEEK $50,w0
- SERTXD(#w0,CR,LF)
- w0 = $1234
- WRITE $50,$AB
- READ $50,w0
- SERTXD(#w0,CR,LF)
In both cases the value in w0 after the PEEK or READ is 4779 ($12AB); only the LSB is updated.
I expected that the MSB would be cleared as it is when performing the following 'take a byte value and store it in a word variable' statements ...
LET w0 = b2
INFRAIN w0
INFRAIN2 w0
READADC PIN,w0
READI2C LOC,w0
READTEMP PIN,w0
SERIN PIN,BAUD,w0
Do any of the above actually not clear the MSB when reading a byte value ?
Obviously when using PEEK or READ to retrieve a word value, two such statements need to be done to obtain the MSB and LSB, but it's the handling logic of a byte value being stored in a word value is where the discrepency / confusion occurs.
Personally I'd like to see the MSB cleared when using word variables, or the command limited to only accepting byte variables as the operand.
While the manual alludes to only byte variables being used with PEEK, the READ desciption infers that any variable can be used, and doesn't mention this side effect ( ditto for READMEM ).
It's probably going to be argued as not a bug, but PEEK and READ behaviour is not what I'd expected, not clearly explained in the manual, nor consistant with other PICAXE statements ...
- w0 = $1234
- POKE $50,$AB
- PEEK $50,w0
- SERTXD(#w0,CR,LF)
- w0 = $1234
- WRITE $50,$AB
- READ $50,w0
- SERTXD(#w0,CR,LF)
In both cases the value in w0 after the PEEK or READ is 4779 ($12AB); only the LSB is updated.
I expected that the MSB would be cleared as it is when performing the following 'take a byte value and store it in a word variable' statements ...
LET w0 = b2
INFRAIN w0
INFRAIN2 w0
READADC PIN,w0
READI2C LOC,w0
READTEMP PIN,w0
SERIN PIN,BAUD,w0
Do any of the above actually not clear the MSB when reading a byte value ?
Obviously when using PEEK or READ to retrieve a word value, two such statements need to be done to obtain the MSB and LSB, but it's the handling logic of a byte value being stored in a word value is where the discrepency / confusion occurs.
Personally I'd like to see the MSB cleared when using word variables, or the command limited to only accepting byte variables as the operand.
While the manual alludes to only byte variables being used with PEEK, the READ desciption infers that any variable can be used, and doesn't mention this side effect ( ditto for READMEM ).