Hey i met up with another problem with my program.
; Program: [Stepper_Motor.asm]; Written by: Foo DF; Date: 29-Aug-2006
; This program configures PortC RC0-7 as OUTPUT to control the L293D Motor Control Board
;
; ************* HEADER **************************************************************
LIST p=16F876 ;PIC16F876 is the target processor
#include "P16F876.INC" ;Include header file
__config H'3F3A' ;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'
NUMBER
d1 ;use for Delay subroutine
d2
d3
d4
SENSOR
BOTTOM
sensor
time_on
endc
;
; ************* Reset Vector ********************************************************
org H'00'
clrf STATUS
movlw 0x00
movwf PCLATH
goto Initial
;
;******************* Port A initialisation*******************************
initial bcf STATUS , RP0
clrf PORTA
banksel ADCON1
movlw B'00000110'
movwf ADCON1
movlw B'00000000'
movwf TRISA
; ************* Port B and C I/O Initialisation *************************************
Initial ;
bsf STATUS,RP0 ; Select BANK 1
; banksel TRISB
movlw B'00000000' ; Set PortB to O/Ps
movwf TRISB ; PortB setting is done!
movlw B'11111111' ; Set PortC to I/Ps
movwf TRISC ; PortC setting is done!
movlw B'00000000' ; Set PortA to O/Ps
movwf TRISA ; PortB setting is done!
movlw B'00000110'
movwf ADCON1
;
; ************* Main Program *******************************************************
banksel PORTA
;&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
Start
clrf PORTA
clrf PORTB
clrf PORTC
call SENSOR_CHK
;movlw b'00110000'
;movwf PORTAw
;call SENSE
; call TOPP
;goto Start
;test
;movfw PORTC
;movwf PORTB
;call SENSOR_CHK
;goto test
SENSOR_CHK
movlw b'00110000'
movwf PORTA
call Delay_50us
movfw PORTC
movwf SENSOR
call SENSE
call BTM
movwf PORTA
return
;Forward movlw b'00111101'
; movwf PORTA
; return
;Reverse movlw b'00110111'
; movwf PORTA
; return
;Right_turn movlw b'00111100'
; movwf PORTA
; return
;Left_turn movlw b'00110001'
; movwf PORTA
; return
;&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
SENSE
; clrf PORTA
clrf PORTB
movfw PORTC
movwf SENSOR
movwf PORTB
return
;TOPP
; movfw SENSOR
; andlw b'11110000'
; movwf TOP
; swapf TOP,w
; call Top_Table
; movwf PORTA
; return
BTM
movfw SENSOR
andlw b'00001111'
movwf BOTTOM
call BTM_Table
return
;&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
Delay_50us movlw 0x0F
movwf d1
again3 decfsz d1,f
goto again3
return
;&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
;Top_Table
; addwf PCL
; retlw b'00110000' ;stop (Stop,stop)(0000)
; retlw b'00111000' ;Left Turn (stop,forward)(0001)
; retlw b'00110010' ;right turn (move,stop)(0010)
; retlw b'00111111' ;reverse (reverse, reverse)(0011)
; retlw b'00111000' ;turn left (stop,move)(0100)
; retlw b'00111010' ;forward (move,move)(0101)
; retlw b'00110010' ;turn right(move,stop)(0110)
; retlw b'00111000' ;turn left(stop,move)(0111)
; retlw b'00110010' ;turn right(move stop)(1000)
; retlw b'00110010' ;turn right(move stop)!1001)
; retlw b'00110010' ;turn right(move stop)(1010)
; retlw b'00110010' ;turn right(move stop)(1011)
; retlw b'00111010' ;forward (move move)(1100)
; retlw b'00111000' ;turn left (stop move)(1101)
; retlw b'00110010' ;turn right (move stop)(1110)
; retlw b'00111010' ;move forward (move move)(1111)
BTM_Table
addwf PCL
retlw b'00111101' ;forward (0000)
retlw b'00111100' ;right (0001)
retlw b'00110001' ;left (0010)
retlw b'00111101' ;forward (0011)
retlw b'00111101' ;forward (0100)
retlw b'00111100' ;right (0101)
retlw b'00110001' ;left (0110)
retlw b'00111101' ;forward (0111)
retlw b'00111101' ;forward (1000)
retlw b'00111100' ;right (1001)
retlw b'00110001' ;left (1010)
retlw b'00111101' ;forward (1011)
retlw b'00111101' ;forward (1100)
retlw b'00111100' ;right (1101)
retlw b'00110001' ;left (1110)
retlw b'00110000' ;stop (1111)
; ************* End of the program ************************************************
END ;End of the program
this is what i have come out with so far. it is able to move forward , reverse, turn left and turn right. The sensors are all connected to the LEDs.
However when i try to piece the bottom sensors to move the motors, nothing happen.
The program should be running like this
Call sensor_check ( this will call the sensor to detect, lighting up the LEDs)-> goto sense( checking if its black or white at the bottom sensors. if all 4 sensors detect black it will stop the buggy-> BTM ( where this will call the btm lookup table)-> Btm lookup table.
This is what i thought should happen but the buggy moves but when all 4 of the bottom sensors detect black it still doesnt stop.
some help please