;room power control with counter
list P = 16F628a ;microcontroller
#include <P16F628a.inc> ;registers for F628
__CONFIG _CP_OFF & _LVP_OFF & _PWRTE_ON & _WDT_OFF & _INTRC_OSC_NOCLKOUT & _MCLRE_OFF
temp1 equ 20h ;for delay
temp2 equ 21h ;for delay
SwUp equ 22h ;
SwDwn equ 23h ;
units equ 24h ;
tens equ 25h ;
Sw_Flag equ 26h ;
countt1 equ 27h
countt2 equ 28h
countt3 equ 29h
reset org 00
goto SetUp ;goto SetUp
table addwf PCL,F ;add W to program counter
retlw b'00111111'
retlw b'00000110'
retlw b'01011011'
retlw b'01001111'
retlw b'01100110'
retlw b'01101101'
retlw b'01111101'
retlw b'00000111'
retlw b'01111111'
retlw b'01101111'
SetUp
movlw b'00001100'
banksel TRISA
movwf TRISA
clrf TRISB ;Make all RB output
movlw b'10000000'
movwf option_reg
banksel 0
clrf units
clrf tens
clrf Sw_Flag
movlw 0x00
movwf PORTB
movlw 07h
movwf cmcon
goto Main
Delay movlw 0Ah
movwf temp2
nop
decfsz temp1,1
goto $-2
decfsz temp2,1
goto $-4
retlw 00
D_1000ms movlw .255
movwf countt1
movlw .255
movwf countt2
movlw .255
movwf countt3
decfsz countt1,1
goto $-1
decfsz countt2,1
goto $-1
decfsz countt3,1
goto $-1
return
Up btfsc Sw_Flag,2
retlw 00
bsf Sw_Flag,2
incf units,1
movlw 0Ah
xorwf units,0
btfss status,2
retlw 00
clrf units
incf tens,1
movlw 0Ah
xorwf tens,0
btfsc status,2
clrf tens
retlw 00
Dwn btfsc Sw_Flag,3
retlw 00
bsf Sw_Flag,3
decf units,1
movlw 0FFh
xorwf units,0
btfss status,2
retlw 00
movlw 09
movwf units
decf tens,1
movlw 0FFh
xorwf tens,0
btfsc status,2
goto $+2
retlw 00
clrf tens
clrf units
retlw 00
Main btfss portA,2
call Up
btfss portA,3
call Dwn
movlw b'00000001'
movwf portA
movf units,0
call table
movwf portB
call Delay
clrf portB
movlw b'00000010'
movwf portA
movf tens,0
call table
movwf portB
call Delay
clrf portB
btfsc portA,2
bcf Sw_Flag,2
btfsc portA,3
bcf Sw_Flag,3
goto Main
END