今天搞了一下AD。原理图:
代码:
#include "delay.h"
#include "sys.h"
#include "uart.h"
#include "adc.h"
#include "led.h"
/********************************************************************************************************
**º¯ÊýÐÅÏ¢ £ºmain(void)
**¹¦ÄÜÃèÊö £º
**ÊäÈë²ÎÊý £º
**Êä³ö²ÎÊý £º
** ±¸×¢ £º
********************************************************************************************************/
int main(void)
{
u16 ADCVAL;
float fValue;
delay_init();
LED_Init();
uart_initwBaudRate(115200); //´®¿Ú³õʼ»¯Îª115200
/*ÅäÖÃADC1Ϊµ¥´Îת»»Ä£Ê½,ͨµÀ1ʹÄÜ*/
ADC1_SingleChannel( ADC_Channel_1);
while(1)
{
ADCVAL=Get_Adc_Average(ADC_Channel_1,5);
fValue = ((float)ADCVAL/4095)*3.3;
printf("ADC1_CH_1=%fV\r\n",fValue);
delay_ms(200);
}
}
效果图:
工程:
AD.rar
(342 KB)
|