LCD1602显示

2019-07-14 20:27发布

   我在郭天祥的单片机板子上面用了下面的代码,液晶显示1602就不显示了呢?
其他引脚的功能我没有变化,只是把RS,RW,EN分别插到引脚P1.0,P1.1,P1.2。望哪位大神帮忙解答一下,
在此谢谢!

  1. #include<reg52.h>
  2. #define uchar unsigned char
  3. #define uint unsigned int

  4. #define Lcd_DB P0
  5. sbit Lcd_RS = P1^0;
  6. sbit Lcd_RW = P1^1;
  7. sbit Lcd_EN = P1^2;
  8. sbit dula = P2^6;
  9. sbit wela = P2^7;

  10. void InitLcd1602();
  11. void LcdShowStr(unsigned char x, unsigned char y, unsigned char *str);

  12. void main()
  13. {
  14.         wela = 0;
  15.         dula = 0;
  16.         InitLcd1602();
  17.         LcdShowStr(2,0,"UESTC.COM");
  18.         LcdShowStr(0,1,"WELCOME TO UESTC");
  19.         while(1);
  20. }

  21. void LcdWaitReady()
  22. {
  23.         unsigned char sta;

  24.         Lcd_DB = 0xff;
  25.         Lcd_RS = 0;
  26.         Lcd_RW = 1;       

  27.         do{
  28.                 Lcd_EN = 1;
  29.                 sta = Lcd_DB;
  30.                 Lcd_EN = 0;
  31.         }while(sta&0x80);
  32. }

  33. void LcdWriteCmd(unsigned char cmd)
  34. {
  35.         LcdWaitReady();
  36.         Lcd_RS = 0;
  37.         Lcd_RW = 0;
  38.         Lcd_DB = cmd;
  39.         Lcd_EN = 1;
  40.         Lcd_EN = 0;
  41. }

  42. void InitLcd1602()
  43. {
  44.         LcdWriteCmd(0x38);
  45.         LcdWriteCmd(0x0C);
  46.         LcdWriteCmd(0x06);
  47.         LcdWriteCmd(0x01);
  48. }

  49. void LcdShowCursor(unsigned char x, unsigned char y)
  50. {
  51.         unsigned char addr;
  52.         if(0==y)
  53.         {
  54.                 addr = 0x00 + x;
  55.         }
  56.         else
  57.                 addr = 0x40 + x;

  58.         LcdWriteCmd(addr | 0x80);
  59. }

  60. void LcdWriteDat(unsigned char dat)
  61. {
  62.         LcdWaitReady();
  63.         Lcd_RS = 1;
  64.         Lcd_RW = 0;
  65.         Lcd_DB = dat;
  66.         Lcd_EN = 1;
  67.         Lcd_EN = 0;
  68. }

  69. void LcdShowStr(unsigned char x, unsigned char y, unsigned char *str)
  70. {
  71.         LcdShowCursor(x,y);
  72.        
  73.         while(*str != '')
  74.         {
  75.                 LcdWriteDat(*str++);
  76.         }
  77. }
复制代码


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