LCD6210字符型液晶显示器 (2)

实例

首先在第一行显示“I love MCU!”,第二行显示“LCD1602 Test!”。延时一段时间,清屏。然后在第一行显示“Welcome to my lcd6210!”,显示方式是从屏幕右面移入,左面移出。周而复始

#include

#include
typedef unsigned int u16;
typedef unsigned char u8;
#define DATA P0
sbit rs = P2^1;
sbit rw = P1^5;
sbit en = P1^6;


u8 strMCU[]="I love MCU";
u8 strTest[]="LCD1602 Test!";
u8 blog[]="Welcome to my lcd6210!"; 


void lcd_delay(u16 num)
{
int x ,y;
for(y = num; y >= 0; y--){
for(x = 110; x>=0 ; x--){

}
}
}


void write_cmd(u8 cmd)
{
rs = 0;
rw = 0;
lcd_delay(50);
en = 1;
DATA = cmd;
lcd_delay(50);
en = 0;
}


void write_data(u8 dat)
{
rs = 1;
rw = 0;
lcd_delay(50);
en = 1;
DATA = dat;
lcd_delay(50);
en = 0;
}


void write_str(u8 addr, u8 len, u8 *pbuf)
{
u8 i;
write_cmd(addr);
for(i = 0; i < len; i++){
write_data(pbuf[i]);
}
}


void lcd_init(void)
{
write_cmd(0x02);
write_cmd(0x06);
write_cmd(0x0c);
write_cmd(0x38);
write_cmd(0x01);
}


int main(void)
{
rs = 0;
rw = 0;
en = 0;
lcd_init();
write_str(0x80,strlen(strMCU),strMCU);
write_str(0x80+0x40,strlen(strTest),strTest);

//延迟一段时间,再清屏
lcd_delay(500);
write_cmd(0x01);


write_str(0x80+0x10,strlen(blog),blog);//写在显示之外

while(1){
write_cmd(0x1c);
lcd_delay(100);
};
}

你可能感兴趣的:(单片机)