Editing of ASM file

Discussion in 'Programmer's Corner' started by rn.ksheer, Jan 4, 2013.

  1. rn.ksheer

    Thread Starter New Member

    May 16, 2012
    8
    0
    Hi. I have successfully completed constructing CERBERES robot given in http://webspace.webring.com/people/bt/tjaco/cerberes/cerberes.html. The robot works well but when it comes to a corner where both the sensors sense the object , The robot seems to get confused and gets stuck in the same place. The given code doesn't have any instruction for the motors, when both sensors are active. Will it be possible to add a instruction to make the robot turn 180 degrees, then start moving forward or to come backwards, turn left/right then start moving forward when both the sensors sense the object. I am very new to programming so i would require the help.

    Sorry for my English :)
     
  2. absf

    Senior Member

    Dec 29, 2010
    1,490
    371
    People here dont like zip files as they're sometimes having virus problems and it needs to be unzipped.

    I post your asm code here so others may spot your problems easily....

    Code ( (Unknown Language)):
    1. ;TJACO'S DESIGN GRAVEYARD: WWW.GEOCITIES.COM/TJACODESIGN        ;
    2. ;22 JULY 2002                               ;
    3. ;CERBERES : MINI ROBOT WITH IR EYES                     ;
    4. ;USES PIC16F84 µCONTROLLER                     ;
    5. ;WRITTEN IN MICROCHIP ASSEMBLY USE MPASM ASSEMBLER FROM MPLAB       ;
    6. ;MPLAB CAN BE DOWNLOADED FROM WWW.MICROCHIP.COM             ;
    7.  
    8. ;***SET UP THE CONTANTS & VARIABLES****
    9.  
    10.        LIST            P=16F84A
    11.        ERRORLEVEL      -302    ;SUPPRESS BANK SELECTION MESSAGES
    12.         __config        0x3FFB
    13.  
    14. STATUS  EQU H'03'       ;STATUS REGISTER
    15. TRISB   EQU H'86'       ;TRISB REGISTER FOR SETUP OF PORTB
    16. PORTB   EQU H'06'       ;PORTB REGISTER TO DRIVE PORT B
    17. COUNT1  EQU H'0C'       ;COUNT VARIABLE 1 IS IN GENERAL PURPOSE REG 08H
    18. COUNT2  EQU H'0D'       ;COUNT VARIABLE 2 IS IN GENERAL PURPOSE REG 09H
    19.  
    20. ;***SET UP PORT B IN & OUTPUT****
    21.     BSF     STATUS,5    ;SWITCH TO BANK0 TO SET UP PORT B
    22.     MOVLW   B'11110000' ;RB7,6,5,4 IS INPUT
    23.     MOVWF   TRISB       ;RB3,2,1,0 IS OUTPUT
    24.     BCF     STATUS,5    ;SWITCH BACK TO BANK0 TO USE PORT B
    25.  
    26. ;***MAIN PROGRAM****
    27. START   MOVLW   B'00000101' ;MAKE RB0&2 HIGH: MOVE FORWARD
    28.     MOVWF   PORTB       ;
    29.     MOVLW   H'FE'       ;RESET COUNT1 TO 254
    30.     MOVWF   COUNT1      ;  
    31.     MOVLW   H'FE'       ;RESET COUNT2 TO 254
    32.     MOVWF   COUNT2      ;
    33.     BTFSS   PORTB,5     ;CHECK RB5 (INPUT); IF IT IS LOW
    34.     CALL    BACKL       ;THEN EXECUTE BACKLEFT ROUTINE
    35.     BTFSS   PORTB,6     ;CHECK RB6 (INPUT); IF IT IS LOW
    36.     CALL    BACKR       ;EXECUTE BACKRIGHT ROUTINE
    37.     GOTO    START       ;RETURN TO LABEL START
    38.  
    39. ;***BACKLEFT ROUTINE****
    40. BACKL   MOVLW   B'00001010' ;MAKE RB1&3 HIGH: MOVE BACKWARD
    41.     MOVWF   PORTB       ;
    42.     CALL    DELAY       ;
    43.     MOVLW   B'00001001' ;MAKE RB2&3 HIGH: ROTATE LEFT
    44.     MOVWF   PORTB       ;
    45.     CALL    DELAY       ;
    46.     RETURN
    47. ;***BACKRIGHT ROUTINE****
    48. BACKR   MOVLW   B'00001010' ;MAKE RB1&3 HIGH: MOVE BACKWARD
    49.     MOVWF   PORTB       ;
    50.     CALL    DELAY       ;
    51.     MOVLW   B'00000110' ;MAKE RB2&3 HIGH: ROTATE RIGHT
    52.     MOVWF   PORTB       ;
    53.     CALL    DELAY       ;
    54.     RETURN
    55.  
    56. DELAY   MOVLW   H'EE'       ;RESET ALL COUNTER VARIABLES
    57.     MOVWF   COUNT1     
    58.     MOVLW   H'99'  
    59.     MOVWF   COUNT2
    60.  
    61. LOOP1   CLRWDT          ;RESET THE WATCHDOG TIMER
    62.     DECFSZ  COUNT1,1    ;this is a delay loop    
    63.     GOTO    LOOP1       ;tuned to make Cerberes
    64.     DECFSZ  COUNT2,1    ;turn about 90 degrees
    65.     GOTO    LOOP1  
    66.     RETURN
    67.  
    68.     END;
    69.  
    I have looked through the codes but I dont have time to add in the needed codes for you. May be others can help you faster than me.

    Allen
     
    Last edited: Jan 5, 2013
  3. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    Your link went bad. Could you post the schematic so I know where these two sensor are going?

    (Why do I feel like I'm talking to a pair of spambots?)
     
  4. rn.ksheer

    Thread Starter New Member

    May 16, 2012
    8
    0
  5. rn.ksheer

    Thread Starter New Member

    May 16, 2012
    8
    0
    After looking into the instructions set for 16f84a, i found ANDWF or ANDLW operand can be used where we can compare the two inputs. If both the inputs are low (both the sensors sense the object) a sub routine can be called to perform a operation but i am not able to find detailed examples in Google.
     
  6. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    This might do it:

    Code ( (Unknown Language)):
    1. ;TJACO'S DESIGN GRAVEYARD: WWW.GEOCITIES.COM/TJACODESIGN        ;
    2. ;22 JULY 2002                                ;
    3. ;CERBERES : MINI ROBOT WITH IR EYES                      ;
    4. ;USES PIC16F84 µCONTROLLER                        ;
    5. ;WRITTEN IN MICROCHIP ASSEMBLY USE MPASM ASSEMBLER FROM MPLAB        ;
    6. ;MPLAB CAN BE DOWNLOADED FROM WWW.MICROCHIP.COM                ;
    7.  
    8. ;***SET UP THE CONTANTS & VARIABLES****
    9.  
    10.        LIST            P=16F84A
    11.        ERRORLEVEL      -302    ;SUPPRESS BANK SELECTION MESSAGES
    12.         __config        0x3FFB
    13.  
    14. STATUS    EQU H'03'        ;STATUS REGISTER
    15. TRISB     EQU H'86'        ;TRISB REGISTER FOR SETUP OF PORTB
    16. PORTB     EQU H'06'        ;PORTB REGISTER TO DRIVE PORT B
    17. COUNT1     EQU H'0C'        ;COUNT VARIABLE 1 IS IN GENERAL PURPOSE REG 08H
    18. COUNT2     EQU H'0D'        ;COUNT VARIABLE 2 IS IN GENERAL PURPOSE REG 09H
    19.  
    20. ;***SET UP PORT B IN & OUTPUT****
    21.     BSF     STATUS,5    ;SWITCH TO BANK0 TO SET UP PORT B
    22.     MOVLW     B'11110000'    ;RB7,6,5,4 IS INPUT
    23.     MOVWF     TRISB        ;RB3,2,1,0 IS OUTPUT
    24.     BCF     STATUS,5    ;SWITCH BACK TO BANK0 TO USE PORT B
    25.  
    26. ;***MAIN PROGRAM****
    27. START    MOVLW     B'00000101'    ;MAKE RB0&2 HIGH: MOVE FORWARD
    28.     MOVWF     PORTB        ;
    29.     MOVLW     H'FE'        ;RESET COUNT1 TO 254
    30.     MOVWF     COUNT1        ;    
    31.     MOVLW     H'FE'        ;RESET COUNT2 TO 254
    32.     MOVWF     COUNT2        ;
    33. [B]    MOVF PORTB, W           ;put it in W register
    34.     ANDLW b'01100000'       ;ignore bits apart from 5 and 6
    35.     BTFSS STATUS, Z          ;(assuming sensor at low voltage means
    36.  ;active) skip the "GOTO NEXT_TEST" instruction if result is zero.
    37.     GOTO NEXT_TEST
    38. ;put code here for both sensors active
    39.     GOTO START                ;don't do other checks
    40. NEXT_TEST[/B]
    41.     BTFSS     PORTB,5        ;CHECK RB5 (INPUT); IF IT IS LOW
    42.     CALL     BACKL        ;THEN EXECUTE BACKLEFT ROUTINE
    43.     BTFSS     PORTB,6        ;CHECK RB6 (INPUT); IF IT IS LOW
    44.     CALL     BACKR        ;EXECUTE BACKRIGHT ROUTINE
    45.     GOTO     START        ;RETURN TO LABEL START
    46.  
    47. ;***BACKLEFT ROUTINE****
    48. BACKL    MOVLW     B'00001010'    ;MAKE RB1&3 HIGH: MOVE BACKWARD
    49.     MOVWF     PORTB        ;
    50.     CALL     DELAY        ;
    51.     MOVLW     B'00001001'    ;MAKE RB2&3 HIGH: ROTATE LEFT
    52.     MOVWF     PORTB        ;
    53.     CALL     DELAY        ;
    54.     RETURN
    55. ;***BACKRIGHT ROUTINE****
    56. BACKR    MOVLW     B'00001010'    ;MAKE RB1&3 HIGH: MOVE BACKWARD
    57.     MOVWF     PORTB        ;
    58.     CALL     DELAY        ;
    59.     MOVLW     B'00000110'    ;MAKE RB2&3 HIGH: ROTATE RIGHT
    60.     MOVWF     PORTB        ;
    61.     CALL     DELAY        ;
    62.     RETURN
    63.  
    64. DELAY    MOVLW     H'EE'        ;RESET ALL COUNTER VARIABLES
    65.     MOVWF     COUNT1        
    66.     MOVLW     H'99'    
    67.     MOVWF     COUNT2
    68.  
    69. LOOP1    CLRWDT            ;RESET THE WATCHDOG TIMER
    70.     DECFSZ     COUNT1,1    ;this is a delay loop    
    71.     GOTO     LOOP1        ;tuned to make Cerberes
    72.     DECFSZ    COUNT2,1    ;turn about 90 degrees
    73.     GOTO    LOOP1    
    74.     RETURN
    75.  
    76.     END;
     
    rn.ksheer likes this.
  7. rn.ksheer

    Thread Starter New Member

    May 16, 2012
    8
    0
    I have added the sub routine for both sensors active but when compiling in MPlab i am getting this error "Symbol not previously defined (Z)" .

    Code ( (Unknown Language)):
    1. ;***SET UP THE CONTANTS & VARIABLES****
    2.  
    3.        LIST            P=16F84A
    4.        ERRORLEVEL      -302    ;SUPPRESS BANK SELECTION MESSAGES
    5.  
    6. STATUS    EQU H'03'        ;STATUS REGISTER
    7. TRISB     EQU H'86'        ;TRISB REGISTER FOR SETUP OF PORTB
    8. PORTB     EQU H'06'        ;PORTB REGISTER TO DRIVE PORT B
    9. COUNT1     EQU H'0C'        ;COUNT VARIABLE 1 IS IN GENERAL PURPOSE REG 08H
    10. COUNT2     EQU H'0D'        ;COUNT VARIABLE 2 IS IN GENERAL PURPOSE REG 09H
    11.  
    12. ;***SET UP PORT B IN & OUTPUT****
    13.     BSF     STATUS,5    ;SWITCH TO BANK0 TO SET UP PORT B
    14.     MOVLW   B'11110000'    ;RB7,6,5,4 IS INPUT
    15.     MOVWF   TRISB        ;RB3,2,1,0 IS OUTPUT
    16.     BCF     STATUS,5    ;SWITCH BACK TO BANK0 TO USE PORT B
    17.  
    18. ;***MAIN PROGRAM****
    19. START    MOVLW     B'00000101'    ;MAKE RB0&2 HIGH: MOVE FORWARD
    20.     MOVWF     PORTB        ;
    21.     MOVLW     H'FE'        ;RESET COUNT1 TO 254
    22.     MOVWF     COUNT1        ;    
    23.     MOVLW     H'FE'        ;RESET COUNT2 TO 254
    24.     MOVWF     COUNT2        ;
    25.     MOVF PORTB, W           ;put it in W register
    26.     ANDLW b'01100000'       ;ignore bits apart from 5 and 6
    27.     BTFSS STATUS, Z          ;(assuming sensor at low voltage means
    28.                              ;active) skip the "GOTO NEXT_TEST" instruction if result is zero.
    29.     GOTO NEXT_TEST
    30.     CALL     BTHACT          ;put code here for both sensors active
    31.     GOTO START               ;don't do other checks
    32.    
    33. NEXT_TEST
    34.     BTFSS    PORTB,5      ;CHECK RB5 (INPUT); IF IT IS LOW
    35.     CALL     BACKL        ;THEN EXECUTE BACKLEFT ROUTINE
    36.     BTFSS    PORTB,6     ;CHECK RB6 (INPUT); IF IT IS LOW
    37.     CALL     BACKR        ;EXECUTE BACKRIGHT ROUTINE
    38.     GOTO     START        ;RETURN TO LABEL START
    39.  
    40. ;***BACKLEFT ROUTINE****
    41. BACKL    MOVLW     B'00001010'    ;MAKE RB1&3 HIGH: MOVE BACKWARD
    42.     MOVWF    PORTB        ;
    43.     CALL     DELAY        ;
    44.     MOVLW    B'00001001'    ;MAKE RB2&3 HIGH: ROTATE LEFT
    45.     MOVWF    PORTB        ;
    46.     CALL     DELAY        ;
    47.     RETURN
    48.    
    49. ;***BACKRIGHT ROUTINE****
    50. BACKR    MOVLW     B'00001010'    ;MAKE RB1&3 HIGH: MOVE BACKWARD
    51.     MOVWF    PORTB        ;
    52.     CALL     DELAY        ;
    53.     MOVLW    B'00000110'    ;MAKE RB2&3 HIGH: ROTATE RIGHT
    54.     MOVWF    PORTB        ;
    55.     CALL     DELAY        ;
    56.     RETURN
    57.    
    58. ;***BOTH ACTIVE****
    59. BTHACT   MOVLW     B'00001010'    ;MAKE RB1&3 HIGH: MOVE BACKWARD
    60.     MOVWF    PORTB        ;
    61.     CALL     DELAY
    62.     MOVLW    B'00000110'    ;MAKE RB2&3 HIGH: ROTATE RIGHT
    63.     MOVWF    PORTB        ;
    64.     CALL     DELAY        ;
    65.     RETURN
    66.    
    67. DELAY    MOVLW     H'EE'        ;RESET ALL COUNTER VARIABLES
    68.     MOVWF     COUNT1        
    69.     MOVLW     H'99'    
    70.     MOVWF     COUNT2
    71.  
    72. LOOP1    CLRWDT            ;RESET THE WATCHDOG TIMER
    73.     DECFSZ   COUNT1,1    ;this is a delay loop    
    74.     GOTO     LOOP1        ;tuned to make Cerberes
    75.     DECFSZ   COUNT2,1    ;turn about 90 degrees
    76.     GOTO     LOOP1    
    77.     RETURN
    78.  
    79.     END;
     
    Last edited by a moderator: Jan 20, 2013
  8. takao21203

    Distinguished Member

    Apr 28, 2012
    3,577
    463
    16f84 is antiquated, and in no way appreciate for a robot.

    You should at least use a 18F chip or better a 24F or PIC32.

    If you use these antiquated chips, your thinking and problem solving remains chained to the limits of this chip.
     
  9. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    Add this line:
    #include <p16f84a.inc>
    after the "LIST" line at the start. It includes definitions for things like PORTA, STATUS, and bits like Z, C.
    The programmer hasn't done it, but it's easier to understand the code if you put:

    DECF COUNT1, F
    instead of
    DECF COUNT1, 1

    or
    BTFSS STATUS, Z
    instead of
    BTFSS STATUS, 2

    If you want to make the existing code easier to understand, you can make changes like that.
     
    rn.ksheer likes this.
  10. rn.ksheer

    Thread Starter New Member

    May 16, 2012
    8
    0
  11. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    Good to see it working. I think I see it turn 180 degrees a few times, presumably that is when both sensors detect an object.
     
Loading...