hi there ,
here's the whole code listing :
#include P16F84A.inc
cpostn equ 10
nsn equ B'00000000' ; no sun shine
pos equ B'00100000' ; facing sun
lft equ B'01000000' ; sun on left
rht equ B'00010000' ; sun on right
pp equ B'00000001'
;Portb equ 06
;Porta equ 05
;trisa equ 05
;trisb equ 06
;status equ 03
delcntr1 equ 11
org 00
;--------initialization process------------------------------
start bsf STATUS, 5 ; select bank 1
movlw B'11110000' ; bits 7,6,5 & 4 as inputs
movwf TRISB
movlw 00
movwf TRISA ; all o/ps
movlw 00
movwf cpostn ; reseting
bcf STATUS, 5 ;select bank0
;----------- Main Routine -----------------------------------
align movlw PORTB
movwf cpostn
btfsc cpostn ,pos
goto stay ; its the right position
btfsc cpostn ,lft ; check the for left turn
goto mvlft ; sub-routine to move left
btfsc cpostn ,rht
goto mvrht
btfsc cpostn ,nsn
goto park
goto align
;------------------------------------------------
;Move left sub-routine
;
mvlft nop
agaan movlw B'10000'; start motor
movwf PORTA
call delay ; time delay subroutine
movlw B'00000'
movwf PORTA ; stop motor
movlw PORTB ; refresh position
movlw cpostn
btfsc cpostn ,lft ; compare current position
goto agaan
return
; -----------End of subroutine-------------------
;
;
;------------------------------------------------
;Move right sub-routine
;
mvrht nop
again movlw B'01000'; start motor
movwf PORTA
call delay ; time delay subroutine
movlw B'00000'
movwf PORTA ; stop motor
movlw PORTB ; refresh position
movlw cpostn
btfsc cpostn ,rht
goto again
return
; -----------End of subroutine-----
;------------------------------------------------
;just stay here
;
stay nop
; Charging and power managment sub-routine will be added in future
; here we sense main grid supply
; if present = continue charging, jump to CHARGING subroutine
; else = check charge level of batteries
; if charge level = ok
; switch over ( DC-to-AC converstion )
; else = indicate charge level down
; return from sr
nop
goto align
; -----------End of subroutine-----
;
;Parking towards Next morning sun , facing towards left
;
park nop
adjt movlw B'10000' ; start motor
movwf PORTA
call delay ; time delay subroutine
movlw B'00000'
movwf PORTA ; stop motor
movlw PORTB ; refresh position
btfsc cpostn ,nsn
goto adjt
return
; -----------End of subroutine-----
;
;---------Delay subroutine----------
;
;
;Introduces delay of 1ms approx, for 1 MHz clock
delay movlw D'200' ;200 cycles called,
movwf delcntr1
del1 nop ;5 inst cycles in this loop
nop
decfsz delcntr1,1
goto del1
return
;-----------------------------------
end