有了上述的几个函数以后,我们的程序差不多能够运行了,还差点啥,恩,是的,的确,是输出字符串的函数,下面就是他了,这个输出字符串的函数比较简单,其实我应该把它做成一个输出中文的东西的,不过这里没有,因为我的12864是带字库的,所以这一切做的比较省事,具体的关于这些中文或者英文在12864的存储空间中的位置的事情,你可以去查阅他的说明书,说的很清楚。
恩,字符输出的函数不再单独贴出来,整个完整的代码在此:
int psb_pin = 3;
int reset_pin = 4;
int bla_pin = 13;
int blk_pin = 12;
int e_pin = 5;
int rs_pin = 7;
int rw_pin = 6;
int v0_pin = A0;
int vcc_pin = 11;
// all the Chinese word are in the CGROM,
// this is a set for serial communication
char shuzu[]={"hello"};
void setup()
{
// set the pin mode
pinMode(vcc_pin,OUTPUT);
pinMode(psb_pin,OUTPUT);
pinMode(reset_pin,OUTPUT);
pinMode(bla_pin,OUTPUT);
pinMode(blk_pin,OUTPUT);
pinMode(e_pin,OUTPUT);
pinMode(rs_pin,OUTPUT);
pinMode(rw_pin,OUTPUT);
pinMode(v0_pin,OUTPUT);
pinMode(reset_pin,OUTPUT);
// testing point
digitalWrite(vcc_pin,HIGH);
digitalWrite(bla_pin,HIGH);
digitalWrite(blk_pin,LOW);
digitalWrite(psb_pin,0); // set the mode to parallel
analogWrite(v0_pin,150);
digitalWrite(reset_pin,LOW);
digitalWrite(reset_pin,HIGH);
LCD_Init();
delay(1000);
LCD_WriteStr(1,1,shuzu);
}
void LCD_setxy(unsigned char x,unsigned char y)
{
switch(y)
{
case 1:
LCD_write_byte(0,0,0X7F+x);break; //Line1
case 2:
LCD_write_byte(0,0,0X8F+x);break; //Line2
case 3:
LCD_write_byte(0,0,0X87+x);break; //Line3
case 4:
LCD_write_byte(0,0,0X97+x);break; //Line4
default:break;
}
}
void LCD_WriteStr(unsigned char dis_addr_x,unsigned char dis_addr_y,char* str)
{
unsigned char LCD_temp;
LCD_setxy(dis_addr_x,dis_addr_y);
LCD_temp=*str;
while(LCD_temp != 0x00) //显示字符串子程序,字符码为0时退出
{
LCD_write_byte(0,1,LCD_temp);
LCD_temp=*(++str);
}
}
void serial_write_byte(unsigned char dat)
{
unsigned char i;
for(i=0;i<8;i++)
{
if((dat&0x80)==0){
clear_rw();
delay(2);
set_e();
delay(4);
clear_e();
delay(2);
clear_rw();
}
else{
set_rw();
delay(2);
set_e();
delay(4);
clear_e();
delay(2);
clear_rw();
}
dat = dat << 1;
}
}
void LCD_write_byte(unsigned char RW, unsigned char RS, unsigned char W_data)
{
unsigned int H_data,L_data,S_ID = 0xf8; //11111RWRS0
if(RW == 0) //RW=0,MCU写一个数据到液晶;
{
S_ID &=~ 0x04;
}
else //RW=1,从液晶读数据到MCU
{
S_ID |= 0X04;
}
if(RS == 0) //RS=1,写入的是数据
{
S_ID &=~ 0x02;
}
else //RS=0,写入的是指令;
{
S_ID |= 0X02;
}
H_data = W_data;
H_data &= 0xf0; //屏蔽低4位的数据
L_data = W_data; //xxxx0000格式
L_data &= 0x0f; //屏蔽高4位的数据
L_data <<= 4; //xxxx0000格式
set_rs();
serial_write_byte(S_ID); //发送S_ID
serial_write_byte(H_data); //发送H_data
serial_write_byte(L_data); //发送L_data
clear_rs();
}
void LCD_Init(void)
{
delay(2);
LCD_write_byte(0,0,0x30); //功能设置 8位数据,基本指令
delay(2);
LCD_write_byte(0,0,0x04); //点设定:显示字符/光标从左到右移位,DDRAM地址加1
delay(2);
LCD_write_byte(0,0,0x0C); //显示设定:开显示,显示光标,当前显示位反白闪动
delay(2);
LCD_write_byte(0,0,0x01); //写指令:清除显示, 清DDRAM
delay(2);
LCD_write_byte(0,0,0x02); //写指令:DDRAM地址归位
delay(2);
LCD_write_byte(0,0,0x80); //写指令:设置DDRAM地址,把显示地址设为0X80,即为第一行的首位
delay(2);
}
void loop()
{
}
void set_e()
{
digitalWrite(e_pin,HIGH);
}
void clear_e()
{
digitalWrite(e_pin,LOW);
}
void set_rs()
{
digitalWrite(rs_pin,HIGH);
}
void clear_rs()
{
digitalWrite(rs_pin,LOW);
}
void set_rw()
{
digitalWrite(rw_pin,HIGH);
}
void clear_rw()
{
digitalWrite(rw_pin,LOW);
}
还请各位多多指教,这些代码写的比较仓促,还是有一些不足的地方的,欢迎指正。
文章评论(0条评论)
登录后参与讨论