;********************************************************************* ;* ;* ;* File Name : ADC_DEMO.ASM ;* Title : Analog to Digital converter test ;* Date : 07/04/99 ;* Target MCU : AT90S8535 or AT90S4433 on STK200 ;* Coded By : Tim Kuechler ;* ;* ;* ;* This program measures the voltage present at ADC0 on Analog port ;* of STK200 Kit in terms of the ADC output. ;* ;* BUTTON FUNCTIONS: ;* PD0 = Start measuring (Default) ;* PD1 = Stop measuring ;* PD2 = Show LSB of measurement Display LEDs On Solid (Default) ;* PD3 = Show MSB of measurement Display LEDs Flashing ;* ;* Data is displayed on LEDs of port B ;* ;* Psuedo code ;* ;*RESET: ;* ;* INIT_STACK ;* INIT_KEYS ;* INIT_DISPLAY ;* INIT_AD_CONV ;* INIT_TIMER0 (flash rate) ;* ;*MAIN: ;* IF [convert] ;* READ_VOLTS ;* ENDIF ;* DISPLAY_VOLTS ;* KEYSCAN ;* rjmp MAIN ;* ;*READ_VOLTS: ;* SET_AD ;* START_CONV ;* IDLE Wait for conversion interrupt ;* RETURN ;* ;*ADC: Conversion interrupt ;* ;* ;*Things to watch on ADC: ;*1) ADSC stays high while conv is in progress ;*2) Always read from ADCL before ADCH. This locks ADCH. ;*3) If ADC using noise canceller, make sure ADSC is low before entering IDLE state ;*4) ADMUX at I/O 0x07 ADCSR at I/O 0x06 ;*5) INPORTANT: Writing a 1 to ADIF will CLEAR a pending ADC interrupt ;*This can happen on a Read-Modify-Write cycle even if that bit is not touched ;*For example a set bit to another bit in that register. ;* ;* ;* STOP_CONV ;* GET_VOLTS ;* RETI ;* ;*DISPLAY_VOLTS: ;* IF [FLSH_MOD] ;* GET_MSB_VOLTS ;* ELSE ;* GET_LSB_VOLTS ;* ENDIF ;* AND FLSH_MSK (If the display is supposed to be flashing, is it on or off?) ;* OUTB ;* RET ;* ;*KEYSCAN: ;* IF [BUTTON 0] ;* DEBOUNCE ;* convert=1 ;* ENDIF ;* IF [BUTTON 1] ;* DEBOUNCE ;* convert=0 ;* ENDIF ;* IF [BUTTON 2] ;* DEBOUNCE ;* msb=false ;* ENDIF ;* IF [BUTTON 3] ;* DEBOUNCE ;* msb=true ;* ENDIF ;* ;* ;*TIM0_OVF: ;* DECR TIME ;* IF [TIME=0] ;* IF [FLSH_MSK & FLSH_MOD] ;* FLSH_MSK=00 ;* TIME=SHORT ;* ELSE ;* FLSH_MSK=FF ;* TIME=LONG ;* ENDIF ;* ENDIF ;* RESTART_TIMER ;* RETI ;* ;* ;* ;* ;* ;* ;* ;* ;********************************************************************** .include "8535def.inc" ;**************************** SET UP CONSTANTS ************************ .def TEMP = R16 .def ITEMP = R23 .def SPEED = R25 .def UP_DOWN = R26 ; 0 = UP, 1 = DOWN .def PGM = R27 ; 0=Count, 1=LPM, 2=PWM Auto, 3=PWM Man .equ EE_TST = 0x0001 ; E2 Test Location .equ EE_SPD = 0x0002 ; E2 SPEED Location .equ EE_UP = 0x0003 ; E2 UP_DOWN Location .equ EE_PGM = 0x0004 ; E2 PGM Location ;ADC INIT CONSTANTS def ADC_LO = r20 ;Storage location for raw A/D conversion result .def ADC_HI = r21 .equ ADC_CH0 = 0x00 ; Select channel zero on ADC MUX .equ ADC_INI = 0b10000101 ; ADEN=1, ADSC=0 ; ADFR=0, ADIF=0, ADIE=0 No interrupts yet please ; Prescale = 101: 4MHZ/32 = 125KHz .equ ADC_COV = 1<