、
//宏定义引脚
#define rs A0
#define rw A1
#define en A2
#define psb A3
#define D4 3
#define D5 9
#define D6 10
#define D7 11
//汉字地址表 可以显示 9*2 个汉字
unsigned char addr_tab[]=
{
0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,//第一行汉字位置
0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97, //第二行汉字位置
};
unsigned char DIS1[]={"朝辞白帝彩云间"};
//发送数据,先发高四位,再发第四位
void lcd_WritData(uint8_t value)
{
byte d=0;
digitalWrite(rs,1);
digitalWrite(en,0);
d=value & 0x80;
digitalWrite(D7,d);
d=value & 0x40;
digitalWrite(D6,d);
d=value & 0x20;
digitalWrite(D5,d);
d=value & 0x10;
digitalWrite(D4,d);
digitalWrite(en,1);
digitalWrite(en,0);
d=value & 0x08;
digitalWrite(D7,d);
d=value & 0x04;
digitalWrite(D6,d);
d=value & 0x02;
digitalWrite(D5,d);
d=value & 0x01;
digitalWrite(D4,d);
digitalWrite(en,1);
digitalWrite(en,0);
}
//发送命令指令
void lcd_WriteComn(uint8_t value)
{
byte d=0;
digitalWrite(rs,0);
digitalWrite(en,0);
d=value & 0x80;
digitalWrite(D7,d);
d=value & 0x40;
digitalWrite(D6,d);
d=value & 0x20;
digitalWrite(D5,d);
d=value & 0x10;
digitalWrite(D4,d);
digitalWrite(en,1);
digitalWrite(en,0);
d=value & 0x08;
digitalWrite(D7,d);
d=value & 0x04;
digitalWrite(D6,d);
d=value & 0x02;
digitalWrite(D5,d);
d=value & 0x01;
digitalWrite(D4,d);
digitalWrite(en,1);
digitalWrite(en,0);
}
//设置显示的位置
void lcd_setpos(unsigned char x , unsigned char y)
{
unsigned char pos;
if(x==1)
{
x=0x80;
}else if(x==2)
{
x=0x90;
}
else if(x==3)
{
x=0x88;
}
else if(x==4)
{
x=0x98;
}
pos= x+y;
lcd_WriteComn(pos);
}
/*
void setPosi
tion(unsigned char x, unsigned char y)
{
unsigned char p;
switch(x%4)
{
case 0: p = 0x80; break; //第一行开始地址
case 1: p = 0x90; break; //第二行
case 2: p = 0x88; break; //第三行
case 3: p = 0x98; break; //第四行
}
p += y;
lcd_WriteComn(p);
}
*/
void writeString(unsigned char * str)
{
unsigned char i = 0;
while(str != ' ')
{
lcd_WritData(str[i++]);
}
}
void lcd_Init()
{
digitalWrite(psb,1);
lcd_WriteComn(0x20);//四位bit,基本指令
delay(10);
lcd_WriteComn(0x03);//
delay(10);
lcd_WriteComn(0x0c);
delay(10);
lcd_WriteComn(0x01);//清屏显示
delay(10);
lcd_WriteComn(0x06);
delay(10);
}
//主函数
void setup() {
// put your setup code here, to run once:
pinMode(rs,OUTPUT);
pinMode(rw,OUTPUT);
pinMode(en,OUTPUT);
pinMode(psb,OUTPUT);
pinMode(D4,OUTPUT);
pinMode(D5,OUTPUT);
pinMode(D6,OUTPUT);
pinMode(D7,OUTPUT);
lcd_Init();
lcd_setpos(2,0);
for(int i=0;i<16;i++)
{
lcd_WritData(DIS1
);
}
//setPosition(1,0);
//writeString(datas1);
}
void loop() {
// put your main code here, to run repeatedly:
}
-
-
HJ14432ZWA模块(说明书.pdf
下载积分: 积分 -1 分
371.5 KB, 下载次数: 11, 下载积分: 积分 -1 分
显示汉字有查表或查字库的问题,只有显示正常了,才能查找是否查表计算的错误。
一周热门 更多>