Hi
I'm having a problem with Rotate Right command, it doesn't do a proper bit shift operation but it copies msb to the right; for instance:
'Chip model
#chip 16F690,4
#config _INTRC_OSC_NOCLKOUT, _WDT_OFF,_PWRTE_OFF,_MCLRE_OFF,_CP_OFF, _BOR_OFF, _IESO_OFF,_FCMEN_OFF
#define LCD_IO 2
#Define LCD_DB Porta.0 'Required: pin where Data Bit is wired
#Define LCD_CB Porta.1 'Required: pin where Clock Bit is wired
#Define Dallas PORTC.0 'Dallas/Maxim DS18b20 wiring
do
Rotation = b'10000000'
for loopprg=1 to 8
LOCATE 1,1
PRINT "___"
LOCATE 1,1
LCDINT Rotation
Rotate Rotation Right
wait 1 s
next loopprg
loop
Instead of 128 (bin 10000000), 64 (bin 01000000) and so on, the program print on LCD 128 (starting value for variable) , the second value becames 192 (bin 11000000), the third 224 (bin 11100000).
It really seems that Rotate command copy msb instead of shifting it.
Greetings & Thanks for your answer
P.S. Another question: why Print (LCD command) don't print space made strings? (" "). It would be a big help to clean LCD positions.
Stefano B.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
It would seem that I have neglected to document the way that the ROTATE command works properly!
This is a result of the way that the rlf and rrf assembly mnemonics work - STATUS.C acts as a ninth bit of the variable that is being rotated. When a variable is rotated right, STATUS.C is placed into the MSB of the variable Rotation, and the LSB of Rotation is placed into STATUS.C.
For now, the way to work around this is to add some code to set STATUS.C to the least significant bit of the variable, like this:
SET STATUS.C OFF
IF Rotation.0 ON THEN SET STATUS.C ON
Rotate Rotation right
This will make your program work as expected. In the next version of GCBASIC, I'll fix the documentation and add an option to the Rotate command so that it can be made to add those lines automatically if desired.
PRINT should be able to print strings consisting of just a space. This may be something that was broken during translation from QBASIC to FreeBASIC - I'll look into it in more detail and see what is happening.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I'm trying to do something similar, but I don't get the output I expect
number = 162
'sets number to 10100010
for counter = 1 to 8
IF number.7 ON THEN print("1")
IF number.7 OFF then print("0")
SET STATUS.C OFF
IF number.7 ON THEN SET STATUS.C ON
rotate number left
NEXT
when I compile and run, my LCD displays 11111111
shouldn't it display 10100010 ?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I'm pretty sure that problem is due to a bug in the string handling code of the 24/12 update. Try http://gcbasic.sourceforge.net/newfiles/update.zip - this is the latest version (17/1), and the bug is fixed in it.
The newest version has a modified rotate command, so GCBASIC will add the code to set/clear STATUS.C if you add "simple" to the end of the rotate command. The modified code would look like this:
number = 162
'sets number to 10100010
for counter = 1 to 8
IF number.7 ON THEN print("1")
IF number.7 OFF then print("0")
rotate number left simple
NEXT
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi
I'm having a problem with Rotate Right command, it doesn't do a proper bit shift operation but it copies msb to the right; for instance:
'Chip model
#chip 16F690,4
#config _INTRC_OSC_NOCLKOUT, _WDT_OFF,_PWRTE_OFF,_MCLRE_OFF,_CP_OFF, _BOR_OFF, _IESO_OFF,_FCMEN_OFF
#define LCD_IO 2
#Define LCD_DB Porta.0 'Required: pin where Data Bit is wired
#Define LCD_CB Porta.1 'Required: pin where Clock Bit is wired
#Define Dallas PORTC.0 'Dallas/Maxim DS18b20 wiring
do
Rotation = b'10000000'
for loopprg=1 to 8
LOCATE 1,1
PRINT "___"
LOCATE 1,1
LCDINT Rotation
Rotate Rotation Right
wait 1 s
next loopprg
loop
Instead of 128 (bin 10000000), 64 (bin 01000000) and so on, the program print on LCD 128 (starting value for variable) , the second value becames 192 (bin 11000000), the third 224 (bin 11100000).
It really seems that Rotate command copy msb instead of shifting it.
Greetings & Thanks for your answer
P.S. Another question: why Print (LCD command) don't print space made strings? (" "). It would be a big help to clean LCD positions.
Stefano B.
It would seem that I have neglected to document the way that the ROTATE command works properly!
This is a result of the way that the rlf and rrf assembly mnemonics work - STATUS.C acts as a ninth bit of the variable that is being rotated. When a variable is rotated right, STATUS.C is placed into the MSB of the variable Rotation, and the LSB of Rotation is placed into STATUS.C.
For now, the way to work around this is to add some code to set STATUS.C to the least significant bit of the variable, like this:
SET STATUS.C OFF
IF Rotation.0 ON THEN SET STATUS.C ON
Rotate Rotation right
This will make your program work as expected. In the next version of GCBASIC, I'll fix the documentation and add an option to the Rotate command so that it can be made to add those lines automatically if desired.
PRINT should be able to print strings consisting of just a space. This may be something that was broken during translation from QBASIC to FreeBASIC - I'll look into it in more detail and see what is happening.
Thanks a lot for your answer!
Stefano B.
I'm trying to do something similar, but I don't get the output I expect
number = 162
'sets number to 10100010
for counter = 1 to 8
IF number.7 ON THEN print("1")
IF number.7 OFF then print("0")
SET STATUS.C OFF
IF number.7 ON THEN SET STATUS.C ON
rotate number left
NEXT
when I compile and run, my LCD displays 11111111
shouldn't it display 10100010 ?
I'm pretty sure that problem is due to a bug in the string handling code of the 24/12 update. Try http://gcbasic.sourceforge.net/newfiles/update.zip - this is the latest version (17/1), and the bug is fixed in it.
The newest version has a modified rotate command, so GCBASIC will add the code to set/clear STATUS.C if you add "simple" to the end of the rotate command. The modified code would look like this:
number = 162
'sets number to 10100010
for counter = 1 to 8
IF number.7 ON THEN print("1")
IF number.7 OFF then print("0")
rotate number left simple
NEXT