#include "head.h"
#include "para.c"
#include "english_6x8_pixel.h"
/*-----------------------------------------------------------------------
LCD_write_byte : 写数据到LCD
输入参数:data :写入的数据;
command :写数据/命令选择;
-----------------------------------------------------------------------*/
void LCD_write_byte(uchar dat, uchar command)
{
uchar i;
LCD_CSB = 0; // 使能LCD
if (command == 0)
LCD_A0 = 0; // 传送命令
else
LCD_A0 = 1; // 传送数据
for(i=0;i<8;i++)
{
if(dat&0x80)
LCD_SDA = 1;
else
LCD_SDA = 0;
LCD_SCL = 0;
dat = dat << 1;
LCD_SCL = 1;
}
LCD_CSB = 1; // 关闭LCD
}
/*-----------------------------------------------------------------------
LCD_init : LCD初始化
-----------------------------------------------------------------------*/
void LCD_init(void)
{
LCD_RST = 1;
mDelay(1);
LCD_RST = 0; // 产生一个让LCD复位的低电平脉冲
uDelay(1); // 延时1uS
LCD_RST = 1; //
LCD_write_byte(0xE2, 0); // 软件复位
uDelay(1); // 延时1uS
LCD_write_byte(0xA2, 0); // 偏压设置 第11行命令
LCD_write_byte(0xA0, 0); // 显示方向 左右 第8行命令
LCD_write_byte(0xC8, 0); // 显示方向 上下 第15行命令
LCD_write_byte(0x27, 0); // 电阻率设置 第17行命令
LCD_write_byte(0x81, 0); // 对比度 第18行命令
LCD_write_byte(0x04, 0); //
LCD_write_byte(0xF8, 0); // 双字节命令 增压 第19行命令
LCD_write_byte(0x01, 0); //
uDelay(1); // 延时1uS
LCD_write_byte(0x2F, 0); // 电源开
LCD_write_byte(0xA6, 0); // 白底黑字 0xA7为黑底白字
LCD_write_byte(0xA4, 0); // 正常显示
LCD_write_byte(0x40, 0); // 显示开始位置
LCD_write_byte(0xAF, 0); // 开显示
LCD_clear();
}
/*-----------------------------------------------------------------------
LCD_clear : LCD清屏函数
-----------------------------------------------------------------------*/
void LCD_clear(void)
{
uchar i,j;
for(i=0;i<8;i++)
{
LCD_write_byte(0xB0 | i,0);
LCD_write_byte(0x10,0); // row
LCD_write_byte(0x00,0);
for(j=0;j<128;j++)
{
LCD_write_byte(0x00, 1);
}
}
}
/*-----------------------------------------------------------------------
LCD_set_XY : 设置LCD坐标函数
输入参数:X :0-3
Y :0-15
-----------------------------------------------------------------------*/
void LCD_set_XY(uchar X, uchar Y, uchar Z)
{
if(Z==0)
LCD_write_byte(0xB0 | X*2, 0);
else
LCD_write_byte(0xB0 | X*2+1, 0); // column
LCD_write_byte(0x10 | Y/16, 0); // row
LCD_write_byte(0x00 | Y%16, 0);
}
/*-----------------------------------------------------------------------
LCD_write_charfb : 显示反白英文字符
输入参数:c :显示反白的字符;
-----------------------------------------------------------------------*/
void LCD_write_charfb(uchar X,uchar Y,uchar c)
{
uchar line;
c -= 32;
LCD_set_XY(X,Y,0);
for (line=0; line<8; line++)
LCD_write_byte(~font16x8[c][line], 1);
LCD_set_XY(X,Y,1);
for (line=8; line<16; line++)
LCD_write_byte(~font16x8[c][line], 1);
}
/*-----------------------------------------------------------------------
LCD_write_char : 显示英文字符
输入参数:c :显示的字符;
-----------------------------------------------------------------------*/
void LCD_write_char(uchar X,uchar Y,uchar c)
{
uchar line;
c -= 32;
LCD_set_XY(X,Y,0);
for (line=0; line<8; line++)
LCD_write_byte(font16x8[c][line], 1);
LCD_set_XY(X,Y,1);
for (line=8; line<16; line++)
LCD_write_byte(font16x8[c][line], 1);
}
/*-----------------------------------------------------------------------
LCD_write_english_String : 英文字符串显示函数
输入参数:*s :英文字符串指针;
X、Y : 显示字符串的位置,x 0-3 ,y 0-64
-----------------------------------------------------------------------*/
void LCD_write_english_string(uchar X,uchar Y,char *s)
{
uchar i;
while (*s)
{
LCD_write_char(X,Y+(i*8),*s);
s++;
i++;
}
}
/*-----------------------------------------------------------------------
LCD_draw_map : 位图绘制函数
输入参数:X、Y :位图绘制的起始X、Y坐标;
*map :位图点阵数据;
Pix_x :位图像素(长)
Pix_y :位图像素(宽)
-----------------------------------------------------------------------*/
void LCD_draw_bmp_pixel(uchar X,uchar Y,uchar *map,uchar Pix_x,uchar Pix_y)
{
uint i,n;
uchar row;
if (Pix_y%8==0)
row=Pix_y/8; //计算位图所占行数
else
row=Pix_y/8+1;
for (n=0;n<row;n++)
{
LCD_write_byte(0xB0 | X | n,0);
LCD_write_byte(0x10 | Y/16 ,0);
LCD_write_byte(0x00 | Y%16 ,0);
for(i=0; i<Pix_x; i++)
{
LCD_write_byte(*map, 1);
map++;
}
}
}