找回密碼
 立即注冊(cè)

QQ登錄

只需一步,快速開(kāi)始

搜索
查看: 4635|回復(fù): 0
打印 上一主題 下一主題
收起左側(cè)

一個(gè)簡(jiǎn)單的C8051f單片機(jī)ADC應(yīng)用程序和測(cè)試

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:406093 發(fā)表于 2018-10-20 14:32 | 只看該作者 |只看大圖 回帖獎(jiǎng)勵(lì) |倒序?yàn)g覽 |閱讀模式
以下是一個(gè)簡(jiǎn)單的8051單片機(jī)ADC應(yīng)用程序和測(cè)試:

  1. unsigned int adc_result;
  2. char txt[6];

  3. void main() {

  4.   WDTCN    = 0xDE;                   // Sequence for
  5.   WDTCN    = 0xAD;                   //   disabling the watchdog timer
  6.   OSCICN   = 0x83;                   // Enable internal oscillator (24.5MHz divided by 1)
  7.   P0MDOUT |= 0x01;                   // Configure P0.0 (TX) pin as push-pull

  8.   UART2_Init(4800);                  // Initialize UART2
  9.   Delay_100ms();

  10.   P1MDIN.B2 = 0;                     // Configure P1.2 as Analog Input
  11.   ADC2_Init();                       // Initialize ADC2 module

  12.   while (1) {
  13.     adc_result = ADC2_Get_Sample(2); // Read AIN2.2 (P1.2) analog input
  14.     WordToStr(adc_result, txt);      // convert result to string
  15.     UART2_Write_Text(txt);           // send string to UART
  16.     UART2_Write(13);UART2_Write(10); // send new line (CR+LF)
  17.     Delay_ms(500);
  18.   }
  19. }
復(fù)制代碼
相關(guān)信息:http://www.torrancerestoration.com/bbs/dpj-136722-1.html



分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏2 分享淘帖 頂 踩
回復(fù)

使用道具 舉報(bào)

本版積分規(guī)則

手機(jī)版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表