The MCU programWPC uses ATtiny26 microcontroller manufactured by ATMEL. The MCU program was debuged in AVR Studio. You can see the code below .include "tn26def.inc" .def tmp=r16 .def hrs=r20 .def num=r18 .def m=r21 rjmp RESET rjmp EXT_INT0 ;external interrupt handling RESET: ldi tmp,RAMEND ;stack initialization out sp,tmp ldi tmp,0b01000000 out GIMSK,tmp ldi tmp,0b00000010 out MCUCR,tmp ldi tmp,0b01111111 ;port initialization out ddra,tmp ldi tmp,0b00000110 out ddrb,tmp clr tmp clr hrs rcall INDICATE ;'0' indication START: clr tmp clr hrs rcall INDICATE sei ;allow interrupts STRT: sbis pina,7 ;waiting for button rjmp STRT rcall del_s rcall del_s sbis pina,7 rjmp STRT sbi portb,1 ;indication 'I am rcall del_s ;working!' cbi portb,1 rcall del_s sbi portb,1 rcall del_s cbi portb,1 sbis pinb,3 ;checking 'mode rjmp REPEAT ;selection' button rcall INDICATE TIMER: cli ;TIMER mode rcall INDICATE tst hrs breq IMMEDIATE dec hrs rcall del_h rjmp TIMER IMMEDIATE: rcall IND_LS sbis pinb,5 rjmp START rcall PUMPING clr hrs rjmp START INDICATE: cpi hrs,1 ;indication of ;desired number on a brne TWO ;7-seg indicator ldi num,0b00000110 out porta,num ret TWO: cpi hrs,2 brne THREE ldi num,0b01011011 out porta,num ret THREE: cpi hrs,3 brne FOUR ldi num,0b01001111 out porta,num ret FOUR: brne FIVE ldi num,0b01100110 out porta,num ret FIVE: cpi hrs,5 brne SIX ldi num,0b01101101 out porta,num ret SIX: cpi hrs,6 brne SEVEN ldi num,0b01111101 out porta,num ret SEVEN: cpi hrs,7 brne EIGHT ldi num,0b00000111 out porta,num ret EIGHT: cpi hrs,8 brne NINE ldi num,0b01111111 out porta,num ret NINE: cpi hrs,9 brne ZERO ldi num,0b01101111 out porta,num ret ZERO: ldi num,0b00111111 out porta,num ret REPEAT: cli ;REPEAT mode rcall INDICATE tst hrs breq PUMP rcall del_h dec hrs rcall INDICATE rcall REPEAT PUMP: mov hrs,tmp rcall IND_LS sbis pinb,5 rjmp REPEAT rcall PUMPING rjmp REPEAT PUMPING: ldi m,1 sbi portb,1 sbi portb,2 CONT: com m mov num,m inc num andi num,1 breq INV ldi num,0b00000001 ;'pumping' out porta,num ;indication rcall del_s rcall del_s ldi num,0b00000011 out porta,num rcall del_s rcall del_s ldi num,0b00000111 out porta,num rcall del_s rcall del_s ldi num,0b00001111 out porta,num rcall del_s rcall del_s ldi num,0b00011111 out porta,num rcall del_s rcall del_s ldi num,0b00111111 out porta,num rcall del_s rjmp CHK INV: ldi num,0b00111110 out porta,num rcall del_s rcall del_s ldi num,0b00111100 out porta,num rcall del_s rcall del_s ldi num,0b00111000 out porta,num rcall del_s rcall del_s ldi num,0b00110000 out porta,num rcall del_s rcall del_s ldi num,0b00100000 out porta,num rcall del_s rcall del_s ldi num,0b00000000 out porta,num rcall del_s CHK: rcall del_s sbic pinb,5 rjmp CONT cbi portb,1 cbi portb,2 clr hrs rcall INDICATE ret IND_LS: clr num ;indication out porta,num ;'level sensor rcall del_s ;is being checked' ldi num,0b01011110 out porta,num rcall del_s clr num out porta,num rcall del_s ldi num,0b01011110 out porta,num rcall del_s clr num out porta,num ret EXT_INT0: cpi hrs,9 ;external interrupt brne SKIP ;handling routine clr hrs rjmp S SKIP: inc hrs S: mov tmp,hrs rcall INDICATE reti del_s: push r16 ;time delay push r17 ;0.5 sec push r18 ldi r18,65 del11: ldi r17,49 del12: ldi r16,52 del13: dec r16 brne del13 dec r17 brne del12 dec r18 brne del11 pop r18 pop r17 pop r16 ret del_h: push r16 ;time delay push r17 ;1 hour push r18 push r19 ldi r19,246 del34: ldi r18,140 del33: ldi r17,180 del32: ldi r16,195 del31: dec r16 brne del31 dec r17 brne del32 dec r18 brne del33 dec r19 brne del34 pop r19 pop r18 pop r17 pop r16 ret © 2010 Vadim Loginov |