Hi
Ive designed a line following robot using 2 Microcontrollers (PIC16F84 ... one for each motor).. i have 4 Reflective object sensors connected at portA 0 to 3 and outputs for each motors are on PORTB 1 to 4. ( They send signals to the L298 driver which drives the stepper motor).... I ran into some problem with the code for the stepper motors. It compiles and i can flash it onto the microcontroller but then i do not get any outputs from PORTB. Any help with this code will be greatly appreciated.
The code for the robot is as follows
'For the Left motor 16f84
'Code for 16f84
' Code for moving the motor
DEFINE OSC 4
sensorL var PORTA.0
sensorML var PORTA.1
sensorMR var PORTA.2
sensorR var PORTA.3
delayval var byte
sensorflag var byte
x var byte
y var byte
'ADCON1 = 7 'only for the 18F452
TRISA = %11111111
TRISB = %00000000
'start of main code
sensorflag = 0
start:
delayval = 6
gosub checksensors
goto start
checksensors:
If ((sensorL = 0) AND (sensorML = 0) AND (sensorMR = 0) AND (sensorR = 0)) then
gosub motor_idle
sensorflag = 1
endif
If ((sensorL = 0) AND (sensorML = 0) AND (sensorMR = 0) AND (sensorR = 1)) then
gosub turnright_hard
sensorflag = 1
endif
If ((sensorL = 0) AND (sensorML = 0) AND (sensorMR = 1) AND (sensorR = 0)) then
gosub turnright
sensorflag = 1
endif
if ((sensorL = 0) AND (sensorML = 0) AND (sensorMR = 1) AND (sensorR = 1)) then
gosub turnright
sensorflag =1
endif
if ((sensorL = 0) AND (sensorML = 1) AND (sensorMR = 0) AND (sensorR = 0)) then
gosub turnleft
sensorflag =1
endif
'if sensorL = 0 AND sensorML = 1 AND sensorMR = 0 AND sensorR = 1 then
'gosub moveforward
'endif
'if sensorL = 0 AND sensorML = 1 AND sensorMR = 1 AND sensorR = 0 then
'gosub moveforward
'endif
if ((sensorL = 0) AND (sensorML = 1) AND (sensorMR = 1) AND (sensorR = 1)) then
gosub turnright
sensorflag = 1
endif
if ((sensorL = 1) AND (sensorML = 0) AND (sensorMR = 0) AND (sensorR = 0)) then
gosub turnleft_hard
sensorflag = 1
endif
'if sensorL = 1 AND sensorML = 0 AND sensorMR = 0 AND sensorR = 1 then
'gosub moveforward
'endif
'if sensorL = 1 AND sensorML = 0 AND sensorMR = 1 AND sensorR = 0 then
'gosub moveforward
'endif
'if sensorL = 1 AND sensorML = 0 AND sensorMR = 1 AND sensorR = 1 then
'gosub moveforward
'endif
'if sensorL = 1 AND sensorML = 1 AND sensorMR = 0 AND sensorR = 0 then
'gosub moveforward
'endif
'if sensorL = 1 AND sensorML = 1 AND sensorMR = 0 AND sensorR = 1 then
'gosub moveforward
'endif
'if sensorL = 1 AND sensorML = 1 AND sensorMR = 1 AND sensorR = 0 then
'gosub moveforward
'endif
'if sensorL = 1 AND sensorML = 1 AND sensorMR = 1 AND sensorR = 1 then
'gosub moveforward
'endif
if sensorflag = 0 then gosub moveforward
return
motor_idle
LOW PORTB.0 : LOW PORTB.1 : LOW PORTB.2 : low PORTB.3
return
drive_motor:
HIGH PORTB.1 : LOW PORTB.2 : LOW PORTB.3 : LOW PORTB.4
gosub Delay_routine
HIGH PORTB.1 : HIGH PORTB.2 : LOW PORTB.3 : LOW PORTB.4
gosub Delay_routine
LOW PORTB.1 : HIGH PORTB.2 : LOW PORTB.3 : LOW PORTB.4
gosub Delay_routine
LOW PORTB.1 : HIGH PORTB.2 : HIGH PORTB.3 : LOW PORTB.4
gosub Delay_routine
LOW PORTB.1 : LOW PORTB.2 : HIGH PORTB.3 : LOW PORTB.4
gosub Delay_routine
LOW PORTB.1 : LOW PORTB.2 : HIGH PORTB.3 : High PORTB.4
gosub Delay_routine
LOW PORTB.1 : LOW PORTB.2 : LOW PORTB.3 : HIGH PORTB.4
gosub Delay_routine
HIGH PORTB.1 : LOW PORTB.2 : LOW PORTB.3 : HIGH PORTB.4
gosub Delay_routine
return
Delay_routine:
pause delayval
return
moveforward:
for x = 1 to 1000
gosub drive_motor
next
sensorflag = 0
return
turnleft: 'This PIC controls the Left wheel only
for x = 1 to 100
delayval = 6
gosub drive_motor
next
return
turnleft_hard: 'This PIC controls the Left wheel only
for x = 1 to 100
delayval = 7
gosub drive_motor
next
return
turnright: 'This PIC controls the Left wheel only
for x = 1 to 100
delayval = 12
gosub drive_motor
next
return
turnright_hard: 'This PIC controls the Left wheel only
for x = 1 to 100
gosub motor_idle
next
return
Bookmarks