;;
;;
;; Tuinverlichtingsautomaat.asm, a PIC 16F84 program to control garden lights.
;;
;; Copyright (C) 2000 Geert Van Espen (geert.van.espen@bigfoot.com)
;;
;;
processor 16c84
include "p16c84.inc"
;
;
; Schematic diagram used for connecting the input switches, LDR, and relay output to the PIC 16F84
;
; 12-position switch
;
; .__1________________________x___________________________________x_____________ RB1
; / .__2_______________________|_____x_____________________________|_x___________ RB2
; / .__3______________________|_____|_____x_______________________|_|_x_________ RB3
; 1K / .__4_____________________|_____|_____|_____x_________________|_|_|_x_______ RB4
; _____/\/\/\___./ .__5____________________|_____|_____|_____|_____x___________|_|_|_|_x_____ RB5
; | .__6____________________|_____|_____|_____|_____|_____x_____|_|_|_|_|_x___ RB6
; +5V .__7_________________ | | | | | | | | | | | |
; .__8_______________ | | | | | | | | | | | | |
; .__9______________ | | | | | | | | / / / / / /
; .__10____________ | | | | | | | | | \ \ \ \ \ \
; .__11____________ | | | | | | | | | | / / / / / /
; .__12__________ | | | | | | | | | | | \ \ \ \ \ \
; | | | | | | | | | | | | | | | | | |
; | | | | | | | | | | | | | | | | | |
; switch positions | | | | | | | | | | | | | | | | | |
; **************** | | | | | | | | | | | | | | | | | |
; 1 = manual off | | | | | | | | | | | | | | | | | |
; 2 = manual on | | | | | | | | | | | | | | | | | |
; 3 = dusk till dawn | | | | | | | | | | | | |_|_|_|_|_|_
; 4 = +1h | | | | | | _|_ _|_ _|_ _|_ _|_ _|_ |
; 5 = +2h | | | | | | / \ / \ / \ / \ / \ / \ _|_
; 6 = +3h | | | | | | --- --- --- --- --- ---
; 7 = +4h | | | | | | | | | | | | 7 x 4K7
; 8 = +5h | | | | | |__x | | | | |
; 9 = +6h | | | | |____|_____x | | | | ____
; 10 = +7h | | | |______|_____|_____x | | | | |
; 11 = +8h | | |________|_____|_____|_____x | | | |
; 12 = +9h | |__________|_____|_____|_____|_____x | | _|_
; |____________|_____|_____|_____|_____|_____x |
; | | | | | | /
; | | | | | | \
; | | | | | | /
; _|_ _|_ _|_ _|_ _|_ _|_ \
; \ / \ / \ / \ / \ / \ / |
; --- --- --- --- --- --- |
; | | | | | | |
; |_____|_____|_____|_____|_____|____________|________ RB0
;
;
;
; _______________ +5V
; |
; |
; \
; / 22K
; \
; /
; |
; \
; / 100K POTmeter
; \
; /
; |
; x___________________________________________________ RB7
; |
; |
; \
; /
; \
; / LDR
; \
; /
; |
; |______________
; |
; _|_
;
;
;
;
;
;
;
;
; | +5V
; |
; _________x
; | __|___
; _|_ | relay|
; / \ |______|
; --- |
; | |
; |_________x
; |
; \
; \
; \|____________/\/\/\____________________________ RA0
; /| 1K
; |/_
; / BC547
; |
; |
; |
; _|_
;
; all diodes 1N4148 or similar
;
; commando om dit project naar de pic te sturen:
; TOPIC -RWG TUIN.HEX
; general purpose register allocation
werk equ 0x0c ; werkregister
ddd equ 0x14 ; debug only
t1 equ 0x0d ; telwerk 1
t2 equ 0x0e ; telwerk 2
TIJDl equ 0x10 ; to keep track of time
TIJDh equ 0x11
KLAPPERTIJD equ 0x15 ; hysteresis
LDR_STAND equ 0x16 ; 0=donker 1=licht
tempvar equ 0x18 ;
Wl equ 0x20 ;
Wh equ 0x21 ;
; tijdconstanten
EENuurL equ 0x10 ;
EENuurH equ 0x0e ; 3600
TWEEuurL equ 0x20 ;
TWEEuurH equ 0x1c ; 7200
DRIEuurL equ 0x30 ;
DRIEuurH equ 0x2a ; 10800
VIERuurL equ 0x40 ;
VIERuurH equ 0x38 ; 14400
VIJFuurL equ 0x50 ;
VIJFuurH equ 0x46 ; 18000
ZESuurL equ 0x60 ;
ZESuurH equ 0x54 ; 21600
ZEVENuurL equ 0x70 ;
ZEVENuurH equ 0x62 ; 25200
ACHTuurL equ 0x80 ;
ACHTuurH equ 0x70 ; 28800
NEGENuurL equ 0x90 ;
NEGENuurH equ 0x7e ; 32400
TIENuurL equ 0x91 ;
TIENuurH equ 0x7e ; 324101
;;;;;;;;;;;;;;;;
m_input_a equ b'00000000' ; input mask, which bits are input
m_input_b equ b'11111111' ;
;org 0x00 ; reset vector
goto main
dt "2000-06-04 geert.van.espen@bigfoot.com Tuinverlichting"
initialise: ; set up ports
MOVLW 0
TRIS 5
MOVLW 0xFF
TRIS 6
MOVLW 0x80
OPTION
clrf TIJDl ; initialisaties
clrf TIJDh ;
clrf KLAPPERTIJD ;
clrf LDR_STAND ;
clrf PORTA ; UIT laag
clrf PORTB
; uitgang even aan en uit laten knipperen om te laten zien dat het
; apparaat werkt
movlw 1 ;
movwf PORTA ;
movlw 6 ; knipper 3 keer
movwf t1 ;
functiontest:
movlw 0x19 ; wacht halve seconde
call wachtlus ;
movlw 1 ;
btfsc PORTA,0 ;
movlw 0 ;
movwf PORTA ;
decfsz t1,f ;
goto functiontest ;
clrf PORTA ; UIT laag
retlw 0
wachtlus:
; wacht x keer 18 milliseconden, met x in w
movwf werk ; zet w in werk
; debug only
; movlw 1
; movwf werk
slapertje:
sleep ;
decfsz werk,f ;
goto slapertje ;
retlw 0
main:
;btfsc STATUS,NOT_TO ; if this is a reset or power-up ...
call initialise ; set port drivers and WDT prescaler
start:
test_manual_off:
btfss PORTB,1 ; test if manual off input high
goto test_manual_off_af; (but RB0 must be low)
btfsc PORTB,0 ;
goto test_manual_off_af;
clrf PORTA ; UIT laag
clrf TIJDl ;
clrf TIJDh ; TIJD = 0
movlw 0x5 ; wacht fraktie van seconde
call wachtlus ;
goto start ;
test_manual_off_af:
test_manual_on:
btfss PORTB,2 ; test if manual on input high
goto test_manual_on_af; (but RB0 must be low)
btfsc PORTB,0 ;
goto test_manual_on_af;
movlw 1 ;
movwf PORTA ; UIT hoog
clrf TIJDl ;
clrf TIJDh ; TIJD = 0
movlw 0x5 ; wacht fraktie van seconde
call wachtlus ;
goto start ;
test_manual_on_af:
test_ldr_stand:
btfsc LDR_STAND,0 ;
goto test_ldr_stand_af;
clrf PORTA ; UIT laag
clrf TIJDl ; TIJD = 0
clrf TIJDh ;
test_ldr_stand_af:
hysteresis:
movf PORTB,w ;
movwf tempvar ;
rrf tempvar,f ;
rrf tempvar,f ;
rrf tempvar,f ;
rrf tempvar,f ;
rrf tempvar,f ;
rrf tempvar,f ;
rrf tempvar,f ;
movf tempvar,w ;
andlw 1 ;
subwf LDR_STAND,w ;
btfss STATUS,Z ; LDR input = LDR_STAND?
goto hyst1 ;
movlw 0 ;
movwf KLAPPERTIJD ; ja: KLAPPERTIJD = 0
goto hyst2 ;
hyst1: incf KLAPPERTIJD,f ; neen: verhoog KLAPPERTIJD
goto hyst2 ;
hyst2:
btfss KLAPPERTIJD,4 ; KLAPPERTIJD hoog?
goto hyst3 ;
movf PORTB,w ;
movwf tempvar ;
rrf tempvar,f ;
rrf tempvar,f ;
rrf tempvar,f ;
rrf tempvar,f ;
rrf tempvar,f ;
rrf tempvar,f ;
rrf tempvar,f ;
movf tempvar,w ;
andlw 1 ;
movwf LDR_STAND ; LDR_STAND = LDR input
movlw 0 ;
movwf KLAPPERTIJD ; KLAPPERTIJD = 0
hyst3:
;SLEEP ; main loop sleep
movlw 0x36 ; 54 = 1 seconde
call wachtlus ;
incf TIJDl,f ;
btfsc STATUS,Z ;
incf TIJDh,f ;
test_dusktilldawn:
btfss PORTB,3 ; test if dusktilldawn input high
goto test_dusktilldawn_af; (but RB0 must be low)
btfsc PORTB,0 ;
goto test_dusktilldawn_af;
btfss LDR_STAND,0 ; LDR_STAND = 1?
goto start ;
movlw 1 ;
movwf PORTA ; UIT hoog
clrf TIJDl ; TIJD = 0
clrf TIJDh ;
goto start ;
test_dusktilldawn_af:
btfsc LDR_STAND,0 ;
goto ldrtest_af ;
clrf TIJDl ; TIJD = 0
clrf TIJDh ;
ldrtest_af:
movf TIJDl,w ; W = TIJD
movwf Wl ;
movf TIJDh,w ;
movwf Wh ;
test_1h:
btfss PORTB,4 ; test if 1h input high
goto test_1h_af ; (but RB0 must be low)
btfsc PORTB,0 ;
goto test_1h_af ;
movf Wl,w ;
sublw EENuurL ;
movwf Wl ;
movf Wh,w ;
btfss STATUS,C ;
incf Wh,w ;
sublw EENuurH ;
movwf Wh ;
test_1h_af:
test_2h:
btfss PORTB,5 ; test if 2h input high
goto test_2h_af ; (but RB0 must be low)
btfsc PORTB,0 ;
goto test_2h_af ;
movf Wl,w ;
sublw TWEEuurL ;
movwf Wl ;
movf Wh,w ;
btfss STATUS,C ;
incf Wh,w ;
sublw TWEEuurH ;
movwf Wh ;
test_2h_af:
test_3h:
btfss PORTB,6 ; test if 3h input high
goto test_3h_af ; (but RB0 must be low)
btfsc PORTB,0 ;
goto test_3h_af ;
movf Wl,w ;
sublw DRIEuurL ;
movwf Wl ;
movf Wh,w ;
btfss STATUS,C ;
incf Wh,w ;
sublw DRIEuurH ;
movwf Wh ;
test_3h_af:
test_4h:
btfss PORTB,1 ; test if 4h input high
goto test_4h_af ; (but RB0 must be high)
btfss PORTB,0 ;
goto test_4h_af ;
movf Wl,w ;
sublw VIERuurL ;
movwf Wl ;
movf Wh,w ;
btfss STATUS,C ;
incf Wh,w ;
sublw VIERuurH ;
movwf Wh ;
test_4h_af:
test_5h:
btfss PORTB,2 ; test if 5h input high
goto test_5h_af ; (but RB0 must be high)
btfss PORTB,0 ;
goto test_5h_af ;
movf Wl,w ;
sublw VIJFuurL ;
movwf Wl ;
movf Wh,w ;
btfss STATUS,C ;
incf Wh,w ;
sublw VIJFuurH ;
movwf Wh ;
test_5h_af:
test_6h:
btfss PORTB,3 ; test if 6h input high
goto test_6h_af ; (but RB0 must be high)
btfss PORTB,0 ;
goto test_6h_af ;
movf Wl,w ;
sublw ZESuurL ;
movwf Wl ;
movf Wh,w ;
btfss STATUS,C ;
incf Wh,w ;
sublw ZESuurH ;
movwf Wh ;
test_6h_af:
test_7h:
btfss PORTB,4 ; test if 7h input high
goto test_7h_af ; (but RB0 must be high)
btfss PORTB,0 ;
goto test_7h_af ;
movf Wl,w ;
sublw ZEVENuurL ;
movwf Wl ;
movf Wh,w ;
btfss STATUS,C ;
incf Wh,w ;
sublw ZEVENuurH ;
movwf Wh ;
test_7h_af:
test_8h:
btfss PORTB,5 ; test if 8h input high
goto test_8h_af ; (but RB0 must be high)
btfss PORTB,0 ;
goto test_8h_af ;
movf Wl,w ;
sublw ACHTuurL ;
movwf Wl ;
movf Wh,w ;
btfss STATUS,C ;
incf Wh,w ;
sublw ACHTuurH ;
movwf Wh ;
test_8h_af:
test_9h:
btfss PORTB,6 ; test if 9h input high
goto test_9h_af ; (but RB0 must be high)
btfss PORTB,0 ;
goto test_9h_af ;
movf Wl,w ;
sublw NEGENuurL ;
movwf Wl ;
movf Wh,w ;
btfss STATUS,C ;
incf Wh,w ;
sublw NEGENuurH ;
movwf Wh ;
test_9h_af:
test_10h:
movf Wl,w ;
sublw TIENuurL ;
movwf Wl ;
movf Wh,w ;
btfss STATUS,C ;
incf Wh,w ;
sublw TIENuurH ;
movwf Wh ;
test_10h_af:
test_overtime:
btfss STATUS,C ; W < 0 ?
goto overtime ;
no_overtime:
btfss LDR_STAND,0 ; LDR_STAND = 1?
goto test_overtime_af;
movlw 1 ;
movwf PORTA ; UIT hoog
goto test_overtime_af;
overtime:
clrf PORTA ; UIT laag
movlw 0xf8 ;
movwf TIJDl ;
movlw 0x7f ;
movwf TIJDh ; TIJD = 32760
goto test_overtime_af;
test_overtime_af:
goto start ;
;;
;;
end
Voorbeeld van een klevertje voor de 12-positie schakelaar:
| Stroomschema (Word 97 document) | Stroomschema (PDF formaat) |
Foto van het afgewerkte apparaat