📄 main.c
字号:
/************************************************
文件:main.c
用途:
注意:内部8M晶振
创建:2008.4.1
修改:2008.4.1
Copy Right (c) www.avrvi.com AVR与虚拟仪器
************************************************/
#include "config.h"
float adc_result;
void adc_init(void)
{
ADCSRA = 0x00; //disable adc
ADMUX = (1<<REFS0)|(1<<ADLAR);
ACSR = (1<<ACD);
ADCSRA = (1<<ADEN);
}
void get_adc(unsigned adc_channel)
{
unsigned int value=0,i;
adc_init();
ADMUX += adc_channel;
for(i=0;i<4;i++)
{
ADCSRA |= (1<<ADSC);
delay_nus(100);
value += ADCH;
}
value >>= 2;
adc_result=(value*4.97)/256;
}
void main(void)
{
unsigned char *adc_str="The adc result of channel 0 is : 2.031 V\n\n",i=0;
CLI();
Com_init();
SEI();
while(1)
{
get_adc(i);
adc_str[26]=i+0x30;
adc_result *= 1000;
adc_str[33]=(unsigned int)adc_result/1000+0x30;
adc_str[35]=((unsigned int)adc_result%1000)/100+0x30;
adc_str[36]=((unsigned int)adc_result%100)/10+0x30;
adc_str[37]=(unsigned int)adc_result%10+0x30;
Com_putstring (adc_str,41,&RTbuf_UART0);
i++;
if(i>1) i=0;
delay_nms(300);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -