Menu

Rotate PORTA Right - query

Help
Vladimir
2019-03-16
2019-03-17
  • Vladimir

    Vladimir - 2019-03-16

    Hello! I can not understand in what business, not working a shift right on PORTA PIC16F716. This is because he is a 5-bit?

    #chip 16f716, 20
    
      dir PORTA out
    
      PORTA = b'10000'
    
      repeat 4
        Rotate PORTA Right Simple
        wait 500 ms
      end repeat
    
     

    Last edit: Anobium 2019-03-16
  • Anobium

    Anobium - 2019-03-16

    Hello and Welcome.

    This is working. The code set the port high in turn as follows: porta.3.. 2. 1...0 leaving Porta.0 high.

    I have used a simulator - but, this code is good code.

    What is happening ?

     

    Last edit: Anobium 2019-03-16
  • Vladimir

    Vladimir - 2019-03-16

    Thank you!
    This code work -

    PORTA = b'00001'
    repeat 4
    Rotate PORTA Left Simple
    wait 500 ms
    end repeat

    but shift to the Right not. Value on PortA not change, PortA.4 only set to 0.

    Temporarily I made so

          Rotate Bug Right Simple
          PORTA = Bug
    

    But I would like to know what is wrong.

     
  • Anobium

    Anobium - 2019-03-16

    I do not understand. What is actually happening?

    There is no bug. Please post the actual code and describe what is, and what is not happening.

     
  • Vladimir

    Vladimir - 2019-03-16

    Tried in hardware, everything works. Probably a mistake in my simulator. In vain raised panic :)
    Thank you very much for your response!

     
  • Vladimir

    Vladimir - 2019-03-16

    This code does not work in the simulator

      #chip 16f716, 20
    
      dir PORTA out
      dir PORTB out
      dim Bug as Byte
    
    'Step 1 Work
       Set PortB.0 on
        PORTA = b'00000001'
       repeat 4
        Rotate PORTA Left Simple
           wait 500 ms
      end repeat
    
    '  Step 2 Not Work
       Set PortB.1 on
       PORTA = b'00010000'
      repeat 4
           Rotate PORTA Right Simple
           wait 500 ms
       end repeat
    
    '  Step 3 Work
       Set PortB.2 on
       PORTA = b'00010000'
       Bug = PORTA
      repeat 4
           Rotate Bug Right Simple
           PORTA = Bug
           wait 500 ms
       end repeat
    

    https://youtu.be/uP5JungwQqU

     
  • Anobium

    Anobium - 2019-03-16

    Try real hardware.

     
  • Anobium

    Anobium - 2019-03-17

    I am sorry, but, the code you posted does what it is intended to do.

    In step 2 you set the port to b'00010000' then you rotate. If the sim does not work... then, real hardware will.

    Let me show.... I have adapted your code adding some serial debug (which you can remove or use) and then I set portb to the value of porta when you initialise it....

    Seems to work as expected. Something Bill Roth (a seasoned PIC developer) taught me... do not trust a simulator the real test is the real hardware.

    But, I may be wrong but I think not.

    #chip 16f716, 20
    
      dir PORTA out
      dir PORTB out
      dim Bug as Byte
    
      #include <softserial.h>
    
      ; ----- Config Serial UART :
      #define SER1_BAUD 9600     ; baudrate must be defined
      #define SER1_DATABITS 8    ; databits optional (default = 8)
      #define SER1_STOPBITS 1    ; stopbits optional (default = 1)
      #define SER1_INVERT Off    ; inverted polarity optional (default = Off)
      ; Config I/O ports for transmitting:
      #define SER1_TXPORT PORTB  ; I/O port (without .bit) must be defined
      #define SER1_TXPIN 7       ; portbit  must be defined
      ; Config I/O ports for receiving:
      #define SER1_RXPORT PORTB  ; I/O port (without .bit) must be defined
      #define SER1_RXPIN 6       ; portbit  must be defined
      #define SER1_RXNOWAIT Off  ; don't wait for stopbit optional (default = Off)
    
    'Step 1 Work
    
       Ser1Send 13   'new line in Terminal
       Ser1Send 10   '
       Ser1Print "Step 1 Work"
    
    
        PORTA = b'00000001'
        portb = porta
       repeat 4
        Rotate PORTA Left Simple
           wait 500 ms
      end repeat
    
    '  Step 2 Work
       Ser1Send 13   'new line in Terminal
       Ser1Send 10   '
       Ser1Print "Step 2 Work"
    
    
       PORTA = b'00010000'
       portb = porta
      repeat 4
           Rotate PORTA Right Simple
           wait 500 ms
       end repeat
    
    '  Step 3 Work
       Ser1Send 13   'new line in Terminal
       Ser1Send 10   '
       Ser1Print "Step 3 Work"
    
    
       PORTA = b'00010000'
       portb = porta
       Bug = PORTA
      repeat 4
           Rotate Bug Right Simple
           PORTA = Bug
           wait 500 ms
       end repeat
    
     

    Last edit: Anobium 2019-03-17
  • Vladimir

    Vladimir - 2019-03-17

    Yes, simulators are evil. Provoke stupid posts on the forum :) I Write a program, and the prototype is not ready yet, so I decided to use the simulator. He caused trouble. Once again, thank you very much for your response.

     
  • Anobium

    Anobium - 2019-03-17

    :-)

    Advice. Do not use that old microcontroller - use a PIC16F18344 or something with more capabilities.

     
  • Vladimir

    Vladimir - 2019-03-17

    I have a lot of them, soldered from old devices. I make them animated snowflakes, so as not to throw. Their capabilities in this task is enough.

     
  • Anobium

    Anobium - 2019-03-17

    Excellent - re-use!

    Do post completed project and a video when all done.

    :-)

     
  • Vladimir

    Vladimir - 2019-03-17

    OK :-)

     

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.