;***** AtoD Test with interrupt driven timing ******** ;Timer 1 match function is used to take 1 sample/sec ; and display the top 8 bits on the LEDs. ;You will need to CHANGE this path .include "8535def.inc" .device AT90S8535 ; specifies to the assembler which chip we are using .def save =r1 ;SREG temp reg .def temp =r16 ;temporary register .def AnaLo =r17 ;A to D result .def AnaHi =r18 ; .def itemp =r19 ;temp reg for interrupts ;***** Initialization .cseg .org $0000 rjmp RESET ;reset entry vector reti reti reti reti reti rjmp t1match reti reti reti reti reti reti reti reti reti reti RESET: ldi temp, LOW(RAMEND) ;setup stack pointer out SPL, temp ldi temp, HIGH(RAMEND) out SPH, temp ;set up port B to run LEDS ser temp ;set PORTD to be out DDRD,temp ;all outputs to LEDs out PORTD, temp ;set up Timer 1 to interrupt on compare A match ;and set the compare time to 62500 ticks ldi temp,0b00010000 ;enable t1 matchA interrupt out TIMSK, temp ldi temp, 0x00 ;set the match A register to out OCR1AH, temp ;83 since 83*2us=166us=1/6000 ldi temp, 83 ;62500 = 0xf424 out OCR1AL, temp ldi temp,0b00001010 ;prescale timer by 8 (one tick=16 microsec) out TCCR1B, temp ;and clear-on-matchA ;set up analog converter to read channel zero ldi temp, 7 out ADMUX, temp sei ;enable all interrupts swait: in temp, ADCSR ;wait for A to D start andi temp, 0b01000000;by checking if ADSC bit is set breq swait ;this bit is set by t1match interrupt await: in temp, ADCSR ;wait for A to D done andi temp, 0b01000000;by checking ADSC bit brne await ;this bit is cleared by the AtoD hardware in AnaLo, ADCL ;read the voltage in AnaHi, ADCH lsr AnaHi ;double precision shift ror AnaLo ;right twice lsr AnaHi ror AnaLo com AnaLo ;invert for LEDs out PORTD, AnaLo ;output the top 8 bits rjmp swait ;**** timer 1 compare A match 1/sec t1match:in save, SREG ldi itemp, 0b11000101 ;start A to D conversion out ADCSR, itemp out SREG, save reti