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

QQ登錄

只需一步,快速開始

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

MSP430讀取ADC0832并LCD1602顯示

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:3721 發(fā)表于 2016-6-13 14:27 | 只看該作者 回帖獎(jiǎng)勵(lì) |倒序?yàn)g覽 |閱讀模式

#include "io430.h"

unsigned char tb1[]=" Power:";
unsigned char tb2[]="Volt";
unsigned char tb3[]="   low Power";
unsigned char tb4[]="   Power Full";
unsigned char tb5[]=" percent:";
///////////////////////////////////////////////////////////////////////
//      P1=dat; rs=P2.4,e=P2.5                 /////
//   ADC0832: CLK=P2.0;DI=P2.1;             ////
//      DO=P2.2;   CS=P2.3                         ////
/////////////////////////////////////////////////////////////////////   

void w1602(unsigned char t,unsigned char dat)
{
  char n;
  if(t==0)
    P2OUT &=~BIT4;
  else
    P2OUT |=BIT4;
  P1OUT =dat;
  P2OUT &=~BIT5;
  n=5;
  while(n--);
  P2OUT |=BIT5;
  n=10;
  while(n--);
  P2OUT &=~BIT5;  
}
unsigned char rADC0832()
{
  unsigned char temp=0,k;

  P2OUT |=BIT3;
   __no_operation();
  P2OUT &=~BIT3;  //start

  P2OUT &=~BIT0;
  __no_operation();
  P2OUT |=BIT1;
  __no_operation();
  P2OUT |=BIT0;
  __no_operation();//DI=1
  P2OUT &=~BIT0;

  __no_operation();
  P2OUT |=BIT0;
  __no_operation(); //DI=1
  P2OUT &=~BIT0;

  P2OUT &=~BIT1;
  __no_operation();
  P2OUT |=BIT0;
  __no_operation(); //DI=1
  P2OUT &=~BIT0;

  __no_operation();
  P2OUT |=BIT0;
  __no_operation(); //DI=1
  P2OUT &=~BIT0;

  for(k=0;k<8;k++)
  {
     temp=temp<<1;
     P2OUT |=BIT0;
     if(P2IN & BIT2)temp |=0x01;
     P2OUT &=~BIT0;
  }
  return temp;   
}
void init1602()
{
  w1602(0,0x38);
  w1602(0,0x06);
  w1602(0,0x0c);
  w1602(0,0x01);

}
int main( void )
{
  // Stop watchdog timer to prevent time out reset
  WDTCTL = WDTPW + WDTHOLD;
  unsigned int d,d1,dd;
  P1DIR =0xff;
  P2DIR =0x3B;
  //P2REN |=BIT2;
  P2OUT |=BIT2;
  init1602();
  while(1)
  {

        d=196 * rADC0832();//25000(3V=153(29988) 3.7=189(37)
        dd=100*(rADC0832()-153)/36;  
      ////////////////////////////  
        w1602(0,0x80);
        for(d1=0;d1<7;d1++)
          w1602(1,tb1[d1]);
        w1602(1,(d/10000)+0x30);
        w1602(1,0x2E);
        w1602(1,(d%10000)/1000+0x30);
        w1602(1,((d%10000)%1000)/100+0x30);
        for(d1=0;d1<4;d1++)
          w1602(1,tb2[d1]);
        w1602(1,0x20);
        w1602(1,0x20);
        ///////////////////////////
        w1602(0,0xc0);
        if(d<29988)
           {   
                for(d1=0;d1<12;d1++)
                w1602(1,tb3[d1]);
                w1602(1,0x20);
                w1602(1,0x20);
                w1602(1,0x20);
                w1602(1,0x20);
           }
        else
           {
             if(d>37044)
                 {
                   for(d1=0;d1<13;d1++)
                       w1602(1,tb4[d1]);
                   w1602(1,0x20);
                   w1602(1,0x20);
                   w1602(1,0x20);
                 }
             else
                 {
                   for(d1=0;d1<9;d1++)
                       w1602(1,tb5[d1]);
                   if((dd/10)==0)
                     w1602(1,0x20);
                   else
                      w1602(1,dd/10+0x30);
                   w1602(1,dd%10+0x30);
                   w1602(1,0x25);
                   w1602(1,0x20);
                   w1602(1,0x20);
                   w1602(1,0x20);
                   w1602(1,0x20);
               }        
           }

  }  
}


ADC0832的時(shí)序圖詳解:http://www.torrancerestoration.com/bbs/dpj-51688-1.html

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

使用道具 舉報(bào)

本版積分規(guī)則

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

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

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