標(biāo)題:
一個(gè)簡(jiǎn)單的C8051f單片機(jī)ADC應(yīng)用程序和測(cè)試
[打印本頁]
作者:
oldspring
時(shí)間:
2018-10-20 14:32
標(biāo)題:
一個(gè)簡(jiǎn)單的C8051f單片機(jī)ADC應(yīng)用程序和測(cè)試
以下是一個(gè)簡(jiǎn)單的8051單片機(jī)ADC應(yīng)用程序和測(cè)試:
unsigned int adc_result;
char txt[6];
void main() {
WDTCN = 0xDE; // Sequence for
WDTCN = 0xAD; // disabling the watchdog timer
OSCICN = 0x83; // Enable internal oscillator (24.5MHz divided by 1)
P0MDOUT |= 0x01; // Configure P0.0 (TX) pin as push-pull
UART2_Init(4800); // Initialize UART2
Delay_100ms();
P1MDIN.B2 = 0; // Configure P1.2 as Analog Input
ADC2_Init(); // Initialize ADC2 module
while (1) {
adc_result = ADC2_Get_Sample(2); // Read AIN2.2 (P1.2) analog input
WordToStr(adc_result, txt); // convert result to string
UART2_Write_Text(txt); // send string to UART
UART2_Write(13);UART2_Write(10); // send new line (CR+LF)
Delay_ms(500);
}
}
復(fù)制代碼
相關(guān)信息:
http://www.torrancerestoration.com/bbs/dpj-136722-1.html
ADC.jpg
(34.86 KB, 下載次數(shù): 43)
下載附件
2018-10-20 14:30 上傳
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1