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

專注電子技術學習與研究
當前位置:單片機教程網 >> MCU設計實例 >> 瀏覽文章

基于51單片機AD0809八路AD采樣12864顯示

作者:hkxiaoma   來源:互聯網   點擊數:  更新時間:2014年07月29日   【字體:



#include<reg52.h>
#include

 

#define uchar unsigned char
#define uint unsigned int
//****端口定義*************************
sbit lcdrst=P3^3;
sbit lcdrs=P3^2;
sbit lcdrw=P3^1;
sbit lcde=P3^0;
//****端口定義*************************
sbit ST=P2^7;      //A/D啟動轉換信號
sbit OE=P2^5;      //數據輸出允許信號
sbit EOC=P2^6;     //A/D轉換結束信號
sbit CLK=P2^4;     //時鐘脈沖

sbit ADDA=P2^0;
sbit ADDB=P2^1;
sbit ADDC=P2^2;
//****顯示緩存定義*********************
uint  tabSambuffer[8]={0,0,0,0,0,0,0,0};
long  tempvalue=0;   //采集回來數據第一次處理
uint  value_V=0;
uchar diapbuffer[4]={0,10,0,0};
uchar code tab_zix[]={"0123456789.:"};

uchar code dis1[]={" CH0:    CH1:    "};
uchar code dis2[]={" CH2:    CH3:    "};
uchar code dis3[]={" CH4:    CH5:    "};
uchar code dis4[]={" CH6:    CH7:    "};
uchar  code dia11[]={">C"};    //當前數據跟新
uchar  code dia00[]={" C"};
uchar xh,cnt;
void longdelay(uchar t)
{
   uint j;
   for(;t>0;t--)
     {for(j=1000;j>0;j--);}
}
void shortdelay(uchar i)
{
  for(;i>0;i--);
}
//****讀狀態函數*************************
uchar readstatus(void)
{
   uchar i;
   P1=0xff;
   lcdrw=1;
   lcdrs=0;
   lcde=0;
   shortdelay(10);
   lcde=1;
   shortdelay(20);
   i=P1;
   shortdelay(40);
   lcde=0;
   return(i);
}
//****寫命令函數*************************
void lcdwriteinstruc(uchar instruction)
{
   while((readstatus()&0x80)!=0x00);
   P1=0;
   lcdrw=0;
   lcdrs=0;
   lcde=0;
   P1=instruction;
   shortdelay(100);
   lcde=1;
   shortdelay(100);
   lcde=0;
}
//****初始化LCD*************************
void initlcd(void)
{
   longdelay(40);
   lcdrst=0;
   longdelay(1);
   lcdrst=1;
   longdelay(1);   //復位LCD
   lcdwriteinstruc(0x30);
   longdelay(1);
   lcdwriteinstruc(0x30);
   longdelay(1);
   lcdwriteinstruc(0x0c);  //顯示開  游標關 游標位置反白
   longdelay(1);
   lcdwriteinstruc(0x01);
   longdelay(1);
   lcdwriteinstruc(0x06);  //增量方式 不移位
   longdelay(1);
}
//****寫一個字節函數*************************
void writeonebyte(uchar dat)
{
   while((readstatus()&0x80)!=0x00);
   P1=0;
   lcdrw=0;
   lcdrs=1;
   lcde=0;
   P1=dat;
   shortdelay(100);
   lcde=1;
   shortdelay(100);
   lcde=0;
}
//****顯示地址解析*************************
void disponeword(uchar x,uchar y)
{
  uchar dispaddr;
  switch(x)
  {
    case 0: dispaddr=0x80;break;
 case 1: dispaddr=0x90;break;
    case 2: dispaddr=0x88;break;
 case 3: dispaddr=0x98;break;
 default:break;
  }
  dispaddr=dispaddr+y;
  lcdwriteinstruc(dispaddr);
}
void Clear()
{
  //******************************************************************

        disponeword(0,0); 
      for(xh=0;xh<2;xh++)
      {
        writeonebyte(dia00[xh]);
     shortdelay(1);
     
         
         disponeword(1,0);
      for(xh=0;xh<2;xh++)
      {
        writeonebyte(dia00[xh]);
     shortdelay(1);
        

        disponeword(2,0); 
      for(xh=0;xh<2;xh++)
      {
        writeonebyte(dia00[xh]);
     shortdelay(1);
     
         
         disponeword(3,0);
      for(xh=0;xh<2;xh++)
      {
        writeonebyte(dia00[xh]);
     shortdelay(1);
        
     //******************************************************************
}
void main()
{
 initlcd();
//***********初始頁面顯示畫面*************************************
   disponeword(0,0);
   for(xh=0;xh<17;xh++)
   {
     writeonebyte(dis1[xh]);
  shortdelay(1);
   }

   disponeword(1,0);
   for(xh=0;xh<17;xh++)
   {
     writeonebyte(dis2[xh]);
  shortdelay(1);
   }

   disponeword(2,0);
   for(xh=0;xh<17;xh++)
   {
     writeonebyte(dis3[xh]);
  shortdelay(1);
   }

   disponeword(3,0);
   for(xh=0;xh<17;xh++)
   {
     writeonebyte(dis4[xh]);
  shortdelay(1);
   }//***********初始頁面顯示畫面***完*****************************
    TMOD=0X01;       //定時器中斷0
  CLK=0;        //脈沖信號初始值為0
  TH0=(65536-2)/256;     //定時時間高八位初值
  TL0=(65536-2)%6;     //定時時間低八位初值
  EA=1;        //開CPU中斷
  ET0=1;        //開T/C0中斷
  TR0=1;
   while(1)
   {
      Clear();     //清除當前行指示
    for(cnt=0;cnt<8;cnt++)
    {
     P2&=0xf0;
   P2|=cnt;       //設置采集通道
      ST=0;     //使采集信號為低
   shortdelay(2);
   ST=1;     //開始數據轉換
   shortdelay(2);
   ST=0;     //停止數據轉換
   longdelay(10);    //長延時
   //while(!EOC);   //等待數據轉換完畢
   OE=1;     //允許數據輸出信號
   shortdelay(1);
   tabSambuffer[cnt]=P0; //讀取數據
   shortdelay(1);
   OE=0;     //一次數據采集完成
   tempvalue=tabSambuffer[cnt];
   tempvalue=tempvalue*341/256;
   value_V=(uint)tempvalue;
   diapbuffer[0]=11;
   diapbuffer[1]=value_V/100;
   diapbuffer[2]=10;   //小數點     code tab_zix[]
   diapbuffer[3]=value_V0/10;
   switch(cnt)
   {
   case 0x00:disponeword(0,2); break;
   case 0x01:disponeword(0,6); break;
   case 0x02:disponeword(1,2); break;
   case 0x03:disponeword(1,6); break;
   case 0x04:disponeword(2,2); break;
   case 0x05:disponeword(2,6); break;
   case 0x06:disponeword(3,2); break;
   case 0x07:disponeword(3,6); break;
   }
     for(xh=0;xh<4;xh++)   //每次更新數據
    
       writeonebyte(tab_zix[diapbuffer[xh]]);
    shortdelay(1);
     }
     //******************************************************************
     if((cnt==0)|(cnt==1))//更新數據后指示當前行
     {
        disponeword(0,0); 
      for(xh=0;xh<2;xh++)
      {
        writeonebyte(dia11[xh]);
     shortdelay(1);
        
     }
     if((cnt==2)|(cnt==3))//更新數據后指示當前行
     {
         disponeword(1,0);
      for(xh=0;xh<2;xh++)
      {
        writeonebyte(dia11[xh]);
     shortdelay(1);
        
     }
     if((cnt==4)|(cnt==5))//更新數據后指示當前行
     {
        disponeword(2,0); 
      for(xh=0;xh<2;xh++)
      {
        writeonebyte(dia11[xh]);
     shortdelay(1);
        
     }
     if((cnt==6)|(cnt==7))//更新數據后指示當前行
     {
         disponeword(3,0);
      for(xh=0;xh<2;xh++)
      {
        writeonebyte(dia11[xh]);
     shortdelay(1);
        
     }
     //******************************************************************

   }
  
}
//***********產生AD采樣脈沖*******************************************
void timer0( ) interrupt 1    //定時器0工作方式1
{
  TH0=(65536-2)/256;     //重裝計數初值
  TL0=(65536-2)%6;     //重裝計數初值
  CLK=!CLK;         //取?
}

關閉窗口

相關文章