按键控制键值在lcd1602上显示,为什么在LCD1602液晶上无法显示?

2019-07-15 08:09发布

这是按键控制键值在lcd1602上显示,为什么在LCD1602液晶上无法显示
#include<reg51.h>
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int
#define out P0
sbit RS=P2^6;
sbit RW=P2^5;
sbit E=P2^7;
sbit L1=P1^0;
sbit L2=P1^1;
sbit L3=P1^2;
sbit L4=P1^3;
uchar dat[16]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};
void lcd_initial(void);
void check_busy(void);
void write_command(uchar com);
void write_data(uchar dat);
void string(uchar ad,uchar *s);
void delay(uint);

main()
{
uchar temp;
uchar i;
uchar j;
while(1)  
{
  P1=0xef;
  for(i=0;i<=3;i++)
  {
   if(L1==0) P0=dat[i*4+0];
   if(L2==0) P0=dat[i*4+1];
   if(L3==0) P0=dat[i*4+2];
   if(L4==0) P0=dat[i*4+3];
   delay(500);
   temp=P1;
   temp=temp | 0x0f;
   temp=temp <<1;
   temp=temp | 0x0f;
   P1=temp;
  }
  for(j=1;j<=16;j++)
  {
  lcd_initial();
  if(P0==dat[1])
  {
  string(0x85,"frequency");
  string(0xc3,"0");
  }
  else if(P0==dat[2])
  {
  string(0x85,"phase");
  string(0xc3,"1");
  }
  else if(P0==dat[3])
  {
  string(0x85,"amplitude");
  string(0xc3,"2");
  }
  else if(P0==dat[4]) string(0xc3,"3");
  else if(P0==dat[5]) string(0xc3,"4");
  else if(P0==dat[6]) string(0xc3,"5");
  else if(P0==dat[7]) string(0xc3,"6");
  else if(P0==dat[8]) string(0xc3,"7");
  else if(P0==dat[9]) string(0xc3,"8");
  else if(P0==dat[10]) string(0xc3,"9");
  else if(P0==dat[11]) string(0xc3,"A");
  else if(P0==dat[12]) string(0xc3,"B");
  else if(P0==dat[13]) string(0xc3,"C");
  else if(P0==dat[14]) string(0xc3,"D");
  else if(P0==dat[15]) string(0xc3,"E");
  else if(P0==dat[16]) string(0xc3,"F");
}   
}
}


void delay(uint j)
{
  uchar i=250;
for(;j>0;j--)
{
  while(--i);
  i=249;
  while(--i);
  i=250;
}
}
/*******************************************************************************
* 函 数 名       : check-busy
* 函数功能   : 检查忙标志函数
* 输    入       : 无
* 输    出       : 无
*******************************************************************************/
void  check_busy(void)
{
uchar dt;
do
{
  dt=0xff;
   E=0;
   RS=0;
   RW=1;
   E=1;
  dt=out;
}while(dt&0x80);
  E=0;
}
/*******************************************************************************
* 函 数 名       : LcdWriteCom
* 函数功能   : 写命令函数
* 输    入       : 无
* 输    出       : 无
*******************************************************************************/
void  write_command(uchar com)
{
check_busy();
   E=0;
   RS=0;
   RW=0;
  out=com;
   E=1;
  delay(5);
E=0;
}
void write_data(uchar dat)
{
check_busy();
   E=0;
   RS=1;
   RW=0;
  out=dat;
   E=1;
  delay(5);
E=0;
}
/*******************************************************************************
* 函 数 名       : LcdInit()
* 函数功能   : 初始化LCD屏
* 输    入       : 无
* 输    出       : 无
*******************************************************************************/     
void lcd_initial()        //LCD初始化
{
write_command(0x38);
write_command(0x0C);
write_command(0x06);
write_command(0x01);
delay(1);
}
  void string(uchar ad,uchar *s)
  {
   write_command(ad);
   while(*s>0)
  {
   write_data(*s++);
delay(100);
   }
  }

0条回答

一周热门 更多>