;Firmware for the avr in the GWEMeter-setup. ;Copyright 2006 Jeroen Domburg . This ;software is licensed under the GPL. ;We're using a tiny2313 here. .device ATTiny2313 ;You might want to include the ATTiny2313-definitions included with ;your assembler. I use gavrasm, which doesn't need them. ;The fuses should be configured as follows: ;FUSE_L=0xcf ;FUSE_H=0xdf ;Port declarations ;PortB .equ led1 = 7 .equ ldr1 = 6 .equ led2 = 5 .equ ldr2 = 4 .equ led3 = 3 .equ ldr3 = 2 .equ led4 = 1 .equ ldr4 = 0 ;Port D .equ ind1 = 2 .equ ind2 = 3 .equ ind3 = 4 .equ ind4 = 5 .def a1 = r1 .def a2 = r2 .def a3 = r3 .def b1 = r4 .def b2 = r5 .def b3 = r6 .def c1 = r7 .def c2 = r8 .def c3 = r9 .def d1 = r10 .def d2 = r11 .def d3 = r12 .def temp = R16 ;The temp register .def temp2 = R17 ;Second temp register .def temp3 = R18 .def tha = r19 .def thb = r20 .def thc = r21 .def thd = r22 .def oldon = r23 rjmp start ; reset vector reti ; External Int 0 not enabled reti ; External Int 1 not enabled reti ; Timer 1 Capture Int not enabled reti ; Timer 1 Compare match A Int not enabled reti ; Timer 1 Overflow Int not enabled reti ; Timer 0 Overflow Int not enabled reti ; UART ReceiveInt reti ; UART Date Reg Empty Int not enabled reti ; UART tx'ed Int Not enabled reti ; Anacomp interrupt Not enabled start: ldi temp,RAMEND ; top of memory out SPL,temp ; init stack pointer ldi temp,0b010101010 ; Port B direction options out DDRB,temp ; Setup port direction ldi temp,0b00111100 ; Port D direction options out DDRD,temp ; Setup port direction ;Configure uart ldi temp,0b011000 out ucsrb,temp ldi temp,0b0110 out ucsrc,temp ldi temp,high(10) out ubrrh,temp ldi temp,low(10) out ubrrl,temp ;Wait till the router has booted completely and the program that reads out ;the uC is running. We know that because that program sends the magic string ; 'M4g1c!' on start. wait4magic: ldi temp,0b0000 out portd,temp rcall getchar cpi temp,'M' brne wait4magic ldi temp,0 out portd,temp rcall getchar cpi temp,'4' brne wait4magic sbi portd,ind1 rcall getchar cpi temp,'g' brne wait4magic sbi portd,ind2 rcall getchar cpi temp,'1' brne wait4magic sbi portd,ind3 rcall getchar cpi temp,'c' brne wait4magic rcall getchar sbi portd,ind4 cpi temp,'!' brne wait4magic clr a1 clr a2 clr a3 clr b1 clr b2 clr b3 clr c1 clr c2 clr c3 clr d1 clr d2 clr d3 mainloop: ;Got a command? sbic ucsra,7 rjmp recvcmd ;Yes -> handle it. ;Counting stuff ldi temp2,0 cbi portd,ind1 ldi temp,1<G t T >tha >thb >thc >thd ;Get a raw sample ; >R C >['1'-'4'] .... >dummy