📄 lcddriver.c
字号:
#include "44b.h"
#include "44blib.h"
#include "def.h"
#include "option.h"
#include "font.h"
#include <stdarg.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <math.h>
void Pin_DatCom(U8 vl)
{
if(vl)
rPDATC |= 0x0080;
else
rPDATC &= 0xff7f;
}
void Pin_Rd(U8 vl)
{
if(vl)
rPDATC |= 0x0040;
else
rPDATC &= 0xffbf;
}
void Pin_Wr(U8 vl)
{
if(vl)
rPDATC |= 0x0020;
else
rPDATC &= 0xffdf;
}
void Pin_Cs(U8 vl)
{
if(vl)
rPDATC |= 0x0010;
else
rPDATC &= 0xffef;
}
void Pin_Rst(U8 vl)
{
if(vl)
rPDATC &= 0xfdff;
else
rPDATC |= 0x0200;
}
void Pin_Bled(U8 vl)
{
if(vl)
rPDATC &= 0xfeff;
else
rPDATC |= 0x0100;
}
/**********************************************************/
void LCD_Reset(U8 st)
{
if(st)
{
Pin_Rst(0);
Delay(5);
Pin_Rst(1);
Delay(5);
}
else
{
Pin_Rst(1);
Delay(5);
Pin_Rst(0);
Delay(5);
}
}
void LCD_Bled(U8 bl)
{
if(bl)
Pin_Bled(0);
else
Pin_Bled(1);
}
void LCD_Cs(U8 cs)
{
if(cs)
Pin_Cs(1);
else
Pin_Cs(0);
}
void LCD_Wcommand(U8 com)
{
Pin_DatCom(0);
Pin_Rd(1);
Pin_Wr(1);
rPDATD = com;
Pin_Wr(0);
Pin_Wr(1);
}
void LCD_Wdata(U8 dat)
{
Pin_DatCom(1);
Pin_Rd(1);
Pin_Wr(1);
rPDATD = dat;
Pin_Wr(0);
Pin_Wr(1);
}
void LCD_Initialize(void)
{
LCD_Reset(1);
LCD_Cs(1);
LCD_Wcommand(0xE2); /* System reset*/
Delay(10);
LCD_Wcommand(0xEB); /* Set lcd bias ratio: 111010_10 */
LCD_Wcommand(0x25); /* Set mux rate and temperature compensation*/
LCD_Wcommand(0x81);
LCD_Wcommand(0xA5); /* Set gain and potentiometer 1_01_00101 */
LCD_Wcommand(0x2F); /* Set power control 00101_1_11 */
LCD_Wcommand(0xAF); /* Display Enable: 1010111_1 */
Delay(10);
LCD_Wcommand(0x40); /* Set start line: 01_000000 */
LCD_Wcommand(0xA4); /* Set all pixel on: 1010010_DC[1] */
LCD_Wcommand(0xA6); /* Set inverse display: 1010011_DC[0] */
LCD_Wcommand(0x89); /* Set ram address control: 10001_001 */
LCD_Wcommand(0xC8); /* Set lcd mapping control: 1100_1_0__0 */
}
void LCD_ClearAll(void)
{
U16 i;
LCD_Cs(1);
LCD_Wcommand(0XB0); /*SET PAGE ADDRESS*/
LCD_Wcommand(0X10); /*SET COLUMN ADDRESS MSB(00000000)*/
LCD_Wcommand(0X00); /*SET COLUMN ADDRESS LSB(00000000)*/
LCD_Wcommand(0X89); /*SET RAM ADDRESS CONTROL*/
for(i=0;i<3840;i++)
LCD_Wdata(0x00);
}
void LCD_WByte(U8 x,U8 y,U8 t)
{
LCD_Cs(1);
LCD_Wcommand(176+y);
LCD_Wcommand(16+x/16);
LCD_Wcommand(x%16);
LCD_Wdata(t);
}
void LCD_WPoint(U8 x,U8 y,U8 k)
{
LCD_Cs(1);
LCD_Wcommand(176+y/8);
LCD_Wcommand(16+x/16);
LCD_Wcommand(x%16);
if(k)
LCD_Wdata(0x01<<y%8);
else
LCD_Wdata(0x00);
}
/*******************************************************/
void LCD_Chinese(U8 x,U8 y,S8 *str,U8 k,U8 t)
{
S8 *OffSet;
U8 i;
U16 AddOffSet;
OffSet=strstr(Index, str);
AddOffSet=(OffSet-Index)<<4;
if(t)
{
if(k)
{
for(i=0;i<16;i++)
LCD_WByte(x+i,y,~FAlib[AddOffSet++]);
for(i=0;i<16;i++)
LCD_WByte(x+i,y+1,~FAlib[AddOffSet++]);
}
else
{
for(i=0;i<16;i++)
LCD_WByte(x+i,y,FAlib[AddOffSet++]);
for(i=0;i<16;i++)
LCD_WByte(x+i,y+1,FAlib[AddOffSet++]);
}
}
else
{
if(k)
{
for(i=0;i<16;i++)
LCD_WByte(x+i,y,~CAlib[AddOffSet++]);
for(i=0;i<16;i++)
LCD_WByte(x+i,y+1,~CAlib[AddOffSet++]);
}
else
{
for(i=0;i<16;i++)
LCD_WByte(x+i,y,CAlib[AddOffSet++]);
for(i=0;i<16;i++)
LCD_WByte(x+i,y+1,CAlib[AddOffSet++]);
}
}
}
void LCD_Ascii(U8 x,U8 y,S8 *str,U8 k)
{
S8 *OffSet;
U8 i;
U16 AddOffSet;
OffSet=strstr(Index, str);
AddOffSet=(OffSet-Index)<<4;
if(k)
{
for(i=0;i<8;i++)
LCD_WByte(x+i,y,~CAlib[AddOffSet++]);
for(i=0;i<8;i++)
LCD_WByte(x+i,y+1,~CAlib[AddOffSet++]);
}
else
{
for(i=0;i<8;i++)
LCD_WByte(x+i,y,CAlib[AddOffSet++]);
for(i=0;i<8;i++)
LCD_WByte(x+i,y+1,CAlib[AddOffSet++]);
}
}
void LCD_CAstr(U8 x,U8 y,S8 *str,U8 k,U8 t)
{
S8 rega[2];
S8 regc[3];
while( *str != 0 )
{
if( (U8)*str < 0xA0 )
{
strncpy(rega, str, 1);
rega[1]=0;
LCD_Ascii(x,y,rega,k);
str=str+1;
x=x+8;
}
if( (U8)*str >= 0xA0 )
{
strncpy(regc, str, 2);
regc[2]=0;
LCD_Chinese(x,y,regc,k,t);
str=str+2;
x=x+16;
}
}
}
void LCD_math(U8 x,U8 y,S8 t,U8 k)
{
U8 i;
U16 AddOffSet;
AddOffSet=6048+16*t;
if(k)
{
for(i=0;i<8;i++)
LCD_WByte(x+i,y,~CAlib[AddOffSet++]);
for(i=0;i<8;i++)
LCD_WByte(x+i,y+1,~CAlib[AddOffSet++]);
}
else
{
for(i=0;i<8;i++)
LCD_WByte(x+i,y,CAlib[AddOffSet++]);
for(i=0;i<8;i++)
LCD_WByte(x+i,y+1,CAlib[AddOffSet++]);
}
}
void LCD_Num(U8 x,U8 y,U16 t,U8 k,S8 *str)
{
S8 a,b,c,d;
a=(int)t/1000;
b=(int)t/100-a*10;
c=(int)t/10-a*100-b*10;
d=(int)t%10;
if(a!=0)
{
LCD_math(x,y,a,k);
LCD_math(x+8,y,b,k);
LCD_math(x+16,y,c,k);
LCD_math(x+24,y,d,k);
LCD_CAstr(x+32,y,str,0,0);
}
if(a==0&&b!=0)
{
LCD_math(x,y,b,k);
LCD_math(x+8,y,c,k);
LCD_math(x+16,y,d,k);
LCD_CAstr(x+24,y,str,0,0);
}
if(a==0&&b==0&&c!=0)
{
LCD_math(x,y,c,k);
LCD_math(x+8,y,d,k);
LCD_CAstr(x+16,y,str,0,0);
}
if(a==0&&b==0&&c==0)
{
LCD_math(x,y,d,k);
LCD_CAstr(x+8,y,str,0,0);
}
}
/********************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -