.include "tn15def.inc" .def temp =R25 .def itemp =R24 .def itemp2=R23 .def lock =R1 .def cnt0 =R2 .def cnt10 =R19 .def cnt11 =R20 .def TOcnt0 =R22 .def TOcnt1 =R18 .def Status = R21 .equ rot =0 .equ gelb =1 .equ gruen =3 .cseg rjmp start ;1 $000 RESET External Reset, Power-on Reset,Brown-out Reset, and Watchdog Reset rjmp IRQ0 ;2 $001 INT0 External Interrupt Request 0 reti ;3 $002 I/O Pins Pin Change Interrupt reti ;4 $003 TIMER1, COMPA Timer/Counter1 Compare Match A rjmp Timer1 ;5 $004 TIMER1, OVF Timer/Counter1 Overflow rjmp Timer0 ;6 $005 TIMER0, OVF Timer/Counter0 Overflow reti ;7 $006 EE_RDY EEPROM Ready reti ;8 $007 ANA_COMP Analog Comparator reti ;9 $008 ADC ADC Conversion Complete start: ldi temp,$ff out PORTB,temp ldi temp,$05 ; // Timer0 Prescaler = CK/1024 (ca. 5.2 Hz bei Overflow) out TCCR0,temp ldi temp,$08 // Timer1 Prescaler = CK/8 out TCCR1,temp ldi temp,$40 out GIMSK,temp; // INT0 einschalten ldi temp,$06 out TIMSK,temp // erst nur Timer1 einschalten --> Ampelphasen einmal durchlaufen clr cnt0 clr cnt10 clr cnt11 // Port B einrichten (die ersten 2+4 bits auf Ausgang) ldi temp,0b00001011 out DDRB,temp // Zuerst Ampel auf rot stellen sbi PORTB,gelb sbi PORTB,gruen cbi PORTB,rot clr Status mov TOcnt0,Status mov TOcnt1,Status ldi temp,$30 // low level of int0, and enable sleep-mode as powerdown out MCUCR,temp main_loop: sei nop nop cli cpi TOcnt1,$5 brne main_loop; //wenn die Phasen einmal durchlaufen wurden, dann Timer abschalten ldi temp,$FF out PORTB,temp sei sleep clr TOcnt0; mov TOcnt1,TOcnt0 out TIMSK,TOcnt0 rjmp start IRQ0: tst lock brne exit_irq ser itemp mov lock,itemp // merken, dass Taste gedrückt wurde ... /elektronisches entsperren; // Timer 0 Interrupt einschalten clr itemp out TCNT1,itemp mov TOcnt0,itemp mov TOcnt1,itemp cpi Status,$2 brne to_grn ldi Status,$4 reti to_grn: clr Status exit_irq: reti; Timer1: clc ldi itemp,$1 add cnt10,itemp brcc t1_add inc cnt11 t1_add: cpi cnt11,$3 brne exit_t1 inc Status cpi Status,$1 brne s2 // Rot->Rot+Gelb cBi PORTB,gelb rjmp exit_t1a s2: cpi Status,$2 brne s3 // Rot+Gelb --> Grün sBi PORTB,rot sBi PORTB,gelb cBi PORTB,gruen rjmp exit_t1a s3: cpi Status,$3 breq dec_unlock cpi Status,$5 brne s6 // Grün -->Gelb sBi PORTB,rot CBi PORTB,gelb SBi PORTB,gruen rjmp exit_t1a s6: cpi Status,$7 brne exit_t1a // Gelb -->Rot cbi PORTB,rot sBi PORTB,gelb dec_unlock: dec Status clr lock exit_t1a: clr cnt10 clr cnt11 exit_t1: reti; Timer0: dec TOcnt0 brne exit_t0 ldi itemp2,$1 add TOcnt1,itemp2 exit_t0: reti;