欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 5169|回復: 0
收起左側

MSP430讀取ADC0832并LCD1602顯示

[復制鏈接]
ID:3721 發表于 2016-6-13 14:27 | 顯示全部樓層 |閱讀模式

#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的時序圖詳解:http://www.raoushi.com/bbs/dpj-51688-1.html

回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規則

小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網

快速回復 返回頂部 返回列表