; avra -I ~/.avr pot15.asm ; avrdude -p t15 -c STK500v2 -P /dev/ttyS0 -U pot15.hex .include "tn15def.inc" .def LEDS = r16 ; temporary register .def Delay = r17 ; Delay variable 1 .def Delay2 = r18 ; Delay variable 2 .def ADCSET = r19 ; for ADC setup ; ** init SETUP: ser LEDS cbr LEDS, 1 ; PB5 is for ADC out DDRB, LEDS ; set portb to output ldi ADCSET, 0x80 ; load ADMUX: REFS = 10, PB5, LAR=0 out ADMUX, ADCSET ldi ADCSET, 0xE0 ; load ADCSR: Enable, Start and Free run out ADCSR, ADCSET LOOP: ; read ADC value (low first, then high) mov ZL, ADCL mov ZH, ADCH rcall FiveOf400 ; translate to LED mapping ; sbr LEDS, 1 ser LEDS rcall UPDATE rcall REST ; cbr LEDS, 1 clr LEDS rcall UPDATE rcall REST rjmp LOOP ; repeat loop forever FiveOf400: ; {80, 160, 240, 320, 400} to {1, 3, 7, 15, 31} ; divide by two lsr zh ; carries over to... ror zl ; 0 1 2 3 4 ; {40, 80, 120, 160, 200} cpi zl, 120 ; compare with 120 brlo under120 ; < 120 under120: ;23:48 < zauslande> (1) Is it < or >= to the {2,3} boundary, branch accordingly ; to the next comparison. ;23:49 < zauslande> if < then (2) Is it < or >= to the {0,1} boundary, map < to ; 0, map >= to 1 ;23:49 < zauslande> if >= then (2) Is it < or >= to the {3,4} bondary, map < to ; 3, map >= to 4 UPDATE: out PORTB, LEDS ; update LEDs ret REST: dec Delay brne REST dec Delay2 brne REST clr Delay clr Delay2 ret