#include <avr/io.h>
void delay_1ms ();
int main(void)
{
DIDR0 = 0b10100; // didr0 for pb2, pb4
ADCSRA = 0xe0; // continuously read A/D
do{ ADMUX = 0b00100001; //0x21; // select channel 1
delay_1ms(); // some delay is needed
int s1 = ADCH; // s1 = ch1 on pin 7, pb2
ADMUX = 0b00100010; //0x22; // select channel 2
delay_1ms(); // some delay is needed
int s2 = ADCH; // s2 = ch2 on pin 3, pb4
} while (1);
return (0);
}
void delay_1ms () // Use 66 when f = 1.2 MHz.
{ for (int i=0;i<66;i++); // Use 54 when f = 1 MHz.
}
比如使用寄存器操作。
|