求指错ADC0804 电压显示在ks 0108的12864上显示

2019-07-15 17:27发布

QQ截图20150425154056.png

求指错ADC0804 电压显示在ks 0108的12864上显示,


#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
#define port P1 //DB0~DB7数据口
sbit e=P2^0;//使能
sbit rw=P2^1;//读写
sbit rs=P2^2;//数据/命令
sbit cs2=P2^3;//片选
sbit cs1=P2^4;
sbit busy=P1^7;//检测忙
#define date  P0
sbit cs=P2^5;    //片选信号,控制芯片的启动,低电平有效
sbit rd=P2^6;   //读数据控制,低电平有效
sbit rw1=P2^7;  //AD转换启动控制,上升沿有效
sbit intr=P3^3; //AD转换结束输出低电平

uchar code hz[][32]={




/*--空格--*/
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,        
  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},

/*--  文字:  电  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
{0x00,0x00,0xF8,0x88,0x88,0x88,0x88,0xFF,0x88,0x88,0x88,0x88,0xF8,0x00,0x00,0x00,
0x00,0x00,0x1F,0x08,0x08,0x08,0x08,0x7F,0x88,0x88,0x88,0x88,0x9F,0x80,0xF0,0x00},

/*--  文字:  压  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
{0x00,0x00,0xFE,0x02,0x82,0x82,0x82,0x82,0xFA,0x82,0x82,0x82,0x82,0x82,0x02,0x00,
0x80,0x60,0x1F,0x40,0x40,0x40,0x40,0x40,0x7F,0x40,0x40,0x44,0x58,0x40,0x40,0x00},


/*--空格--*/
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,        
  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},

/*--  文字:  力  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
{0x00,0x10,0x10,0x10,0x10,0x10,0xFF,0x10,0x10,0x10,0x10,0x10,0xF0,0x00,0x00,0x00,
0x00,0x80,0x40,0x20,0x18,0x06,0x01,0x00,0x20,0x40,0x80,0x40,0x3F,0x00,0x00,0x00},


/*--空格--*/
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,        
  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},

/*--  文字:  时  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
{0x00,0xFC,0x84,0x84,0x84,0xFC,0x00,0x10,0x10,0x10,0x10,0x10,0xFF,0x10,0x10,0x00,
0x00,0x3F,0x10,0x10,0x10,0x3F,0x00,0x00,0x01,0x06,0x40,0x80,0x7F,0x00,0x00,0x00},

/*--  文字:  间  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
{0x00,0xF8,0x01,0x06,0x00,0xF0,0x12,0x12,0x12,0xF2,0x02,0x02,0x02,0xFE,0x00,0x00,
0x00,0xFF,0x00,0x00,0x00,0x1F,0x11,0x11,0x11,0x1F,0x00,0x40,0x80,0x7F,0x00,0x00},

/*--空格--*/
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,        
  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},

};
uchar code num[][16]={
{0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00},
//"0",0

{0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00},
//"1",1

{0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00},
//"2",2

{0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00},
//"3",3

{0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00},
//"4",4

{0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00},
//"5",5

{0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00},
//"6",6

{0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00},
//"7",7

{0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00},
//"8",8

{0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x00} ,
//"9",9

/*--空格--*/
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},

/*--空格--*/
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},

/*--空格--*/
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},

/*--空格--*/
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},

/*--空格--*/
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},

/*--空格--*/
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},


};

//延时
void delay(uint n)
{
  uint i;
  for(;n>0;n--)
    for(i=200;i>0;i--);
}

//启动AD转换子程序
//void start_ad( )
//{
  //cs=0;          //允许进行A/D转换
  //rw1=0;
// delay(5);
// rw1=1; //WR由低变高时,AD开始转换
// while(intr);     //查询转换结束产生INTR 信号(低电平有效)
// cs=1;           //停止AD转换
//}
//读A/D数据子程序
//void read_ad( )
//{
//uint ad_data;
//cs=0;    //允许读
//rd=0;    //读取转换数据结果数据结果
//delay(2);
//ad_data=date;      //把数据存到ad_data中
// rd=1;cs=1;            //停止A/D读取
// return(ad_data);
//}
//数据处理
//void data_shout( )//观察0-5v的变化
//{
// uint a=20,one,two,three,four;

// four=ad_data/51; //第四位数码管(最高位)
//three=ad_data%51*10/51;//第三位数码管?
//two=ad_data%51*10%51*10/51;//第二位数码管?

//one=ad_data%51*10%51*10%51*10/51;//第一位数码管(最低位)
//}

//判断是否忙
void check()
{
    rs=0;  
rw=1;   //读 e=1;
port=0x00;
e=1;
while(busy);
e=0;
}
//写指令
void sendcommand(uchar command)
{
    check();
rs=0;  //指令
rw=0;  //写 e=0;
port=command;
e=1;
e=0; //写入指令
}
//写数据
void writedata(uchar dat)
{
    check();
rs=1;    //数据
rw=0;
port=dat;
e=1;
e=0;
}
//选屏幕 0--全屏,1--左屏,2--右屏;
void select(uint n)
{
    switch(n)
{
    case 0:cs1=0;cs2=0;break;   //低电平选中
       case 1:cs1=0;cs2=1;break;   //cs1左屏
    case 2:cs1=1;cs2=0;break;   //cs2右屏
}  
}
//页
void setpage(uchar page)
{
   page=page&0x07;
   page=page|0xb8;
   sendcommand(page);
}
//列
void setcolumn(uchar column)
{
   column=column&0x3f;
   column=column|0x40;
   sendcommand(column);
}
//起始行
void setline(uchar line)
{
    line=line&0x3f;
line=line|0xc0;
sendcommand(line);
}
//屏幕开关显示 0--关,1--开;
void seton(uint n)
{
   n=n|0x3e;
   sendcommand(n);
}
//清屏 0--全屏,1--左屏,2--右屏;
void clear(uint n)
{
   uchar i,j;
   select(n);
   for(i=0;i<8;i++)
   {
      setpage(i);
   setcolumn(0);
   for(j=0;j<64;j++)
     writedata(0);  //置0清空
   }
}
//初始化
void init(uchar i)
{
  check();

  seton(1);
  select(0);
  //clear(0);
  setline(i);
}
//显示汉字 16*16显示
void show16(uchar page,uchar column,uchar screen,uchar method,uchar *str)  //页,列,
{
  uchar i,j;
  select(screen);
  j=0;

  setpage(page);
  setcolumn(column);
  for(i=0;i<16;i++)
  {  if(method==1)   writedata(~str[j++]); //method为显示方式。当等于1时,反白。
     else            writedata(str[j++]);     
  }
  setpage(page+1);
  setcolumn(column);
  for(i=0;i<16;i++)
  {  if(method==1)   writedata(~str[j++]);
     else            writedata(str[j++]);     
  }
}
  //显示数字 8*16显示
void show8(uchar page,uchar column,uchar screen,uchar method,uchar *str)
{
  uchar i,j;
select(screen);j=0;

setpage(page);
setcolumn(column);
for(i=0;i<8;i++)
{  if(method==1)   writedata(~str[j++]);
     else            writedata(str[j++]);     
}
setpage(page+1);
setcolumn(column);
  for(i=0;i<8;i++)
  {  if(method==1)   writedata(~str[j++]);
     else            writedata(str[j++]);     
  }
}



void main()
{
uint  one,two,three,four;
uint ad_data;
while(intr);     //查询转换结束产生INTR 信号(低电平有效)
{cs=0;          //允许进行A/D转换
  rw1=0;
  delay(5);
  rw1=1; //WR由低变高时,AD开始转换

  cs=1;           //停止AD转换


  cs=0;    //允许读
  rd=0;    //读取转换数据结果数据结果
  delay(2);
  ad_data=date;      //把数据存到ad_data中
   rd=1;cs=1;            //停止A/D读取

  ad_data=ad_data*196;

four=ad_data/10000; //第四位数码管(最高位)
three=ad_data%10000/1000;//第三位数码管?
two=ad_data%1000/100;//第二位数码管?
one=ad_data%100/10;//第一位数码管(最低位)
}
init(0);
clear(0);
setline(0);
while(1)
{        uchar i,j;
  for(i=0;i<4;i++)
         {show16(0,16*i,1,0,hz);
    show16(0,16*i,2,0,hz[i+4]);
        }
        for(j=0;j<4;j++)
    {show8(2,8*j,1,0,num[four]);
    show8(2,8*j,1,0,num[three]);
        show8(2,8*j,1,0,num[two]);
        show8(2,8*j,1,0,num[one]);
          }
    delay(50000);
  }
}


友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。