#include "lcd12864.h"
#include "intrins.h"
void Lcd12864_ByteShow_String(uint8 *str1)
{
while(*str1!='\0')
{
Lcd12864_Write_Data(*str1);
str1++;
}
}
void Lcd12864_Show_String(uint8 row, uint8 col,uint8 *str){
uint8 *defaultValue = "parameter error" ;
switch(row){
case 1:
Lcd12864_Write_Cmd(0x80+col-1);//第一行第y个空格
while(*str!='\0')
{
Lcd12864_Write_Data(*str);
str++;
}
break;
case 2:
Lcd12864_Write_Cmd(0x90+col-1);//第二行第y个空格
while(*str!='\0'){
Lcd12864_Write_Data(*str);
str++;
}
break;
case 3:
Lcd12864_Write_Cmd(0x88+col-1);//第一行第y个空格
while(*str!='\0'){
Lcd12864_Write_Data(*str);
str++;
}
break;
case 4:
Lcd12864_Write_Cmd(0x98+col-1);//第二行第y个空格
while(*str!='\0'){
Lcd12864_Write_Data(*str);
str++;
}
break;
default:
Lcd12864_Write_Cmd(0x00+0x80);//parameter error
while(*defaultValue!='\0'){
Lcd12864_Write_Data(*defaultValue);
defaultValue++;
}
}
}
/******************************************************************************/
// 函数名称:Lcd12864_Busy_Check
// 输入参数:无
// 输出参数:无
// 函数功能:LCD1602忙信号检查
/******************************************************************************/
void Lcd12864_Busy_Check(void){
uint8 tmp;
lcdPort = 0xff;//一开始的时候,lcdPort设置成输入状态
do{
RS2 = 0;
RW2 = 1;
EN2 = 0;
EN2 = 1;
_nop_();
_nop_();//延时CP
tmp = lcdPort;
_nop_();//延时PQ
EN2 = 0;
_nop_();
}while(tmp&0x80);
}
/******************************************************************************/
// 函数名称:Lcd12864_Init
// 输入参数:无
// 输出参数:无
// 函数功能:LCD12864初始化
/******************************************************************************/
void Lcd12864_Init(void)
{
Lcd12864_Write_Cmd(0x30);//基本指令设置
Lcd12864_Write_Cmd(0x01);//清屏
Lcd12864_Write_Cmd(0x06);//显示光标移动设置
Lcd12864_Write_Cmd(0x0c);//显示开及光标设置
vout2 = 0;
rst2 = 1;
}
/******************************************************************************/
// 函数名称:Lcd12864_Write_Cmd
// 输入参数:cmd
// 输出参数:无
// 函数功能:LCD12864发送命令
/******************************************************************************/
void Lcd12864_Write_Cmd(uint8 cmd){
Lcd12864_Busy_Check();//busycheck
PSB2 = 1;
RS2 = 0;
RW2 = 0;
EN2 = 0;
EN2 = 1;
_nop_();
_nop_();
lcdPort = cmd;
_nop_();
_nop_();
EN2 = 0;
_nop_();
_nop_();
}
/******************************************************************************/
// 函数名称:Lcd12864_Write_Data
// 输入参数:Data-写入数据
// 输出参数:无
// 函数功能:LCD12864写一个字节数据
/******************************************************************************/
void Lcd12864_Write_Data(uint8 Data){
Lcd12864_Busy_Check();//busycheck
PSB2 = 1;
RS2 = 1;
RW2 = 0;
EN2 = 0;
EN2 = 1;
_nop_();
_nop_();
lcdPort = Data;
_nop_();
_nop_();
EN2 = 0;
_nop_();
_nop_();
}
/******************************************************************************/
// 函数名称:Lcd12864_Screen_Flash
// 输入参数:无
// 输出参数:无
// 函数功能:LCD12864屏幕闪烁
/******************************************************************************/
//void Lcd12864_Screen_Flash(void){
// Lcd12864_Write_Cmd(0x08);
// Delay400ms();Delay400ms();
// Lcd12864_Write_Cmd(0x0c);
// Delay400ms();Delay400ms();
// Lcd12864_Write_Cmd(0x08);
// Delay400ms();Delay400ms();
// Lcd12864_Write_Cmd(0x0c);
// Delay400ms();Delay400ms();
//}
/******************************************************************************/
// 函数名称:Lcd12864_Show_Specific_Symbol
// 输入参数:无
// 输出参数:无
// 函数功能:LCD12864显示特殊符号
/******************************************************************************/
//void Lcd12864_Show_Specific_Symbol(void){
// uint8 i;
// Lcd12864_Write_Cmd(0x01);//清屏
// for(i=0;i<32;i++){
// Lcd12864_Write_Cmd(0x80+i); //显示位置
// Lcd12864_Write_Data(0x02+i);//显示内容
// }
//}
/******************************************************************************/
// 函数名称:Lcd12864_Screen_Clear
// 输入参数:无
// 输出参数:无
// 函数功能:LCD12864清屏
/******************************************************************************/
void Lcd12864_Screen_Clear(void){
Lcd12864_Write_Cmd(0x01);
}
|