/************************************************
* LCD5110_Driver.c
*
* Created: 2012/11/15 15:15:05
* Author: Charles
**************************************************/
/********************Includes*******************************/
#include <avr/pgmspace.h>
#include "config.h"
#include "type.h"
#include "chars.h"
/********************************************************
/Function Name:LCD_Wr_Byte(u8 dc, u8 cmd)
/Description :向LCD写一个数据
/Input :dc,要写入的数据/命令
cmd,0:写入的是命令
1:写入的是数据
/Output :None
/Return :None
********************************************************/
void LCD_Wr_Byte(u8 dc, u8 cmd)
{
u8 i;
if(cmd)
DC1;
else
DC0;
CE0;
for(i = 0; i < 8; i++)
{
if(dc & 0x80) //从高位开始发送
DIN1;
else
DIN0;
CLK0;
dc <<= 1;
CLK1;
}
CE1;
}
/********************************************************
/Function Name:LCD_Set_ADD(u8 x, u8 y)
/Description :设置要显示的数据的地址
/Input :显示器的(x,y)坐标位置
x:0 ~ 83 (共有84列)
y:0 ~ 5 (共有6行)
/Output :None
/Return :None
********************************************************/
void LCD_Set_ADD(u8 x, u8 y)
{
LCD_Wr_Byte(0x80 | x, 0); //列:0~83
LCD_Wr_Byte(0x40 | y, 0); //行:0~6
}
/********************************************************
/Function Name:LCD_Clr(void)
/Description :LCD清屏
/Input :None
/Output :None
/Return :None
********************************************************/
void LCD_Clr(void)
{
u16 x;
LCD_Set_ADD(0, 0); //地址设为(0,0)
for (x = 0; x < 504; x++) //6*84 = 504
{
LCD_Wr_Byte(0x00, 1); //全部写数据0
}
}
/********************************************************
/Function Name:LCD_Init(void)
/Description :LCD初始化
/Input :None
/Output :None
/Return :None
********************************************************/
void LCD_Init(void)
{
RST0; //硬件复位LCD
RST1;
LCD_Wr_Byte(0x21, 0); //功能设置,芯片活动,水平寻址,使用扩展指令
LCD_Wr_Byte(0x06, 0); //VLCD温度系数2
LCD_Wr_Byte(0x13, 0); //设置偏置系统(BSx)1:48
LCD_Wr_Byte(0xb8, 0); //设置VOP(对比度电压设置)值,室温下编程范围为3.00 ~ 10.68
//计算公式:VLcd = 3.06 + (VOP) * 0.06
LCD_Wr_Byte(0x20, 0); //功能设置,芯片活动,水平寻址,使用基本指令
LCD_Wr_Byte(0x0c, 0); //设定显示配置:普通模式
LCD_Clr(); //清屏
}
/********************************************************
/Function Name:LCD_Clr_Row(u8 row)
/Description :LCD的第row行清行
/Input :row:第row行 0~5
/Output :None
/Return :None
********************************************************/
void LCD_Clr_Row(u8 row)
{
u16 x;
LCD_Set_ADD(0, row); //地址设为第row行起始
for (x = 0; x < 84; x++) //一行84个字节
{
LCD_Wr_Byte(0x00, 1); //全部写数据0
}
}
/********************************************************
/Function Name:LCD_Wr_6x8(u8 x, u8 y, u8 num)
/Description :输入一个6x8的字符
/Input :x:水平方向位置 0~13
/ y:竖直方向位置 0~5
/ num:显示第num个字符
/Output :None
/Return :None
********************************************************/
void LCD_Wr_6x8(u8 x, u8 y, u8 ch, u8 mode)
{
u8 i;
ch -= 32; //ASCII码修正
x *= 6;
LCD_Set_ADD(x , y);
if (!mode)
{
for(i = 0; i < 6; i++)
{
LCD_Wr_Byte(pgm_read_byte(&Font6x8[ch][i]), 1);
}
}
else
{
for(i = 0; i < 6; i++)
{
LCD_Wr_Byte(~pgm_read_byte(&Font6x8[ch][i]), 1);
}
}
}
/********************************************************
/Function Name:LCD_Wr_Str(u8 x, u8 y, *s)
/Description :显示一个字符串(6x8的字符)
/Input :x:水平方向位置 0~13
/ y:竖直方向位置 0~5
/ s:要显示的字符串
/Output :None
/Return :None
********************************************************/
void LCD_Wr_Str(u8 x, u8 y, u8 *s, u8 mode)
{
while(*s)
{
LCD_Wr_6x8(x++, y, *s, mode); //Call the character display function.
s++;
if(x >= 14) //There are 14 chars every line at most.
{
x = 0;
y++;
}
if(y >= 6) //Thera are 6 lines at most.
{
y = 0;
}
}
}