m0_66498354
2022-03-22 10:39
采纳率: 75%
浏览 102

51单片机LCD1602滚动显示

#include <reg52.h>
typedef unsigned int uint;
typedef unsigned char uchar;

sbit EN=P2^7;
sbit RS=P2^6;
sbit RW=P2^5;
sbit key1=P3^0;
sbit key2=P3^1;
void write_dat(uchar dat);
void write_cmd(uchar cmd);
void delay(uint d)
{
    while(d--);
}
void read_busy()
{
    uchar busy;
    P0=0xff;
    RS=0;
    RW=1;
    do
        {
            EN=1;
            busy=P0;
            EN=0;
        }while(busy & 0x80);
}
void write_cmd(uchar cmd)
{
    read_busy();//判断
    RS=0;
    RW=0;
    P0=cmd;
    EN=1;
    EN=0;
}
void write_dat(uchar dat)
{
    read_busy();
    RS=1;
    RW=0;
    P0=dat;
    EN=1;
    EN=0;
}

void main()
{
    uchar i;
    uchar *a[]={"hello ","world! ","derder ","cnm"};
    uchar *pa;
    write_cmd(0x38);//设置16X2显示
    write_cmd(0x0c);//开显示,不显示光标,光标不闪
    write_cmd(0x01);//清屏
    write_cmd(0x07);//左移动屏幕
//    write_cmd(0x80|0x0f);//显示地址
    while(1)
    {
        write_cmd(0x80|0x0f);//显示地址
        for(i=0;i<4;i++)
        {
            pa=a[i];
            while(*pa!='\0')
            {
                write_dat(*pa++);//写数据
                delay(60000);
            }
        }
    }
}



我想实现在LCD1602上循环显示字符数组的内容,但是实际效果是在第一次循环结束后会出现一大串空格,然后在重新显示内容。

img

1条回答 默认 最新

相关推荐 更多相似问题