微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > proteus 1602液晶程序

proteus 1602液晶程序

时间:11-13 来源:互联网 点击:
proteus1602液晶是LM016L

#include
#include
#include
#define uchar unsigned char
#define uint unsigned int
#pragma data:code
const uchar table[]="I LOVE CHINA";
const uchar table1[]="MADE BY LYQ" ;
void delay(uint ms)
{
uint i,j;
for(i=0;ifor(j=0;j<1141;j++);
}
void write_com(uchar com)
{
PORTD&=~BIT(4); // RS
PORTD&=~BIT(5);// RW
PORTB=com;
//PORTD&=~BIT(6);// E
PORTD|=BIT(6);
delay(1);
PORTD&=~BIT(6);

}

void write_data(uchar data)
{
PORTD|=BIT(4); // RS
PORTD&=~BIT(5);// RW
PORTB=data;
//PORTD&=~BIT(6);// E
PORTD|=BIT(6);
delay(1);
PORTD&=~BIT(6);
}

void main()
{
uchar i;
DDRB=0XFF;
DDRD|=BIT(4)|BIT(5)|BIT(6);
PORTD&=~BIT(6);

write_com(0x38);
delay(5);
write_com(0x01);//clear screen//清屏命令非常重要,没有出现乱码
delay(5);
write_com(0x0f);
delay(5);
write_com(0x06);
delay(5);
write_com(0x80+0x10);
delay(5);

for(i=0;i<12;i++)
{
write_data(table[i]);
delay(1);
}
write_com(0x80+0x40+0x10);
delay(5);

for(i=0;i<11;i++)
{
write_data(table1[i]);
delay(1);
}
delay(1000);
for(i=0;i<16;i++)
{
write_com(0x1c);//屏幕左移16次,不是0x18
delay(200);

}

}

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top