;Program for 20 minute timer (FINAL) ; 2009/7/18 ; Fuse and Lock bits are defaults. ; [ != ] means 'not equal'. .include "tn2313def.inc" .def W =r16 .def min_n =r19 .def led_n =r20 .def S_temp =r21 .org 0x00 soft_r: rjmp reset rjmp INTck nop nop nop rjmp ovf1 .org 0x020 ;Wake up from Sleep routine INTck: clr W out GIMSK,W ;Disable further INT0 interrupt reti ;Main routine======================================================= reset: ldi W,low(RAMEND) ;Set SPL out SPL,W clr min_n clr led_n ;Set MCUCR ldi W,0b00110000 ;bit7=0,Pull up enable ;bit6/4=0/1,Power-down mode(Sleep) ;bit5=1,Sleep Enable ;bit3/2=0/0,INT1...no concern ;bit1/0=0/0,INT0...interrupt at the low level out MCUCR,W ;Set IO Port ldi W,0b00000000 ; out PORTB,W ;Clear Port B ldi W,0b11111111 out DDRB,W ;Port B, all output ldi W,0b00000100 out PORTD,W ;Clear Port D, Only PD2 is pull up INPUT. ldi W,0b01111011 ; out DDRD,W ;Set TMR1 clr W out TCCR1A,W ;bit7/4=0/0,OC1A/B port normal operation ;bit3/2,reserved ;bit1/0=0/0,CTC mode out TCNT1H,W out TCNT1L,W out TIFR,W ;Clr interrupt flag out EIFR,W ;Clr external interrupt flag ldi W,3 ;Set OCR1A 3*256+208=976,,,1.024msec*976=999.424msec out OCR1AH,W ldi W,208 out OCR1AL,W ldi W,0b01000000 out GIMSK,W ;Enable INT0 interrupt sei ;Enable Global interrupt sleep ;After wake up, TMR1 start sbi PORTD,5 ;Light on the 1st LED clr W out TIFR,W ldi W,0b01000000 out TIMSK,W ;Enable OCF1A interrupt ldi W,0b00001101 ;TMR1 start out TCCR1B,W ;bit7/6,no concern (input capture) ;bit5,NIL ;bit4/3=0/1,CTC on OCR1A ;bit2/0=1,0,1, prescaler 1/1024, TMR1 Start ;Wait for TMR1 interrupt wait: sei rjmp wait ;================================================================================ ;TMR1 overflow subroutine ovf1: min_sq: inc min_n cpi min_n,60 brne ovf_xt ;min != 60, exit from ovf1 routine led_sq: clr min_n inc led_n led4: cpi led_n,4 brne led6 sbi PORTD,6 rjmp ovf_xt led6: cpi led_n,6 brne led8 sbi PORTB,0 rjmp ovf_xt led8: cpi led_n,8 brne led10 sbi PORTB,1 rjmp ovf_xt led10: cpi led_n,10 brne led12 sbi PORTB,2 rjmp ovf_xt led12: cpi led_n,12 brne led14 sbi PORTB,3 rjmp ovf_xt led14: cpi led_n,14 brne led16 sbi PORTB,4 rjmp ovf_xt led16: cpi led_n,16 brne led18 sbi PORTB,5 rjmp ovf_xt led18: cpi led_n,18 brne led20 sbi PORTB,6 rjmp ovf_xt led20: cpi led_n,20 brne ovf_xt sbi PORTB,7 ; rjmp ovf_xt ovf_xt: clr W out TIFR,W ldi W,0b01000000 out TIMSK,W ;Enable ovf1 interrupt reti ;