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

          新聞中心

          EEPW首頁(yè) > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > MSP430單片機(jī)AD轉(zhuǎn)換LCD1602&TUBE顯示

          MSP430單片機(jī)AD轉(zhuǎn)換LCD1602&TUBE顯示

          作者: 時(shí)間:2016-11-23 來(lái)源:網(wǎng)絡(luò) 收藏
          #include<msp430x14x.h>
          #define uint unsigned int
          #define uchar unsigned char
          #define ulint unsigned long int
          #define RS BIT0;
          #define RW BIT1;
          #define EN BIT2;
          uint Volt0; //設(shè)置電壓變量
          ulint Volttem0;
          unsigned data0=0,data1=0;
          uint ADresult0; //設(shè)置A/D轉(zhuǎn)換結(jié)果
          uint a[10]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};//數(shù)碼管不帶小數(shù)點(diǎn)譯碼
          uint b[10]={0x40,0x79,0x24,0x30,0x19,0x12,0x02,0x78,0x00,0x10};//數(shù)碼管帶小數(shù)點(diǎn)譯碼
          uchar c[]={"voltage:"};
          uchar *fu="V",*dian=".";
          uchar num[]={"0123456789"}; //電壓值尋址
          int value[4]={0,0,0,0}; //存放電壓 (v/1000)
          int counter=0; //計(jì)數(shù)分時(shí)顯示
          void lcd_init(); //初始化LCD
          void lcd_wcmd(uchar cmd); //寫(xiě)LCD指令
          void lcd_wdata(uchar data); //寫(xiě)LCD數(shù)據(jù)
          void lcd_pos(uchar pos); //設(shè)置LCD顯示位置
          void LED_SH();
          void LCD_SH();
          void Adcvolt(void) //進(jìn)行電壓轉(zhuǎn)換時(shí)ADC12的初始化
          {
          ADC12CTL0 &=~ENC; //ENC為低電平,設(shè)置AD控制寄存器
          ADC12CTL0 |=ADC12ON+MSC; //打開(kāi)ADC12,可以進(jìn)行AD轉(zhuǎn)換,參考電壓3.3V
          ADC12CTL1=CSTARTADD_0+CONSEQ_1+SHP;//單通道單次轉(zhuǎn)換,采樣頻率源自采樣定時(shí)器
          ADC12MCTL0=EOS+INCH_0; //選擇模擬輸入通道1
          ADC12IE |=BIT0; //AD轉(zhuǎn)換中斷允許
          ADC12CTL0 |=ENC; //轉(zhuǎn)換允許
          ADC12CTL0 |=ADC12SC; //開(kāi)始AD轉(zhuǎn)換
          }
          void Delay(uint n) //延時(shí)函數(shù)
          {
          uint i,j;
          for(i=n;i>0;i--)
          for(j=100;j>0;j--) ;
          }
          void lcd_init() //初始化LCD
          {
          lcd_wcmd(0x38);//16*2顯示、5*7顯示、8位數(shù)據(jù)顯示
          Delay(1);
          lcd_wcmd(0x0c);//顯示開(kāi),關(guān)光標(biāo)
          Delay(1);
          lcd_wcmd(0x06);//移動(dòng)光標(biāo)
          Delay(1);
          lcd_wcmd(0x01);//清除LCD現(xiàn)實(shí)的內(nèi)容
          Delay(1);
          }
          void lcd_wcmd(uchar cmd) //LCD寫(xiě)指令
          {
          P3OUT &=~RS;
          P3OUT &=~RW;
          P3OUT &=~EN;
          P4OUT=cmd;
          P3OUT |=EN;
          Delay(1);
          P3OUT &=~EN;
          }
          void lcd_pos(uchar pos) //設(shè)置顯示位置
          {
          lcd_wcmd(pos | 0x80);
          }
          void lcd_wdata(uchar data)//寫(xiě)入數(shù)據(jù)到LCD
          {
          P3OUT |=RS;
          P3OUT &=~RW;
          P3OUT &=~EN;
          P4OUT = data;
          P3OUT |=EN;
          P3OUT &=~EN;
          }
          void LED_SH() //LED_show
          {
          P2OUT |=BIT1+BIT3+BIT4;
          P4OUT=0xff;
          P5OUT=0x01; //選擇第一位數(shù)碼管
          P4OUT=b[value[0]]; //P4口顯示采樣值的個(gè)位
          Delay(3);
          P4OUT=0xff;
          P5OUT=0x02; //選擇第二位數(shù)碼管
          P4OUT=a[value[1]];//P4口顯示采樣值的第一位小數(shù)
          Delay(3);
          P4OUT=0xff;
          P5OUT=0x04; //選擇第三位數(shù)碼管
          P4OUT=a[value[2]];//P4顯示采樣值的第二位小數(shù)
          Delay(3);
          P4OUT=0xff;
          P5OUT=0x08; //選擇第四位數(shù)碼管
          P4OUT=a[value[3]];//P4顯示采樣值的第三位小數(shù)
          Delay(3);
          P4OUT=0xff;
          }
          void LCD_SH() //LCD_show
          {
          uint i;
          P2OUT &=~(BIT1+BIT3+BIT4);//turn off 74HC573
          lcd_init(); //初始化LCD,以下為L(zhǎng)CD顯示部分
          Delay(1);
          lcd_wcmd(0x06); //光標(biāo)右移
          lcd_pos(0); //設(shè)置顯示位置為第一行的第一個(gè)字符
          for(i=0;c[i]!=看屁屁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); })();