下面是在网上搜到其它的程序,第10行也有个“ADCW” 。 没法用红色标出,请大家自己数行数。
#i nclude<90s9535.h>
#define LEDS PORTD
#define red 0xfe
#define yellow 0xfd
#define green 0xfc
#define uchar unsigned char
interrupt[ADC_INT] void adc_isr(void)
{
uchar adc_data; //variable for ADC result
adc_data=ADCW; //read all 10bits into variable
if(adc_data>(3*1023)/5)
LEDS=red;
else(adc_data<(2*1023)/5)
LEDS=yellow;
else
LEDS=green;
ADCSR=ADCSR|0x40; //start the next conversion
}
void main()
{
DDRD=0x07; //least signifcant 3 bits for output
ADMUX=0x03; //select to read only channel 3
ADCSR=0xCE; //ADC中断,64分频
#asm("sei")
while(1); //等待ADC中断产生
}
|