Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
PROCESSOR 16F84
#include <p16f84a.inc>
__CONFIG _CP_OFF &_WDT_ON &_PWRTE_ON &_XT_OSC
;*****Set up the Constants****
COUNT1 equ 30h
COUNT2 equ 31h
COUNT3 equ 32h
COUNT4 equ 33h
COUNT5 equ 34h
COUNT6 equ 35h
COUNT7 equ 36h
COUNT8 equ 37h
COUNT9 equ 38h
COUNT10 equ 39h
COUNT11 equ 40h
COUNT12 equ 41h
Extra equ 42h
org 0x00
goto Main
Main
bsf 03h,5 ;Go to Bank 1
movlw 00h ;Put 0h into W
movwf TRISB ;Move W onto TRISB – all pins set to output
movlw 03h ;Put 3h into W
movwf TRISA ;Move w into TrisA - RA0 , RA1 pins set to input
bcf 03h,5 ;Come back to Bank 0
movlw 0x80 ;Put 80h into W
movwf PORTB ;Move W into PortB
movlw 0x00 ;Put 0h into W
movwf PORTA ;Move W into PortA - All output pins set to 0
movlw 0x00
movwf Extra
Call Settingcounters
Waiting
Btfsc PORTA,1 ;Check Port1 RA1 Status
Call Lightson ;If 1 Call Lightson
clrwdt
goto Waiting
Lightsoff movlw 0x00 ;Put 0h into W
movwf PORTA ;Move W into PortA - All output pins set to 0
Return ;Return to End of loop 2
Lightson movlw 0x4 ;Put 4h into W
movwf PORTA ;Move w into PortA - PortA RA2 Set 1
Call Loop1
Return
Loop1 Btfsc PORTA,1 ;Check PortA RA1 Status
Nop
decfsz COUNT1,1 ;COUNT1 5 Cycles x 200
goto Loop1
movlw 0xC8
movwf COUNT1 ;Set COUNT1 To C8h - 200
clrwdt
decfsz COUNT2,1 ;COUNT2
goto Loop1
movlw 0x64
movwf COUNT2
decfsz COUNT3,1 ;1S Counter
goto Loop1
movlw 0x0A
movwf COUNT3
decfsz COUNT4,1 ;60S Counter
goto Loop1
movlw 0x0A
movwf COUNT4
call Warningon
Return
Warningon movlw 0Ch
movwf PORTA
Call Loop2
Return
Loop2 Btfsc PORTA,1
;Call Addextra
Call Lightson
decfsz COUNT6,1
goto Loop2
movlw 0xC8 ;
movwf COUNT6
decfsz COUNT7,1
goto Loop2
movlw 0x64
movwf COUNT7
decfsz COUNT8,1
goto Loop2
movlw 0x0A
movwf COUNT8
decfsz COUNT9,1
goto Loop2
movlw 0x0A
movwf COUNT9
Call Lightsoff
Return
Settingcounters movlw 0xC8
movwf COUNT1 ;Set COUNT1 to C8 - 200
movlw 0x64
movwf COUNT2 ;Set COUNT2 to 64 - 100
movlw 0x0A
movwf COUNT3 ;Set COUNT3 to 0A - 10
movlw 0x0A
movwf COUNT4 ;Set COUNT4 to 3C - 60
movlw 0xFF
movwf COUNT5
movlw 0xC8
movwf COUNT6
movlw 0x64
movwf COUNT7
movlw 0x0A
movwf COUNT8
movlw 0x0A
movwf COUNT9
movlw 0xC8
movwf COUNT10
movlw 0x64
movwf COUNT11
movlw 0x14
movwf COUNT12
Return
end
SAVE_COUNTERS
bcf STATUS,RP0 ;Switching to Bank 0
bcf INTCON,GIE ;Disabling interrupts
movlw d'12'
movwf loopCounter ;Setting the loop counter
movlw COUNT1 ;Address of COUNT1
movwf FSR ;Setting pointer to the start address
clrf EEADR ;Resetting the EEPROM data start address
SC_LOOP
movf INDF,W ;Reading the COUNTx
movwf EEDATA ;Setting the data register
bsf STATUS,RP0 ;Swithcing to Bank 1
bsf EECON1,WREN ;EEPROM write is enabled
movlw h'55'
movwf EECON2
movlw h'AA'
movwf EECON2
bsf EECON1,WR ;Starting the write operation.
btfsc EECON1,WR ;Checking if the write is complete
goto $-1 ;Wait until it finishes
bcf EECON1,WREN ;EEPROM write is disabled
bcf STATUS,RP0 ;Switching back to Bank 0
incf FSR,F ;Addressing the next COUNTx
incf EEADR,F ;Addressing the next EEPROM location
decfsz loopCounter,F ;Checking if there are more bytes to write
goto SC_LOOP ;Continue operation until all bytes are written
bsf INTCON,GIE ;Enabling interrupts
return
RESTORE_COUNTERS
bcf STATUS,RP0 ;Switching to Bank 0
movlw d'12'
movwf loopCounter ;Setting the loop counter
movlw COUNT1 ;Address of COUNT1
movwf FSR ;Setting pointer to the start address
clrf EEADR ;Resetting the EEPROM data start address
RC_LOOP
bsf STATUS,RP0 ;Switching to Bank 1
bsf EECON1,RD ;Starting the read operation.
bcf STATUS,RP0 ;Switching back to Bank 0
movf EEDATA,W ;Reading the data
movwf INDF ;And placing it to COUNTx register
incf FSR,F ;Addressing the next COUNTx
incf EEADR,F ;Addressing the next EEPROM location
decfsz loopCounter,F ;Checking if there are more bytes to read
goto RC_LOOP ;Continue operation until all bytes are read
return
Waiting
Btfsc PORTA,1 ;Check Port1 RA1 Status
Call Lightson ;If 1 Call Lightson
Call IncEepromCounter ;<<<<<<<<<<<<<<<<<<<<<
clrwdt
goto Waiting
Waiting
Btfsc PORTA,1 ;Check Port1 RA1 Status
Call Lightson ;If 1 Call Lightson
Call IncEepromCounter ;<<<<<<<<<<<<<<<<<<<<<
clrwdt
goto Waiting
LightsOn
Call IncEepromCounter
IncEepromCounter
bsf STATUS,RP0 ;Switching to Bank 1
bsf EECON1,RD ;Starting the read operation.
bcf STATUS,RP0 ;Switching back to Bank 0
incf EEDATA,F ;Incrementing the fresh-read data
bcf INTCON,GIE ;Disabling interrupts
bsf STATUS,RP0 ;Swithcing to Bank 1
bsf EECON1,WREN ;EEPROM write is enabled
movlw h'55'
movwf EECON2
movlw h'AA'
movwf EECON2
bsf EECON1,WR ;Starting the write operation.
btfsc EECON1,WR ;Checking if the write is complete
goto $-1 ;Wait until it finishes
bcf STATUS,RP0 ;Switching back to Bank 0
bsf INTCON,GIE ;Enabling interrupts
return