list p=16f628A ; list directive to define processor
#include <p16f628A.inc> ; processor specific variable definitions
errorlevel -302 ;hide banking message
;*****
__CONFIG _CP_OFF & _WDT_OFF & _BODEN_ON & _PWRTE_ON & _INTRC_OSC_NOCLKOUT & _MCLRE_OFF & _LVP_OFF
;*****
;internal osc settings
;*****
; '__CONFIG' directive is used to embed configuration data within .asm file.
; The lables following the directive are located in the respective .inc file.
; See respective data sheet for additional information on configuration word.
;***** VARIABLE DEFINITIONS
w_temp EQU 0x70 ; variable used for context saving
status_temp EQU 0x71 ; variable used for context saving
Count1 EQU 0X20 ; First Counter for Delay
Count1v EQU 0X21 ; Count Storage for Refill Delay
EEPROM_ADDR Equ 0x00 ; Address of EEPROM byte used
;**********************************************************************
ORG 0x000 ; processor reset vector
goto Start ; go to beginning of program
ORG 0x004 ; interrupt vector location
movwf w_temp ; save off current W register contents
movf STATUS,w ; move status register into W register
movwf status_temp ; save off contents of STATUS register
movf status_temp,w ; retrieve copy of STATUS register
movwf STATUS ; restore pre-isr STATUS register contents
swapf w_temp,f
swapf w_temp,w ; restore pre-isr W register contents
retfie ; return from interrupt
Start
clrf PORTA
clrf PORTB
MOVLW 0x07
MOVWF CMCON ; Turn off comparator
bsf STATUS,RP0 ; bank one
movlw 0xFF
movwf TRISA ; porta all Input
movlw 0x00
movwf TRISB ; portb all Output
movlw 0x00 ;See datasheet for prefered
movwf OPTION_REG ;settings of OPTION_REG
bcf STATUS,RP0 ; return to bank 0
call Systest
btfsc PORTA, 2 ; Check if Setup Switch = 1
call Setup ; Go to Setup Subroutine
;movf Count1v,w
;movwf Count1
btfss PORTA,0 ; Check if Upper Sensor = 1
Call Refill ; If not go to Refill Subroutine
Goto Run ; Then go to Operation Mode
Setup
btfss PORTA,2 ; If Setup Switch = 0
call EP_Write ; Write Count1v Data to EEPROM
btfsc PORTA,3 ; If Count Switch = 1
incfsz Count1v,1 ; Increment Count1v by 1
btfsc PORTA,2 ; If Setup Switch = 1
goto Setup ; Return to top of Subroutine
return ; Return to main program
Systest
call Delay ; Call Delay Routine to set Delay time
movlw 0x80 ; Set PortB,7 High the others Low
movwf PORTB
call Delay1 ; Call Delay Subroutine
call Delay ; Call Delay Routine to set Delay time
movlw 0x40 ; Set PortB,6 High the others Low
movwf PORTB
call Delay1 ;Call Delay Subroutine
call Delay ; Call Delay Routine to set Delay time
movlw 0x20 ; Set PortB,5 High the others Low
movwf PORTB
call Delay ; Call Delay Routine to set Delay time
call Delay1 ; Call Delay Subroutine
movlw 0x10 ; Set PortB,4 High the others Low
movwf PORTB
call Delay ; Call Delay Routine to set Delay time
Call Delay1 ; Call Delay Subroutine
movlw 0xF0 ; Set All Indicators High
movwf PORTB
call Delay ; Call Delay Routine to set Delay time
call Delay1 ; Call Delay Subroutine
movlw 0x80 ; Turn on Power LED
movwf PORTB
RETURN ;Return to main program
Run
movlw 0xC0 ; Set Operation Mode
btfss PORTA,0 ; Check if Upper Sensor = 1
movlw 0xE0 ; Set Warning Mode
movwf PORTB ; Move to PortB
btfss PORTA,1 ; Check if Lower Sensor = 1
call Delay ; Then Goto Delay1 Subroutine
btfss PORTA,1 ; Check If Lower Sensor = 1
Call Refill ; Go to Refill Subroutine
Goto Run ; Return to Top
Refill
movlw 0xB8 ; Set Refill Mode
btfsc PORTA,0 ; Check If Upper Sensor = 1
movlw 0xC0 ; Then Set Operation Mode
movwf PORTB ; Move to PORTB
btfsc PORTA,1 ; Check If Lower Sensor = 1
call Delay1 ; Then Go To Delay Subroutine
btfss PORTA,0 ; Check If Upper Sensor = 1
goto Refill ; If Not Return to Top of subroutine
Return ; Return to previous point
Delay:
movlw 0x05 ; Set Counter to 05H
movwf Count1
Return ; Return to previous point
Delay1:
decfsz Count1,1 ;Decrement Count1 1
goto Delay1 ;If Count1 > 0 Return to top
Return ;Return to Previous point
EP_Write
movfw Count1v ; read current value
bsf STATUS,RP0 ; Bank 1
bsf EECON1,WREN ; Enable write
movwf EEDATA ; set EEPROM data
movlw EEPROM_Addr
movwf EEADR ; set EEPROM address
movlw 0x55
movwf EECON2 ; Write 55h
movlw 0xAA
movwf EECON2 ; Write AAh
bsf EECON1,WR ; Set WR bit
; begin write
bcf STATUS,RP0 ; Bank 0
btfss PIR1,EEIF ; wait for write to complete.
goto $-1
bcf PIR1,EEIF ; and clear the 'write complete' flag
bsf STATUS,RP0 ; Bank 1
bcf EECON1,WREN ; Disable write
bcf STATUS,RP0 ; Bank 0
retlw 0x00
Return
EP_READ
BSF STATUS, RP0 ; Bank 1
MOVLW EEPROM_ADDR ;
MOVWF EEADR ; Address to read
BSF EECON1, RD ; EE Read
MOVF EEDATA, W ; W = EEDATA
BCF STATUS, RP0 ; Bank 0
RETURN
END