hello to all in the forum!
I'm new here in the forum and starter in this picbasic programming. please anyone could help me to rewrite this code.
I just added this two lines to the original code and it won't work.
the portb.0 and portb.1 connected to the H bridge.
Code:
if PORTA.1 = 0 then face_east 'limit switch1
if PORTA.2 = 0 then hold 'limit switch2
****************************************************
@ DEVICE PIC16F84,WDT_ON,PWRT_ON,PROTECT_OFF
INCLUDE "bs1defs.bas"
start:
low PORTB.0 'pin portb.0 low
low PORTB.1 'pin portb.1 low
Pot PORTB.2,255,b0 'read first cds sensor
pot PORTB.3,255,b1 'read second cds sensor
if b0 = b1 then start 'if equal do nothing
if b0 > b1 then greater 'if greater, check how much greater
if b0 < b1 then lesser 'if lesser, check how much lesser
if PORTA.1 = 0 then face_east 'limit switch1
if PORTA.2 = 0 then hold 'limit switch2
greater: 'greater routine
b2 = b0 - b1 'find the difference
if b2 > 10 then cw 'is it within the range? if not go to clockwise/ solar panel facing west
goto start 'if it is in the range,do it again
lesser: 'lesser routine
b2 = b1 - b0 'find the difference
if b2 > 10 then ccw 'is it within the range? if not got counter clockwise/solar panel facing east
goto start 'if it is in the range, do it again
cw: 'turn the motor shaft clockwise / solar panel facing west
high PORTB.0 'pin portb.0 high / facing west
pause 100 'let it turn for the moment
goto start 'check again
ccw: 'turn the motor shaft counter clockwise/ solar panel facing east
high PORTB.1 'pin portb.1 high/ solar panel facing east
pause 100 'let it turn for the moment
goto start 'check again
face_east: 'facing east
low PORTB.0 'pin portb.0 low /stopping the solar panel for moving
low PORTB.1 'pin portb.1 low / stopping the solar panel for moving
sleep 14400 'wait for 4 hours
high PORTB.1 'pin portb.1 high /solar panel back facing east ready for next day sun shine
sound PORTB.4,[124,12000] 'tone
pause 1000 'wait for 1 sec
goto start 'check again
hold: '
low PORTB.0 'pin portb,0 low / stopping the solar panel for moving
low PORTB.1 'pin portb.1 low / ----- do ----
sleep 3600 'wait for 1 hour
goto start 'check again
end
'Copied from pic microcontroller project book by John Iovine
Bookmarks