;Program for Counter IC ; ; Fuse and Lock bits are defaults. .include "tn2313def.inc" .def W =r16 .def LAMP_S =r20 .def reset_F =r21 .def S_temp =r22 .org 0x00 soft_r: rjmp reset rjmp INTck .org 0x020 ;INT by Clock Procedure============================================ INTck: ;Save Status Register in S_temp,SREG in W,PIND sbrc W,1 ;If PD1 is cleared, next LED. rjmp r_out ; set,reset seq. lm00: cpi LAMP_S,0x00 brne lm01 sbi PORTB,7 ldi LAMP_S,0x01 rjmp exit lm01: cpi LAMP_S,0x01 brne lm02 cbi PORTB,7 sbi PORTB,6 ldi LAMP_S,0x02 rjmp exit lm02: cpi LAMP_S,0x02 brne lm03 cbi PORTB,6 sbi PORTB,5 ldi LAMP_S,0x03 rjmp exit lm03: cpi LAMP_S,0x03 brne lm04 cbi PORTB,5 sbi PORTB,4 ldi LAMP_S,0x04 rjmp exit lm04: cpi LAMP_S,0x04 brne lm05 cbi PORTB,4 sbi PORTB,3 ldi LAMP_S,0x05 rjmp exit lm05: cpi LAMP_S,0x05 brne lm06 cbi PORTB,3 sbi PORTB,2 ldi LAMP_S,0x06 rjmp exit lm06: cpi LAMP_S,0x06 brne lm07 cbi PORTB,2 sbi PORTB,1 ldi LAMP_S,0x07 rjmp exit lm07: cpi LAMP_S,0x07 brne lm08 cbi PORTB,1 sbi PORTB,0 ldi LAMP_S,0x08 rjmp exit lm08: cpi LAMP_S,0x08 brne lm09 cbi PORTB,0 sbi PORTD,6 ldi LAMP_S,0x09 rjmp exit lm09: cpi LAMP_S,0x09 brne lm10 cbi PORTD,6 sbi PORTD,5 ldi LAMP_S,0x0A rjmp exit lm10: cpi LAMP_S,0x0A brne lm11 cbi PORTD,5 sbi PORTD,4 ldi LAMP_S,0x0B rjmp exit lm11: cpi LAMP_S,0x0B brne lm12 cbi PORTD,4 sbi PORTD,3 ldi LAMP_S,0x0C rjmp exit lm12: cpi LAMP_S,0x0C cbi PORTD,3 sbi PORTB,7 ldi LAMP_S,0x01 rjmp exit r_out: ldi reset_F,0xFF ;Set 'Reset flag' ldi W,0x00 ;Clear all LEDs out PORTB,W ldi W,0x00 ;Clear all LEDs out PORTD,W exit: out SREG,S_temp reti ;Main routine======================================================= reset: ldi W,low(RAMEND) ;Set SPL out SPL,W ldi W,0b10000011 ;Pull up disable & out MCUCR,W ;int where INT0 rising edge. ;Clear Reset flag ldi reset_F,0x00 ;Select return to 1 or 0 in W,PIND sbrc W,0 ;If PD0 is cleared, Rto1. rjmp Rto0 ; set,Rto0. ;Case of "return to 1"************** Rto1: sbi PORTB,PORTB7 ldi W,0xff ;PORTB to output. out DDRB,W ldi LAMP_S,0b00000001 ;set lamp status flag ;Interrupt enable routine ldi W,0b01000000 ;INT0 enable out GIMSK,W ldi W,0x00 ;Clear INT0 flag out EIFR,W sei ;Enable General Interrupt ;PIN Assignment ldi W,0b01111000 ;PORTD bit 6-3/output,2-0/input. out DDRD,W ldi W,0b00000110 ;PORTA bit 0,1/output out DDRA,W ;PORTA bit 2 default reset pin. rjmp lp ;Case of "return to 0"************** Rto0: clr W out PORTB,W ldi W,0xff ;PORTB to output. out DDRB,W ldi LAMP_S,0b00000000 ;set lamp status flag ;Interrupt enable routine ldi W,0b01000000 ;INT0 enable out GIMSK,W ldi W,0x00 ;Clear INT0 flag out EIFR,W sei ;Enable General Interrupt ;PIN Assignment ldi W,0b01111000 ;PORTD bit 6-3/output,2-0/input. out DDRD,W ldi W,0b00000110 ;PORTA bit 0,1/output out DDRA,W ;PORTA bit 2 default reset pin. rjmp lp ;waiting clock INT=========================== lp: nop cpi reset_F,0xFF brne lp rjmp reset