Hi societyofrobots,
-16f876, L293D, 4infrared sensors and 2 dc motor.
i am rather new to what i am doing and would need some help.
i am trying to program my buggy to detect and avoid obstacle with 2 sensors infront and 1 at each sides.
Currently it is able to detect and avoid obstacle but i would like it stop moving after meeting the third obstacle. How can i do it?
Its is a school project and i am in charge of the electronics while my partner was with the software just the two of us. The project is due on the 1st of march and he dropped out of school just 1month before. Its affecting me right now, and currently im having my end semster exams and i cant find much time to commit to the assembly language from scratch. People out here please help me out, i would like to have 30mins or an hour of your time to check our the code and the schematics.
yours reponses will be much appreciated.
I have attached the relavant files(schematics) here please kindly take a look. Thank you.
Sincerely,
Peter.
; ************* HEADER **************************************************************
LIST p=16F876 ;PIC16F876 is the target processor
#include "P16F876.INC" ;Include header file
__config H'3F39' ;Osc=XT; WDT=Off;
;Power Up Timer=Off; Brown Out Detect=Off
;LVP=Disabled, Flash Program Write=Enabled,
;Data EE Read Protect=Off; Code Protect=Off
;
;************** File Register Variable use ******************************************
cblock H'20'; directive to assign address offset to many variables
NUMBER
d1 ;use for Delay subroutine
d2
d3
d4
Bottom
Top
SENSOR
SENSOR_M
endc ;
;
; ************* Reset Vector ********************************************************
org H'00'
clrf STATUS
movlw 0x00
movwf PCLATH
goto Initial
;
; ************* Port B and C I/O Initialisation *************************************
Initial bsf STATUS,RP0 ; Select BANK 1 R/w-0 another file adress
; banksel TRISB
movlw B'00000000' ; Set PortB to Output pins
movwf TRISB ;
movlw B'11111111' ; Set PortC to Input pins
movwf TRISC ;
movlw B'00000000' ; Set PortA to Output pins
movwf TRISA ;
movlw B'00000110' ;making all pins digital
movwf ADCON1 ;set to digital output
;PORTA MOTOR, PORTB LED, PORTC SENSOR
;
; ************* Main Program *******************************************************
banksel PORTA ;
Enable_BS170 movlw b'00110000' ;
movwf PORTA
RUN call SENSING
call SENSOR_MANIPULATE_TOP
call MOTOR
goto RUN
SENSING
movfw PORTC ;
movwf SENSOR ;
movwf PORTB ;
return
SENSOR_MANIPULATE_TOP ;
clrf SENSOR_M
chk_s4 btfss SENSOR,4
goto chk_s5
bsf SENSOR_M,0
chk_s5 btfss SENSOR,5
goto chk_s6
bsf SENSOR_M,1
chk_s6 btfss SENSOR,6
goto chk_s7
bsf SENSOR_M,2
chk_s7 btfss SENSOR,7
goto chk_sX
bsf SENSOR_M,3
chk_sX return
MOTOR
movfw SENSOR_M ;
andlw b'00001111';set upper 4bit to 0
call Get_Code_TOP
movwf PORTA
call Delay_100us
call Delay_100us
call Delay_100us
call Delay_100us
movlw b'00110000'
movwf PORTA
call Delay_100us
call Delay_100us
return
Get_Code_TOP
addwf PCL
retlw b'00110000' ;stop (0000)
retlw b'00111100' ;right (0001)
retlw b'00110001' ;left (0010)
retlw b'00111101' ;forward (0011)
retlw b'00111100' ;right(0100)
retlw b'00111100' ;right (0101)
retlw b'00110001' ;left (0110)
retlw b'00111100' ;right(0111)
retlw b'00110001' ;left(1000)
retlw b'00111100' ;right(1001)
retlw b'00110001' ;left (1010)
retlw b'00110001' ;left (1011)
retlw b'00110000' ;stop(1100)
retlw b'00111100' ;right (1101)
retlw b'00110001' ;left (1110)
retlw b'00111101' ;forward(1111)
; *************** Delays ***********************************************************
Delay_100us movlw 0x1F
movwf d1
again2 decfsz d1,f
goto again2
goto $+1
return
Delay_50us movlw 0x0F
movwf d1
again3 decfsz d1,f
goto again3
return
;
; ************* End of the program ************************************************
END ;End of the program
Please help me out.
Thanks.
Sincerely,
Peter.