sorry was so busy trying to do my program this few days. I have done the look up table for my buggy. Both the top and the bottom of the sensor.
; 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'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'
NUMBER
d1 ;use for Delay subroutine
d2
d3
d4
SENSOR
TOP
BOTTOM
TOP_motion
BTM_motion
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
; 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
Enable_BS170 movlw b'00110000'
movwf PORTA
call SENSE
call TOPP
call BTM
goto Start
;&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
SENSE 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
swapf BOTTOM,w
call BTM_Table
movwf PORTA
return
; *************** 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
Top_Table
addwf PCL
retlw b'00110000' ;stop (Stop,stop)(0000)
retlw b'00110001' ;Left Turn (stop,forward)(0001)
retlw b'00110010' ;right turn (move,stop)(0010)
retlw b'00110011' ;reverse (reverse, reverse)(0011)
retlw b'00110100' ;turn left (stop,move)(0100)
retlw b'00110101' ;forward (move,move)(0101)
retlw b'00110110' ;turn right(move,stop)(0110)
retlw b'00110111' ;turn left(stop,move)(0111)
retlw b'00111000' ;turn right(move stop)(1000)
retlw b'00111001' ;turn right(move stop)!1001)
retlw b'00111010' ;turn right(move stop)(1010)
retlw b'00111011' ;turn right(move stop)(1011)
retlw b'00111100' ;forward (move move)(1100)
retlw b'00111101' ;turn left (stop move)(1101)
retlw b'00111110' ;turn right (move stop)(1110)
retlw b'00111111' ;stop (stop stop)(1111)
BTM_Table
retlw b'00110000' ;stop (Stop,stop)(0000)
retlw b'00110001' ;Left Turn (stop,forward)(0001)
retlw b'00110010' ;right turn (move,stop)(0010)
retlw b'00110011' ;forward (move, move)(0011)
retlw b'00110100' ;forward (move,move)(0100)
retlw b'00110101' ;turn left (stop,move)(0101)
retlw b'00110110' ;turn right(move,stop)(0110)
retlw b'00110111' ;forward(move,move)(0111)
retlw b'00111000' ;forward(move move)(1000)
retlw b'00111001' ;turn left(stop move)!1001)
retlw b'00111010' ;turn right(move stop)(1010)
retlw b'00111011' ;forward(move move)(1011)
retlw b'00111100' ;forward (move move)(1100)
retlw b'00111101' ;turn left (stop move)(1101)
retlw b'00111110' ;turn right (move stop)(1110)
retlw b'00111111' ;move (move move)(1111)
; ************* End of the program ************************************************
END ;End of the program
This is what i have come up with so far. But i am having trouble connecting the look up table to the motor. My buggy has 2 motors as well. The problem i have is the sub routine for the motor. i know i need to declare a new sub routine which is motor. but how do i continue up from there