list n=0, c=150, r=dec
; File: main.asm
; Target: PIC12F675
; Created: 2018-02-23
; Author: Dan1138
;*********************************************************************
; ___ ___
; VDD ->|1 U 8|<- VSS
; LED1 <>|2 7|<> LED3
; LED2 <>|3 6|<> LED4
; SW1n ->|4 5|<> LED5
; ¯¯¯¯¯¯¯
; PIC12F675
;
;*********************************************************************
;
; If the switch is Press and hold (My timer output is enable for 1 Minute minimum) either Press, all LED will be ON.
; After 1 Second, LED 1 Turn Off,
; After 2 Second, LED 2 Turn Off
; After 4 Second, LED 3 Turn Off
; After 6 Second, LED 4 Turn Off
; After 8 Second, LED 5 Turn Off.
;
; (5 LED is used for Manual Timer selection for the Motor will Enable..)
;
;*********************************************************************
; See: https://www.electro-tech-online.com/threads/fish-feeder-idea-help-regards.153045/
;*********************************************************************
#include <p12f675.inc>
ERRORLEVEL -302 ; Suppress warning: Register in operand not in bank 0.
__CONFIG _INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_ON & _MCLRE_OFF & _BODEN_ON & _CP_OFF & _CPD_OFF
#define TIMER0_INTERRUPTS_PER_SECOND D'4000'
;
; BUG 1: LED defines not used should be removed
;
;#define LED1 GPIO,5
;#define LED2 GPIO,4
;#define LED3 GPIO,0
;#define LED4 GPIO,2
;#define LED5 GPIO,1
#define SW1n GPIO,3
ISR_DATA UDATA_SHR H'20' ; 0x20 ; BUG 2: Inconsistent syntax use H'20'
WREG_save res 1
STATUS_save res 1
TIMER_DATA UDATA_SHR
IntsInOneSecond res 2
Seconds res 1
RESET_CODE CODE H'000' ; 0x000 ; BUG 3: Inconsistent syntax use H'000'
goto Start
ISR_CODE CODE H'004' ; 0x004 ; BUG 4: Inconsistent syntax use H'004'
movwf WREG_save
movf STATUS,W
movwf STATUS_save
btfsc INTCON,TMR0IE
btfss INTCON,TMR0IF
goto ISR_Exit
bcf INTCON,TMR0IF
movlw D'256'-D'250'+D'3' ;256-250+3 ; BUG 5: Inconsistent syntax use D'256'-D'250'+D'3'
addwf TMR0,F
movlw -1
addwf IntsInOneSecond,F
skpc
addwf IntsInOneSecond+1,F
skpnc
goto ISR_Exit
movlw HIGH(TIMER0_INTERRUPTS_PER_SECOND-1)
movwf IntsInOneSecond+1
movlw LOW(TIMER0_INTERRUPTS_PER_SECOND-1)
movwf IntsInOneSecond
incf Seconds,F
ISR_Exit:
movf STATUS_save,W
movwf STATUS
swapf WREG_save,F
swapf WREG_save,W
retfie
START_CODE CODE
Start:
btfsc STATUS,RP0
goto OscillatorCalibrationFailed
banksel OSCCAL
call GetOSCCAL
movwf OSCCAL
OscillatorCalibrationFailed:
banksel ANSEL
clrf ANSEL
clrf TRISIO
movlw B'11011111'
movwf OPTION_REG
banksel INTCON
clrf INTCON
clrf GPIO
movlw H'07' ; 0x07 ; BUG 6: Inconsistent syntax use H'07'
movwf CMCON
movlw HIGH(TIMER0_INTERRUPTS_PER_SECOND-1)
movwf IntsInOneSecond+1
movlw LOW(TIMER0_INTERRUPTS_PER_SECOND-1)
movwf IntsInOneSecond
clrf Seconds
clrf TMR0
movlw D'256'-D'250'+D'3' ; 256-250+3 ; BUG 7: Inconsistent syntax use D'256'-D'250'+D'3'
addwf TMR0,F
bsf INTCON,TMR0IE
bsf INTCON,GIE
;
;
;
AppStart:
clrf GPIO
AppLoop:
btfsc SW1n
goto AppLoop
bcf INTCON,TMR0IE
movlw HIGH(TIMER0_INTERRUPTS_PER_SECOND-1)
movwf IntsInOneSecond+1
movlw LOW(TIMER0_INTERRUPTS_PER_SECOND-1)
movwf IntsInOneSecond
clrf Seconds
movlw B'00110111' ; LED1-5 on
movwf GPIO
bsf INTCON,TMR0IE
AppTimeout:
movf Seconds,W
xorlw D'1'
skpnz
goto LED1_off
xorlw D'1'^D'2'
skpnz
goto LED2_off
xorlw D'2'^D'4'
skpnz
goto LED3_off
xorlw D'4'^D'6'
skpnz
goto LED4_off
xorlw D'6'^D'8'
skpnz
goto LED5_off
xorlw D'8'
sublw D'8'
skpc
goto WaitForButtonUp
CheckSwitch:
btfsc SW1n
goto AppStart
goto AppTimeout
;
;
;
WaitForButtonUp:
btfsc SW1n
goto AppStart
goto WaitForButtonUp
;
;
;
LED1_off:
movlw B'00010111' ; LED1 off
movwf GPIO
goto CheckSwitch
LED2_off:
movlw B'00000111' ; LED1-2 off
movwf GPIO
goto CheckSwitch
LED3_off:
movlw B'00000110' ; LED1-3 off
movwf GPIO
goto CheckSwitch
LED4_off:
movlw B'00000010' ; LED1-4 off
movwf GPIO
goto CheckSwitch
LED5_off:
movlw B'00000000' ; LED1-5 off
movwf GPIO
goto CheckSwitch
OSCCAL_CODE CODE H'3FF' ; 0x3ff ; BUG 8: Inconsistent syntax use H'3FF'
GetOSCCAL:
end