;kitchen.asm ;PortB Connects to 2 Thumb wheel switches ;This allows the user to enter the required ;data as minutes and is read by the processor ;as BCD input ;LED on PD0 lights up for 50 ms every second ;A buzzer on PD1 goes off at the end of the present ;time. ;Usage: set the required number of minutes on the ;thumb wheel switches (0 to 99 minutes) and press ;RESET switch. The timer is now armed and will ;activate the buzzer at the end of the period. ;Dhananjay V. Gadre ;9th April 1999 .include "1200def.inc" .def sec=r19 .def minute=r20 .def time=r21 .def save_status=r0 .cseg .org 0 rjmp RESET ;Reset Handle rjmp Timer_int rjmp Timer_int RESET: ldi r16, 0b00000101 ; DIV1024 selected for timer0 out TCCR0, r16 ; timer 0 counts up now ldi r16, 2 out TIMSK, r16 ldi r16, -175 ; -195 gives 50 ms on 4 MHz out TCNT0, r16 ; -175 gives 50 ms on 3.58 MHz ldi r16, 0 ;configure PORT B for all inputs out DDRB, r16 ldi r16, 255 ; put on the pull ups on PORTB so that the ; switches can be read out PORTB, r16 ldi r16, 255 out DDRD, r16 ;configure pin PD0 as output ldi r16, $ff ; everything on PORTD is off out PORTD, r16 ldi sec, 0 ldi minute, 0 ldi time, 0 sei get_t: in r16, PINB com r16 rcall get_value compare: cp r16, time brne compare outit: cbi PORTD, 1 rjmp outit rjmp outit Timer_int: in save_status, SREG sbi PORTD, 0 ; put off PD0 led if it was on ldi r23, -175 ; actually -195 for 4 MHz ;-175 for 3.58 MHz out TCNT0, r23 inc sec cpi sec, 20 ;20 in sec means 1 second brne go_bak cbi PORTD, 0 ; light up PD0 LED ldi sec, 0 inc minute cpi minute, 60 brne go_bak ldi minute, 0 inc time go_bak: out SREG, save_status reti ;subroutine to convert the BCD value in register r16 ;to a hex value. ;Destroys r17 and r18 contents get_value: in save_status, SREG cpi r16, 0 breq no_good mov r17, r16 andi r17, $0f andi r16, $f0 swap r16 ; get r16 higher nibble to ; lower nibble place mov r18, r16 lsl r16 lsl r16 lsl r16 add r16, r18 add r16, r18 add r16, r17 cpi r16, 100 ; check that the result is less than 99 brlo no_good ;less than 100. so fine, go return ldi r16, 01 ; no, then put in 01 no_good: out SREG, save_status ret