LCD1602清屏问题

2019-07-15 09:23发布

以下是我编写的程序,这个程序能够显示wlecom to和I LOVE MCU,但之后显示的就是乱码了,屏幕没有清屏,而且之后的显示不是从指定位开始的,论坛的大神们麻烦给点意见
LCD显示情况 QQ截图20171106131851.png
#include<reg51.h>
#include<intrins.h>
typedef unsigned char BYTE;
typedef bit  BOOL;

sbit LCD_RS=P2^6;
sbit LCD_RW=P2^5;
sbit LCDE=P2^7;

BYTE code dis1[] = {"   WELCOME  TO   "};
BYTE code dis2[] = {"I LONE MCU  "};
BYTE code dis3[] = {"   OT  EMOCLEW   "};
BYTE code dis4[] = {" UCM EVOL I  "};



delay(int ms)
{
        int i;
        while(ms--)
        {
                for(i=0;i<250;i++)
                {
                        _nop_();
                        _nop_();
                        _nop_();
                        _nop_();
                }
        }

}

BOOL LCD_bz()
{
        BOOL result;
        LCD_RS=0;
        LCD_RW=1;
        LCDE=1;
        _nop_();
        _nop_();
        _nop_();
        _nop_();
        result=(BOOL)(P0&0x80);
        LCDE=0;
        return result;
               
}

LCD_wcmd(BYTE cmd)

{
        while(LCD_bz())        ;
        LCD_RS=0;
        LCD_RW=0;
        LCDE=0;
           _nop_();
        _nop_();
        P0=cmd;
        _nop_();
        _nop_();
        _nop_();
        _nop_();
        LCDE=1;
        _nop_();
        _nop_();
        _nop_();
        _nop_();
        LCDE=0;


}

LCD_pos(BYTE pos)
{
        LCD_wcmd(pos|0x80);

}

LCD_wdat(BYTE dat)
{
        while(LCD_bz());
        LCD_RS=1;
        LCD_RW=0;
        LCDE=0;
        P0=dat;
        _nop_();
        _nop_();
        _nop_();
        _nop_();
        LCDE=1;
        _nop_();
        _nop_();
        _nop_();
        _nop_();
        LCDE=0;
}

void init()

{
        LCD_wcmd(0x38);
        delay(1);
        LCD_wcmd(0x0c);
        delay(1);
        LCD_wcmd(0x06);
        delay(1);
        LCD_wcmd(0x01);
        delay(1);

               
}

main()
{
        BYTE i;
        init();
        delay(10);

        while(1)
        {
                LCD_wcmd(0x06);
                LCD_pos(0);
                i=0;
                while(dis1!='')
                {
                        LCD_wdat(dis1);
                        i++;
                        delay(30);
                               
                }
        LCD_pos(0x40);
        i=0;
        while(dis2[1]!='')
        {
                LCD_wdat(dis2);
                i++;
                delay(30);
                       
        }


                delay(800);
                LCD_wcmd(0x01);
            delay(1);
                LCD_wcmd(0x04);
                LCD_pos(15);
                i=0;
                while(dis3!='')
                {
                        LCD_wdat(dis3);
                        i++        ;
                        delay(30);
        }
                LCD_pos(0x4F);
                i=0;
                while(dis4!='')
                {
                        LCD_wdat(dis4);
                        i++;
                        delay(30);
                }

                        delay(800);
                        LCD_wcmd(0x01);
                        delay(200);                  

        }

}


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