编译没有错误 烧录进单片机 LCD1602一直显示A 不知道怎么办

LCD1602头文件
```#ifndef LCD1602_H

#include

 #define _LCD1602_H_

 #define LCD1602_A P0

   sbit RS = P3^5;
   sbit RW = P3^6;
 sbit EN = P3^4;

  typedef unsigned char uchar;
typedef unsigned char uint;

   void delay_ms(uint n);
     void Dis_onechar(uchar x,uchar y,uchar dat);
     void Dis_str(uchar x,uchar y,uchar *str);
     void Init_LCD1602();
     void Read_busy();
     void Write_cmd(uchar cmd);
     void Write_dat(uchar dat);
     void clear_LCD1602();

#endif 
LCD1602程序

```#include "LCD1602.h"


void delay_ms(uint n) 
{ 
uint i,y; 
for(i=n;i>0;i--) 
    {
  for(y=114;y>0;y--);
    }       
}


// º¯ÊýÃû£ºÅÐ溯Êý
// º¯Êý¹¦ÄÜ£ºÅжÏÒº¾§ÊÇ·ñ·±Ã¦
void Read_busy()
{
   uchar busy;
     LCD1602_A = 0xff;
     RS = 0;
     RW = 1;
    do{
       EN = 1;
         busy = LCD1602_A;
         EN = 0;//À­µÍʹÄÜ¶Ë ±ãÓÚÏ´ÎʹÓÃ
    }while(busy & 0x80);//²»ÎªÁã¾ÍÒ»Ö±Ö´ÐÐ
}
//º¯ÊýÃû³Æ£ºÐ´ÃüÁî
//º¯Êý¹¦ÄÜ£ºÏòLCDÖÐдÈëÃüÁî
void Write_cmd(uchar cmd)
  {
    Read_busy();
      RS = 0;
        RW = 0;
        LCD1602_A = cmd;
        EN = 1;
        EN = 0;
}
//º¯ÊýÃû³Æ£ºÐ´Êý¾Ý
//º¯Êý¹¦ÄÜ£ºÏòLCDÖÐдÈëÊý¾Ý
void Write_dat(uchar dat)
{
  Read_busy();
    RS = 1;
    RW = 0;
    LCD1602_A = dat;
    EN = 1;
    EN = 0;
}
//º¯ÊýÃû³Æ£ºÏÔʾһ¸ö×Ö·û
//º¯Êý¹¦ÄÜ£ºÔÚÖ¸¶¨µÄλÖÃÏÔʾһ¸ö×Ö·û
void Dis_onechar(uchar x, uchar y, uchar dat)
{
   if(y) x |= 0x40;
       x |= 0x80;
    Write_cmd(x);
    Write_dat(dat);
}
//º¯ÊýÃû³Æ£ºÏÔʾһ¸ö×Ö·û´®
//º¯Êý¹¦ÄÜ£ºÁ¬ÐøµÄÏÔʾ×Ö·û
void Dis_str(uchar x, uchar y, uchar *str)//strÊÇÖ¸Õë±äÁ¿(µØÖ·)*strÊÇÖ¸Õë»òµØÖ·ÀïµÄÄÚÈÝ
{
   if(y) x |= 0x40;
        x |= 0x80;
     Write_cmd(x);
     while(*str != '\0')
     {
        Write_dat(*str++);//Ö¸ÏòÏÂÒ»¸öµØÖ· µÄÄÚÈÝ
     }
}
//º¯ÊýÃû³Æ£ºLCD³õʼ»¯
//º¯Êý¹¦ÄÜ£º³õʼ»¯LCD
void Init_LCD1602()
{
   Write_cmd(0x38);//ÉèÖÃÏÔʾģʽ
     Write_cmd(0x0c);// ¿ªÏÔʾ ÏÔʾ¹â±ê ¹â±ê²»ÉÁ
     Write_cmd(0x06);//µØÖ·Ö¸Õë¼ÓÒ» ¹â±ê¼ÓÒ»
     Write_cmd(0x01);//ÇåÆÁ
}
void clear_LCD1602()
{
    Write_cmd(0x01);
}

矩阵键盘的程序

#include "LCD1602.h"

uchar str[] = {"0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F,G,H,J,K,L"};


//º¯ÊýÃû£ºÉ¨Ã躯Ê
//º¯Êý¹¦ÄÜ£ºÅжÏ20¸ö°´¼üÄǸö±»°´ÏÂÁË
uchar Keyscan()
{
    uchar dat_l,dat_h;//l ÐÐ h ÁÐ
    P3 = 0xf0;// 1111 0000 ¸ßλÊÇÁÐ µÍλÊÇÐÐ
    if((P3 & 0xf0)!= 0xf0)
    {
        delay_ms(10);
        if((P3 & 0xf0) != 0xf0)
        {
           dat_l = P3 & 0xf0;//´¢´æÁеÄÖµ ¸ßËÄλ µÍËÄλʼÖÕΪÁã
             P3 = P3 | 0x0f;//µÍËÄλȫΪһ ÅжÏÄÄÒ»ÐÐ
             dat_h = P3 & 0x0f;// ¸ßËÄλΪ0 µÍËÄλΪÐÐÖµ ´¢´æÐÐÖµ
            while((P3 & 0x0f) != 0x0f)//Åжϰ´¼üÊÇ·ñËÉ¿ª ²»³ÉÁ¢Ìø³öÑ­»·
                return(dat_l+dat_h);//·µ»Ø¼üÂëÖµ
            }
    }
}
//º¯ÊýÃû³Æ£»Êä³öº¯Êý
//º¯Êý¹¦ÄÜ£»Êä³öÿ¸ö¼üËù´ú±íµÄÊý×Ö
uchar keypro()
{

      switch(Keyscan())
            {
                //µÚÒ»ÐмüÅÌ
                case 0xee: return 0;  break;
              case 0xde: return 1;  break;
                case 0xbe: return 2;  break;
                case 0x7e: return 3;  break;
                //µÚ¶þÐмüÅÌ
                case 0xed: return 4;  break;
                case 0xdd: return 5;  break;
                case 0xbd: return 6;  break;
                case 0x7d: return 7;  break;
                //µÚÈýÐмüÅÌ
                case 0xeb: return 8;  break;
                case 0xdb: return 9;  break;
                case 0xbb: return 10; break;
                case 0x7b: return 11; break;
                //µÚËÄÐмüÅÌ
                case 0xe7: return 12; break;
                case 0xd7: return 13; break;
                case 0xb7: return 14; break;
                case 0x77: return 15; break;

                //¶ÀÁ¢¼üÅÌ
                case 0xfe: return 16; break;
                case 0xfd: return 17; break;
                case 0xfb: return 18; break;
                case 0xf7: return 19; break;
            default: return 20;break;
            }
}
void main()
{
    uchar num;

    while(1)
    {

        Init_LCD1602();
        num = keypro();
        //clear_LCD1602();
      Dis_onechar(2,0,str[num]); 
        delay_ms(10);
    }
}
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问