#include <avr/io.h>
int main(void)
{
// Configure some port for output:
DDRB = 0xFF;
// Setup ADC
// Channel 3
// Left adjustment
// 5V reference
ADMUX = (1<<REFS0) | (1<<ADLAR) | (1<<MUX1) | (1<<MUX0);
// Enable ADC with prescaler 32
ADCSRA = (1<<ADEN) | (1<<ADPS2) | (1<<ADPS0);
while(1)
{
// Start single conversion
ADCSRA |= (1<<ADEN) | (1<<ADSC);
// Wait until conversion is in progress
while(ADCSRA & (1<<ADSC))
asm volatile("NOP");
// Not necessary you can only read ADCH
unsigned char ADC_LOW = ADCL; // Save ADC LOW value to variable
unsigned char ADC_HIGH = ADCH; // Save ADC HIGH value to variable
// Return ADC high value (MSB10:LSB2) to a PORT
PORTB = ADC_HIGH;
}
}
1条答案
按热度按时间pqwbnv8z1#
ADMUX=0x63
设置似乎是正确的。您正在从通道ADC3
阅读数据。ADCSRA
可以配置两种不同的模式。数据可以在轮询或中断时显示为红色,例如:轮询
中断控制
目前我没有平台来测试代码。