<meter id="pryje"><nav id="pryje"><delect id="pryje"></delect></nav></meter>
          <label id="pryje"></label>

          新聞中心

          EEPW首頁(yè) > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > 單片機(jī)STC12C5A60S2內(nèi)部10位AD程序

          單片機(jī)STC12C5A60S2內(nèi)部10位AD程序

          作者: 時(shí)間:2016-11-23 來(lái)源:網(wǎng)絡(luò) 收藏
          #include

          #include

          本文引用地址:http://www.ex-cimer.com/article/201611/320512.htm

          #define uint unsigned int
          #define uchar unsigned char

          sfr P1ASF = 0X9D; //P1口選擇功能寄存器
          sfr ADC_CONTR = 0XBC; //ADC控制寄存器
          sfr ADC_RES = 0XBD; //ADC轉(zhuǎn)換結(jié)果寄存器高
          sfr ADC_RESL = 0XBE; //ADC轉(zhuǎn)換結(jié)果寄存器低
          sfr AUXR1 = 0XA2; //ADC轉(zhuǎn)換結(jié)果調(diào)整位
          //sfr IE = 0XA8; //ADC中斷允許寄存器
          //sfr IP = 0XB8; //ADC中斷優(yōu)先級(jí)控制寄存器高
          //sfr IPH = 0XB7; //ADC中斷優(yōu)先級(jí)控制寄存器低

          uint ADC_Result1, ADC_Result2, ADC_Result;

          void ADC_init(void); //AD轉(zhuǎn)換初始化
          void Delay(uint z); //延時(shí)函數(shù)

          void main(void)
          {
          uint gei, shi, bai, qian;
          uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};

          while (1)
          {
          ADC_init();
          ADC_Result = ADC_Result2 + ADC_Result1 * 256;
          gei = ADC_Result % 10;
          shi = ADC_Result / 10 % 10;
          bai = ADC_Result / 100 % 10;
          qian = ADC_Result / 1000;
          //數(shù)碼管動(dòng)態(tài)顯示顯示采集數(shù)值
          P2 = 1;
          P0 = table[qian];
          Delay(5);
          P2 = 2;
          P0 = table[bai];
          Delay(5);
          P2 = 3;
          P0 = table[shi];
          Delay(5);
          P2 = 4;
          P0 = table[gei];
          Delay(5);
          }
          }

          void ADC_init(void) //AD轉(zhuǎn)換初始化
          {
          P1ASF = 0X01; //X選擇P1.0作為ADC轉(zhuǎn)換輸入通道
          ADC_CONTR = 0X80; //打開ADC轉(zhuǎn)換電源
          _nop_();
          _nop_();

          AUXR1 = 0X04; //將高兩位存放在寄存器ADC_RES,低八位存放在寄存器ADC_RESL中
          ADC_CONTR |= 0X68; //ADC初始化設(shè)置
          _nop_();
          _nop_();
          _nop_();
          _nop_ ();

          ADC_Result1 = ADC_RES;
          ADC_Result2 = ADC_RESL;

          }
          void Delay(uint z) //延時(shí)函數(shù)
          {
          uint x, y;
          for (x = 0; x < z; x++)
          for (y = 0; y < 140; y++);
          }



          關(guān)鍵詞: 單片機(jī)STC12C5A60S2AD程

          評(píng)論


          技術(shù)專區(qū)

          關(guān)閉
          看屁屁www成人影院,亚洲人妻成人图片,亚洲精品成人午夜在线,日韩在线 欧美成人 (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })();