rb13
Newbie level 3
- Joined
- Jan 1, 2015
- Messages
- 3
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1
- Activity points
- 20
I designed a light follower robot using pic16f877a using assembly language.
However, when the switch is on the robot goes forward immediately also when I am not moving the robot it keeps going forward. I need it to stay in place.
The code is:
However, when the switch is on the robot goes forward immediately also when I am not moving the robot it keeps going forward. I need it to stay in place.
The code is:
Code:
#INCLUDE <P16F877A.INC>
__CONFIG _XT_OSC & _WDT_OFF & _PWRTE_OFF & _BODEN_OFF & _LVP_OFF & _CPD_OFF & _WRT_OFF & _CP_OFF
#DEFINE IN1_L PORTB, 0
#DEFINE IN2_L PORTB, 1
#DEFINE IN3_R PORTB, 2
#DEFINE IN4_R PORTB, 3
#DEFINE MID 0X021
#DEFINE RIGHT 0X022
#DEFINE LEFT 0X023
CBLOCK 0x20
A1,COUNTER
ENDC
ORG 0X000
GOTO MAIN
ORG 0X004
BCF INTCON,T0IF
MOVLW -D'125'
MOVWF TMR0
DECFSZ COUNTER,F
RETFIE
MOVLW D'125'
MOVWF COUNTER
CALL TEST
RETFIE
MAIN
CALL SETUP
MOVLW D'125'
MOVWF COUNTER
MOVLW -D'125'
MOVWF TMR0
BSF INTCON, T0IE
BSF INTCON, GIE
GOTO $
A2D_CHANEL_0
MOVLW B'01000001'
MOVWF ADCON0
CALL A2D_DELAY
BSF ADCON0,GO
BTFSC ADCON0,GO
GOTO $-1
MOVF ADRESH,W
MOVWF MID
RETURN
A2D_CHANEL_1
MOVLW B'01001001'
MOVWF ADCON0
CALL A2D_DELAY
BSF ADCON0,GO
BTFSC ADCON0,GO
GOTO $-1
MOVF ADRESH,W
MOVWF LEFT
RETURN
A2D_CHANEL_3
MOVLW B'01011001'
MOVWF ADCON0
CALL A2D_DELAY
BSF ADCON0,GO
BTFSC ADCON0,GO
GOTO $-1
MOVF ADRESH,W
MOVWF RIGHT
RETURN
TEST
CALL A2D_CHANEL_0
CALL A2D_CHANEL_1
CALL A2D_CHANEL_3
MOVF MID,W
SUBWF RIGHT,1
BTFSS STATUS,C
GOTO MOTOR_RIGHT
SUBWF LEFT,1
BTFSS STATUS,C
GOTO MOTOR_LEFT
GOTO MOTOR_FORWARD
RETURN
A2D_DELAY
MOVLW D'5'
MOVWF A1
DECFSZ A1, F
GOTO $-1
RETURN
MOTOR_L_CCW
BSF IN1_L
BCF IN2_L
RETURN
MOTOR_L_CW
BCF IN1_L
BSF IN2_L
RETURN
MOTOR_L_STOP
BCF IN1_L
BCF IN2_L
RETURN
MOTOR_R_CCW
BSF IN3_R
BCF IN4_R
RETURN
MOTOR_R_CW
BCF IN3_R
BSF IN4_R
RETURN
MOTOR_R_STOP
BCF IN3_R
BCF IN4_R
RETURN
MOTOR_FORWARD
CALL MOTOR_L_CW
CALL MOTOR_R_CW
RETURN
MOTOR_RIGHT
CALL MOTOR_R_STOP
CALL MOTOR_L_CCW
RETURN
MOTOR_LEFT
CALL MOTOR_L_STOP
CALL MOTOR_R_CCW
RETURN
MOTOR_STOP
CALL MOTOR_L_STOP
CALL MOTOR_R_STOP
RETURN
SETUP
CLRF PORTA
CLRF PORTB
CLRF PORTC
CLRF PORTD
CLRF PORTE
BSF STATUS, RP0
MOVLW B'00000100'
MOVWF ADCON1
MOVLW B'00000111'
MOVWF CMCON
MOVLW B'00001011'
MOVWF TRISA
MOVLW B'00000000'
MOVWF TRISB
MOVLW B'00000000'
MOVWF TRISC
MOVLW B'00000000'
MOVWF TRISD
MOVLW B'00000000'
MOVWF TRISE
MOVLW B'11000011'
MOVWF OPTION_REG
BCF STATUS, RP0
RETURN
END
Last edited by a moderator: