c语言实现lcd显示自动滚动,LCD1602滚动显示C语言源程序

#include

typedef unsigned char uint8;

typedef unsigned int uint16;

sbit rs=P2^6;

sbit rw=P2^5;

sbit e=P2^7;

uint8 a[16]="perchin designed";

uint8 b[27]="welcome to the world of mcu";

void delay(uint16 i)  //1us

{

while(i--);

}

void wrc(uint8 c)

{

delay(1000);

rs=0;

rw=0;

e=0;

P0=c;

e=1;

delay(10);

e=0;

/*

P0=c<<4;

e=1;

e=0;*/       //四位的LCD要加上

}

void wrd(uint8 dat)

{

delay(1000);

rs=1;

rw=0;

e=0;

P0=dat;

e=1;

delay(10);

e=0;

/*

P0=dat<<4;

e=1;

e=0;*/           //四位的LCD要加上

rs=0;

}

void init()

{

delay(1000);

/*wrc(0x32);

wrc(0x28);

wrc(0x28);        */        //四位的LCD要加上

wrc(0x38);

wrc(0x38);

wrc(0x38);

wrc(0x0c);

wrc(0x01);

}

void display()

{

uint8 i;

wrc(0x00+0x80);

for(i=0;i<16;i++)

{

wrd(a[i]);

}

wrc(0x40+0x80);

for(i=0;i<27;i++)

{

wrd(b[i]);

}

wrc(0x07);         //每写一个数据屏幕就要右移一位,就相对于数据来说就是左移了;

while(1)

{

wrc(0x00+0x80);

for(i=0;i<16;i++)

{

wrd(a[i]);

delay(30000);        //如果不加这条延时语句的话滚动会非常快。

}

}

}

void main()

{

init();

while(1)

{

display();

}

}

  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值