#include "LCD12864_P.h"
int LCD12864_E_PORT = 10;
int LCD12864_RW_PORT = 11;
int LCD12864_RS_PORT = 12;
int DB[] = {2, 3, 4, 5, 6, 7, 8, 9};
//********************************************************************
//LCD12864地址设置
//********************************************************************
void LCD12864_Clear()
{
LCD12864_COM_Write(0x01);
}
//********************************************************************
//LCD12864地址设置
//********************************************************************
void LCD12864_SET_Address( unsigned char i,unsigned char j)
{
switch(i)
{
case 1:
LCD12864_COM_Write(0x80+(j-1));
break;
case 2:
LCD12864_COM_Write(0x90+(j-1));
break;
case 3:
LCD12864_COM_Write(0x88+(j-1));
break;
case 4:
LCD12864_COM_Write(0x98+(j-1));
break;
default: break;
}
}
//********************************************************************
//BUS OUTPUT
//********************************************************************
void LCD12864_DA_PORT(unsigned char value)
{
unsigned char i;
for (i=0; i < 8; i++)
{
digitalWrite(DB[i],value & 01);
value >>= 1;
}
}
//********************************************************************
//LCD12864 忙 信号检测
//********************************************************************
void LCD12864_WaitIdle()
{
unsigned char i;
for (i = 0; i < 8; i++)
{
pinMode(DB[i], OUTPUT);
}
// LCD12864_DA_PORT(0xff);
digitalWrite(LCD12864_RS_PORT, LOW);
// delayMicroseconds(8);
digitalWrite(LCD12864_RW_PORT, HIGH);
// delayMicroseconds(8);
digitalWrite(LCD12864_E_PORT, HIGH);
// delayMicroseconds(8);
for (i = 0; i < 8; i++)
{
pinMode(DB[i], INPUT);
}
while(digitalRead(DB[7])==1); /*等待BF 不为1*/
for (i = 0; i < 8; i++)
{
pinMode(DB[i], OUTPUT);
}
digitalWrite(LCD12864_E_PORT, LOW);
for(i=0;i<50;i++);
}
//********************************************************************
//检测忙信号写入命令字 com_da 为待写入的命令字
//********************************************************************
void LCD12864_COM_Write( unsigned char com_da)
{
LCD12864_WaitIdle();
digitalWrite(LCD12864_RS_PORT, LOW);
// delayMicroseconds(8);
digitalWrite(LCD12864_RW_PORT, LOW);
// delayMicroseconds(8);
LCD12864_DA_PORT(com_da);
digitalWrite(LCD12864_E_PORT, HIGH);
delayMicroseconds(8);
digitalWrite(LCD12864_E_PORT, LOW);
delayMicroseconds(8);
}
//********************************************************************
//不检测忙信号写入命令字 com_da 为待写入的命令字
//********************************************************************
void LCD12864_NoWaitIdle_COM_Write(unsigned char com_da)
{
digitalWrite(LCD12864_RS_PORT, LOW);
// delayMicroseconds(8);
digitalWrite(LCD12864_RW_PORT, LOW);
// delayMicroseconds(8);
LCD12864_DA_PORT(com_da);
digitalWrite(LCD12864_E_PORT, HIGH);
delayMicroseconds(8);
digitalWrite(LCD12864_E_PORT, LOW);
delayMicroseconds(8);
}
//********************************************************************
//数据写入 da 为待写入的8位数据
//********************************************************************
void LCD12864_Data_Write(unsigned char da)
{
LCD12864_WaitIdle(); /*检测忙信号*/
digitalWrite(LCD12864_RS_PORT, HIGH);
// delayMicroseconds(8);
digitalWrite(LCD12864_RW_PORT, LOW);
LCD12864_DA_PORT(da);
digitalWrite(LCD12864_E_PORT, HIGH);
delayMicroseconds(8);
digitalWrite(LCD12864_E_PORT, LOW);
delayMicroseconds(8);
}
//*************************************************************************************
//写连续字符函数
//*************************************************************************************
void LCD12864_write_word(const char *s)
{
while(*s>0)
{
LCD12864_Data_Write(*s);
s++;
delay(1);
}
}
//********************************************************************
//LCD12864初始化
//********************************************************************
void LCD12864_Reset()
{
unsigned char i;
for (i = 0; i < 8; i++)
{
pinMode(DB[i], OUTPUT);
}
pinMode(LCD12864_E_PORT,OUTPUT);
pinMode(LCD12864_RS_PORT,OUTPUT);
pinMode(LCD12864_RW_PORT,OUTPUT);
delay(100); /*适当延时待LCD自动复位完成*/
LCD12864_COM_Write(0x30); /*使用8位并口通讯*/
delay(10);
LCD12864_COM_Write(0x30); /*使用8位并口通讯*/
delay(10);
LCD12864_COM_Write(0x0c); /*显示开及光标设置*/
delay(10);
LCD12864_COM_Write(0x01); /*显示清屏*/
delay(30);
LCD12864_COM_Write(0x06); /*DDRAM的地址计数器(AC)加1*/
delay(30);
}
//void LCD12864_PHOTO_SET()
//{
// LCD12864_COM_Write(0x36);
// lcd_delay_ms(10);
// LCD12864_COM_Write(0x36);
// lcd_delay_ms(10);
//}
//
void LCD12864_HAIZI_SET()
{
LCD12864_COM_Write(0x30);
delay(10);
LCD12864_COM_Write(0x30);
delay(10);
}