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

          新聞中心

          EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計應(yīng)用 > MSP430采集電壓信號程序

          MSP430采集電壓信號程序

          作者: 時間:2016-11-24 來源:網(wǎng)絡(luò) 收藏






          //***************************************************

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

          //功能介紹:對P6.0口電壓進行采集 液晶顯示

          //****************************************************
          #include <msp430x14x.h>
          #include "BoardConfig.h"
          #include "cry1602.h"

          #define Num_of_Results 32

          uchar shuzi[] = {"0123456789.+"};
          uchar tishi[] = {"The Volt is:"};

          static uint results[Num_of_Results]; //保存ADC轉(zhuǎn)換結(jié)果的數(shù)組 // is not used for anything.
          void Trans_val(uint Hex_Val);


          void main(void)
          {
          WDTCTL = WDTPW+WDTHOLD; //關(guān)閉看門狗
          BoardConfig(0xb8); //關(guān)閉數(shù)碼管、流水燈、4245
          LcdReset(); //復(fù)位1602液晶
          DispNChar(2,0,12,tishi); //顯示提示信息
          Disp1Char(11,1,V); //顯示電壓單位
          P6SEL |= 0x01; // 使能ADC通道
          ADC12CTL0 = ADC12ON+SHT0_8+MSC; // 打開ADC,設(shè)置采樣時間
          ADC12CTL1 = SHP+CONSEQ_2; // 使用采樣定時器,單路重復(fù)采集
          ADC12IE = 0x01; // 使能ADC中斷
          ADC12CTL0 |= ENC; // 使能轉(zhuǎn)換
          ADC12CTL0 |= ADC12SC; // 開始轉(zhuǎn)換
          _EINT(); //使能中斷
          LPM0; //低功耗模式
          }


          #pragma vector=ADC_VECTOR
          __interrupt void ADC12ISR (void)
          {
          static uint index = 0;

          results[index++] = ADC12MEM0; // Move results
          if(index == Num_of_Results)
          {
          uchar i;
          unsigned long sum = 0;

          index = 0;
          for(i = 0; i < Num_of_Results; i++)
          {
          sum += results[i];
          }
          sum >>= 5; //除以32
          sum=(sum<<4)+(sum<<2)+sum; //增大21倍原因是大電壓變?yōu)樾‰妷翰杉?br /> Trans_val(sum);
          }
          }


          void Trans_val(uint Hex_Val)
          {
          unsigned long caltmp;
          uint Curr_Volt;
          uchar t1,i;
          uchar ptr[6];

          caltmp = Hex_Val;
          caltmp = (caltmp << 5) + Hex_Val; //caltmp = Hex_Val * 33 擴大10倍便于計算
          caltmp = (caltmp << 3) + (caltmp << 1); //caltmp = caltmp * 10 擴大10倍便于計算
          Curr_Volt = caltmp >> 12; //Curr_Volt = caltmp / 2^n
          ptr[0] = 11; //數(shù)字表中第11位對應(yīng)符號"+"
          ptr[1] = Curr_Volt / 1000; //相當(dāng)于十位上的數(shù)值
          ptr[2] = (Curr_Volt%1000) / 100; //相當(dāng)于個位上的數(shù)值
          t1 = Curr_Volt - (ptr[1] * 1000)-(ptr[2] * 100);
          ptr[4] = t1 / 10; //相當(dāng)于小數(shù)點后第一位
          ptr[5] = t1 - (ptr[4] * 10); //相當(dāng)于小數(shù)點后第二位
          ptr[3] = 10; //數(shù)字表中第10位對應(yīng)符號"."
          //在液晶上顯示變換后的結(jié)果
          for(i = 0;i < 6;i++)
          Disp1Char((4 + i),1,shuzi[ptr[i]]);
          }



          關(guān)鍵詞: MSP430采集電壓信

          評論


          技術(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); })();