51+LCD1602为什么第二行显示不了???

2019-03-24 17:59发布

51+LCD1602为什么第二行显示不了???[local]1[/local]
希望大家帮忙解决一下这个问题 此帖出自小平头技术问答
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
15条回答
njlianjian
2019-03-25 16:27
#include<sh88f516.h>
#include <stdio.h>
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned int
#define nop()  _nop_()

uchar bdata status;
sbit status_busy=status^7;
sbit status_Reset=status^4;

sbit  GXM1602_HD44780_E=P4^6;
sbit  GXM1602_HD44780_RW=P4^7;
sbit  GXM1602_HD44780_RS=P4^1;

void  GXM1602_HD44780_delay1ms(uint delay_xms);
void  GXM1602_HD44780_delay50us(uchar count50us);
void  GXM1602_HD44780_command(uchar command_data);
void  GXM1602_HD44780_data(uchar w_data);
void  GXM1602_HD44780_read_busy();
void  GXM1602_HD44780_initialize();

uchar  code  GXM1602_HD44780_dis_char[]={0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,
                                        };


//* delay  1ms  *//
void GXM1602_HD44780_delay1ms(uint delay_xms)
{
    uint data n,m;
   for(n=0;n<delay_xms;n++)
  {
    for(m=0;m<75;m++)
   {
     ;
      }
}
}
//***********delay50us************************//
void GXM1602_HD44780_delay50us(uchar count50us)
{
    uchar data k ;
     _nop_();
    for(k=0;k<2*count50us;k++)
    {

      _nop_();
      _nop_();
      _nop_();
      _nop_();
      _nop_();
      }
      }

//*********************************************
//向1602里面输入命令
//*********************************************
void GXM1602_HD44780_command(uchar command_data)
{        //RS=0;
         //RW=0;
         GXM1602_HD44780_E=0;
                 GXM1602_HD44780_RS=0;
         GXM1602_HD44780_RW=0;
         GXM1602_HD44780_E=1;
         P1=command_data;
         GXM1602_HD44780_delay1ms(0x02);
         _nop_();
         GXM1602_HD44780_E=0;
         GXM1602_HD44780_RS=1;
         GXM1602_HD44780_RW=1;
        }

//*********************************************
//向1602里面输入数据
//*********************************************
void GXM1602_HD44780_data(uchar w_data)

{
        GXM1602_HD44780_RS=1;
        GXM1602_HD44780_RW=0;
        GXM1602_HD44780_E=1;
        P1=w_data;
        GXM1602_HD44780_delay50us(0x02);
        _nop_();
        GXM1602_HD44780_E=0;
        GXM1602_HD44780_RS=0;
        GXM1602_HD44780_RW=1;
        }
//**********************************************
//1602读忙状态
//**********************************************
void  GXM1602_HD44780_read_busy()
{  
do
{
        GXM1602_HD44780_RS=0;
        GXM1602_HD44780_RW=1;
        GXM1602_HD44780_E=1;
        status=P1;
        GXM1602_HD44780_delay50us(0x02);
        GXM1602_HD44780_delay50us(0x02);
      }
        while(status_busy);
        _nop_();
        GXM1602_HD44780_E=0;
        GXM1602_HD44780_RS=0;
        GXM1602_HD44780_RW=1;
}

//***********************************************
//1602初始化状态
//***********************************************
void GXM1602_HD44780_initialize()
{
//  uchar data i;
      P1=0;

      GXM1602_HD44780_command(0x38);//N=1  2 line  diaplay    DL=1 8_bit bus mode whih MPU F=0 5*8 dots //
      GXM1602_HD44780_delay50us(0x02);
      GXM1602_HD44780_read_busy();
     

      GXM1602_HD44780_command(0x01);  /* CLR LCD AC=0 AC+1清屏 */
      GXM1602_HD44780_delay1ms(0x02);
      GXM1602_HD44780_read_busy();
      //write_command(0x8f); //

      GXM1602_HD44780_command(0x02);//归home位 set DDRAM Adress  is 00h //
      GXM1602_HD44780_delay1ms(0x02);
      GXM1602_HD44780_read_busy();


      GXM1602_HD44780_command(0x04);// 1 I/D S  I/D=0 cursor/blink moves to left and ddram address is decreased by 1 //
      GXM1602_HD44780_delay50us(0x02);
      GXM1602_HD44780_read_busy();

      GXM1602_HD44780_command(0x0c);//1DCB   D=1 entire display is turned on cursor off //cursor bink off   //
      GXM1602_HD44780_delay50us(0x02);
      GXM1602_HD44780_read_busy();

   //   GXM1602_HD44780_command(0x07);
   //   GXM1602_HD44780_delay50us(0x02);
   //   GXM1602_HD44780_read_busy();
     
      }



main()
   {
//   uchar data i,j;
    GXM1602_HD44780_initialize();


      while(1)
      {

   //   GXM1602_HD44780_command(0x40);   
   //   GXM1602_HD44780_delay50us(0x02);

        GXM1602_HD44780_command(0x80);
      GXM1602_HD44780_delay50us(0x01);
     GXM1602_HD44780_data(0x2b);
     GXM1602_HD44780_delay50us(0x01);

      GXM1602_HD44780_command(0x81);
      GXM1602_HD44780_delay50us(0x01);
     GXM1602_HD44780_data(0x34);
     GXM1602_HD44780_delay50us(0x01);

         GXM1602_HD44780_command(0x82);
      GXM1602_HD44780_delay50us(0x01);
     GXM1602_HD44780_data(0x30);
     GXM1602_HD44780_delay50us(0x01);

         GXM1602_HD44780_command(0x83);
      GXM1602_HD44780_delay50us(0x01);
     GXM1602_HD44780_data(0x2e);
     GXM1602_HD44780_delay50us(0x01);
   
        GXM1602_HD44780_command(0x84);
      GXM1602_HD44780_delay50us(0x01);
     GXM1602_HD44780_data(0x33);
     GXM1602_HD44780_delay50us(0x01);




      GXM1602_HD44780_command(0x86);
      GXM1602_HD44780_delay50us(0x01);
     GXM1602_HD44780_data(0x31);
     GXM1602_HD44780_delay50us(0x01);

         GXM1602_HD44780_command(0x87);
      GXM1602_HD44780_delay50us(0x01);
     GXM1602_HD44780_data(0x30);
     GXM1602_HD44780_delay50us(0x01);

         GXM1602_HD44780_command(0x88);
      GXM1602_HD44780_delay50us(0x01);
     GXM1602_HD44780_data(0x2e);
     GXM1602_HD44780_delay50us(0x01);

        GXM1602_HD44780_command(0x89);
      GXM1602_HD44780_delay50us(0x01);
     GXM1602_HD44780_data(0x32);
     GXM1602_HD44780_delay50us(0x01);

      GXM1602_HD44780_command(0x8a);
      GXM1602_HD44780_delay50us(0x01);
     GXM1602_HD44780_data(0x35);
     GXM1602_HD44780_delay50us(0x01);

         GXM1602_HD44780_command(0x8b);
      GXM1602_HD44780_delay50us(0x01);
     GXM1602_HD44780_data(0x38);
     GXM1602_HD44780_delay50us(0x01);

         GXM1602_HD44780_command(0x8d);
      GXM1602_HD44780_delay50us(0x01);
     GXM1602_HD44780_data(0x30);
     GXM1602_HD44780_delay50us(0x01);

         GXM1602_HD44780_command(0x8e);
      GXM1602_HD44780_delay50us(0x01);
     GXM1602_HD44780_data(0x34);
     GXM1602_HD44780_delay50us(0x01);

         GXM1602_HD44780_command(0x8f);
      GXM1602_HD44780_delay50us(0x01);
     GXM1602_HD44780_data(0x30);
     GXM1602_HD44780_delay50us(0x01);

         //////////////////////////////////////
                 GXM1602_HD44780_command(0xc0);
      GXM1602_HD44780_delay50us(0x01);
     GXM1602_HD44780_data(0x2b);
     GXM1602_HD44780_delay50us(0x01);

      GXM1602_HD44780_command(0xc1);
      GXM1602_HD44780_delay50us(0x01);
     GXM1602_HD44780_data(0x34);
     GXM1602_HD44780_delay50us(0x01);

         GXM1602_HD44780_command(0xc2);
      GXM1602_HD44780_delay50us(0x01);
     GXM1602_HD44780_data(0x30);
     GXM1602_HD44780_delay50us(0x01);

         GXM1602_HD44780_command(0xc3);
      GXM1602_HD44780_delay50us(0x01);
     GXM1602_HD44780_data(0x2e);
     GXM1602_HD44780_delay50us(0x01);
   
        GXM1602_HD44780_command(0xc4);
      GXM1602_HD44780_delay50us(0x01);
     GXM1602_HD44780_data(0x33);
     GXM1602_HD44780_delay50us(0x01);




      GXM1602_HD44780_command(0xc6);
      GXM1602_HD44780_delay50us(0x01);
     GXM1602_HD44780_data(0x31);
     GXM1602_HD44780_delay50us(0x01);

         GXM1602_HD44780_command(0xc7);
      GXM1602_HD44780_delay50us(0x01);
     GXM1602_HD44780_data(0x30);
     GXM1602_HD44780_delay50us(0x01);

         GXM1602_HD44780_command(0xc8);
      GXM1602_HD44780_delay50us(0x01);
     GXM1602_HD44780_data(0x2e);
     GXM1602_HD44780_delay50us(0x01);

        GXM1602_HD44780_command(0xc9);
      GXM1602_HD44780_delay50us(0x01);
     GXM1602_HD44780_data(0x32);
     GXM1602_HD44780_delay50us(0x01);

      GXM1602_HD44780_command(0xca);
      GXM1602_HD44780_delay50us(0x01);
     GXM1602_HD44780_data(0x35);
     GXM1602_HD44780_delay50us(0x01);

         GXM1602_HD44780_command(0xcb);
      GXM1602_HD44780_delay50us(0x01);
     GXM1602_HD44780_data(0x38);
     GXM1602_HD44780_delay50us(0x01);

         GXM1602_HD44780_command(0xcd);
      GXM1602_HD44780_delay50us(0x01);
     GXM1602_HD44780_data(0x30);
     GXM1602_HD44780_delay50us(0x01);

         GXM1602_HD44780_command(0xce);
      GXM1602_HD44780_delay50us(0x01);
     GXM1602_HD44780_data(0x34);
     GXM1602_HD44780_delay50us(0x01);

         GXM1602_HD44780_command(0xcf);
      GXM1602_HD44780_delay50us(0x01);
     GXM1602_HD44780_data(0x30);
     GXM1602_HD44780_delay50us(0x01);
        GXM1602_HD44780_delay1ms(1000);

       }
}

一周热门 更多>