You are on page 1of 2

.

org 0x0000
rjmp reset
.org 0x000E
rjmp ADC_ISR
reset:
ldi r16,
out SPL,
ldi r16,
out SPH,

low(RAMEND)
r16
high(RAMEND)
r16

ldi r16, 0xFF


out DDRD, r16
ldi
out
ldi
out

r16, 0
ADMUX, r16
r16, 0b11101101
ADCSR, r16

sei
loop:
rjmp loop
ADC_ISR:
push r16
in r16, SREG
push r16
push r17
in r16, ADCL
in r17, ADCH
lsr r17
ror r16
lsr r17
ror r16
com r16
out PortD, r16
pop r17
pop r16
out SREG, r16
pop r16
reti
; reset vector
; jump to "reset"
;
; ADC Conversion Complete Interrupt vector:
; jump the "ADC_ISR"
;
; the reset code:
; stack setup; set SPH:SPL to
; RAMEND
;
;
;
; set all PortD pins to output
;
;

;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;

write zero
to ADMUX (select channel 0)
from left to right: ADC Enable, Start Conversion, Free-Running Mode, write
zero to ADC Int flag, enable int, prescaler: 101 for XTAL/32
enable interrupts
and loop
forever
Here it is, our ISR!
save r16
use r16 16 to save SREG
(push both on stack)
also save r17
get the last ADC result, low byte first,
then high byte
shift ADC result right (2 bits)
by first shifting out bit 0 of r16, then shifting it into r17
(twice)
now invert result
and write to PortD
restore r17,
SREG
and r16
and return