做了一下1602的仿真,如下图,“I LIKE MCU! ARM.Craftor”从屏幕右边慢慢移动到左边。
C代码如下:
#include<reg52.h>
#include<stdio.h>
#define uint unsigned int
#define uchar unsigned char
uchar code tab1[]="I LIKE MCU!";
uchar code tab2[]="ARM.Craftor";
uchar num,len1,len2;
sbit RS="P1"^0;//位申明
sbit RW="P1"^1;
sbit EN="P1"^2;
void delay(uint x)//延时子程序
{
while(--x);
}
void write_cmd(uchar cmd)//写命令子程序
{
RS=0;
RW=0;
P0=cmd;
delay(500);
EN=1;
delay(500);
EN=0;
}
void write_dat(uchar dat)//写数据子程序
{
RW=0;
RS=1;
P0=dat;
delay(500);
EN=1;
delay(500);
EN=0;
}
void init_lcd()//1602液晶初始化
{
EN=0;
write_cmd(0x38);//显示模式设置
write_cmd(0x0f);//显示开关、光标设置
// write_cmd(0x05);//光标及屏幕显示方式设置
write_cmd(0x01);//清屏
write_cmd(0x80);//指针初始化
}
void main()
{
init_lcd();
len1=sizeof(tab1);
len2=sizeof(tab2);
write_cmd(0x80+0x10);//将第一行字符写入缓冲区
for(num=0;num<len1;num++)
{
write_dat(tab1[num]);
delay(100);
}
write_cmd(0x80+0x55);
for(num=0;num<len2;num++)//将第二行字符写入缓冲区
{
write_dat(tab2[num]);
delay(100);
}
for(num=0;num<16;num++)//屏幕整体左移
{
write_cmd(0x1f);
delay(20000);
}
while(1);
}
用户132338 2008-7-18 10:18
用户124183 2008-7-17 16:53
用户1384026 2008-7-17 09:36
用户151534 2008-7-17 00:05