Menu

Rotate

2006-11-16
2013-05-30
  • Stefano Bonomi

    Stefano Bonomi - 2006-11-16

    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.

     
    • Hugh Considine

      Hugh Considine - 2006-11-19

      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.

       
    • Stefano Bonomi

      Stefano Bonomi - 2006-11-19

      Thanks a lot for your answer!

      Stefano B.

       
    • Nobody/Anonymous

      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 ?

       
    • Hugh Considine

      Hugh Considine - 2007-01-11

      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

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.