casovac.asm
;verze 3 - platna
;2014/08
;casovac pro cerpadlo bazenu
;vstupni podminky: 1 min. chod, 15 min. stop
;rozsireni: 5, 10, 20, 30 min. stop
;nastaveni se cte na vstupnich pinech
;PORTB,0 - prepinac casu
;PORTB,1 - prepinac casu
;PORTB,2 - prepinac casu
;PORTB,3 - vystup pro rele
;PORTB,4 - timer
;PORTB,5 - RESET
;r17 - pracovni
;r18 - citac minuta
;r19 - citac minuta
;r20 - pracovni preruseni
;r21 - citac minut
;r22 - flag minuta
;r23 - minuty z prepinace
.equ MINUTA_L = 0x00
.equ MINUTA_H = 0x42
.include "tn25def.inc"
.org 0x00
rjmp RESET
.org 0x04
rjmp TIMER1
.org 0x20
RESET:
cli
ldi r17, 0b00110111
out PORTB, r17
ldi r17, 0b00111000
out DDRB, r17
cbi PORTB,3 ;cerpadlo STOP
;nastaveni zasobniku
ldi r17, 0x70
out SPL, r17
;priprava registru
ldi r17, 0x00
ldi r18, MINUTA_L
ldi r19, MINUTA_H
ldi r20, 0x00
ldi r21, 0x00
ldi r22, 0x00
;spusteni casovace 1 (s preddelicem)
ldi r17, 0b00000000
out GTCCR, r17
ldi r17, 0b00000100
out TIMSK, r17
ldi r17, 0b00000100
out PLLCSR, r17
ldi r17, 0b00001000
out TCCR1, r17
sei ;preruseni povoleno
;nastav rele (vystup)
sbi PORTB,3 ;cerpadlo START
CEKEJ_MINUTU:
tst r22 ;cekej minutu
BREQ CEKEJ_MINUTU
ldi r22, 0x00
;shod rele
cbi PORTB,3 ;cerpadlo STOP
CEKEJ_MINUTU2:
tst r22 ;cekej minutu
BREQ CEKEJ_MINUTU2
ldi r22, 0x00
;cteni stavu prepinace
SBIS PINB, 0
rjmp MINUT_5
SBIS PINB, 1
rjmp MINUT_10
SBIS PINB, 2
rjmp MINUT_20
ldi r23, 0x1E ;30minut
rjmp TEST_MINUT_END
MINUT_5:
ldi r23, 0x05
rjmp TEST_MINUT_END
MINUT_10:
ldi r23, 0x0A
rjmp TEST_MINUT_END
MINUT_20:
ldi r23, 0x14
rjmp TEST_MINUT_END
TEST_MINUT_END:
;porovnani poctu minut s nastavenim prepinace
mov r17, r23 ;vezmi stav prepinace
sub r17, r21 ;odecti pocet minut
;jestli je zaporne cislo pak jdi na RESET (novy cyklus)
;jinak nedelej nic a skok na CEKEJ_MINUTU2
BRPL CEKEJ_MINUTU2
rjmp RESET
STOP:
rjmp RESET
TIMER1:
in r20,SREG ;ulozeni stavoveho slova
inc r18 ;inkrement nizsiho byte
BRNE TIMER1_VEN
;blikani kontrolni LED
sbic PORTB,4
rjmp BLIK_OFF
sbi PORTB, 4
rjmp BLIK_END
BLIK_OFF:
cbi PORTB, 4
BLIK_END:
inc r19 ;inkrement vyssiho byte
BRNE TIMER1_VEN
ldi r18, MINUTA_L
ldi r19, MINUTA_H
inc r21
ldi r22, 0xff
TIMER1_VEN:
out SREG, r20 ;obnoveni stavoveho slova
reti