📄 lcd.c
字号:
#include "ADuC842.h"
#include"LCD.h"
#include <intrins.h>
#include "math.h"
#include <absacc.h>
#include "bmp.h"
//code unsigned char SED1335Init1[8]={0x30,0x87,0x07,0x27,0x42,0xf0,0x28,0X00};
code unsigned char SED1335Init1[8]={0x30,0x87,0x07,0x27,0x2D,0xf0,0x28,0X00};
code unsigned char SED1335Init2[10]={SED1335LAY1_l,SED1335LAY1_h,0xf0,SED1335LAY2_l,SED1335LAY2_h,0xf0,SED1335LAY3_l,SED1335LAY3_h,0x00,0xC0};
sbit FSYNC = P3^4;
unsigned char *p;
//画点的查表,仔细推理可以得出
code unsigned char dw_point[8]={0x01,0x80,0x40,0x20,0x10,0x08,0x04,0x02};
//-------------------------------0-----1----2---3-----4----5----6---7---//
//===================================================================================//
// 延时函数
//===================================================================================//
void Delay1335(void)
{
_nop_ ();
// _nop_ ();
// _nop_ ();
}
//===================================================================================//
// 写液晶命令字
//===================================================================================//
void LCD_WR_COM(unsigned char lcdcom)
{
FSYNC = 0;
LcdComW = lcdcom;
FSYNC = 1;
Delay1335() ;
}
//===================================================================================//
// 写液晶命令参数
//===================================================================================//
void LCD_WR_DATA(unsigned char lcdpara)
{
FSYNC = 0;
LcdDataW = lcdpara;
FSYNC = 1;
Delay1335() ;
}
//===================================================================================//
// 读液晶命令参数
//===================================================================================//
unsigned char LCD_READ_DATA(void)
{
unsigned char lcdpara;
FSYNC = 0;
lcdpara = LcdDataR;
FSYNC = 1;
Delay1335() ;
return(lcdpara);
}
//===================================================================================//
// 读液晶状态
//===================================================================================//
unsigned char LCD_READ_STATUS(void)
{
unsigned char status;
FSYNC = 0;
status = LcdStatus;
FSYNC = 1;
Delay1335() ;
return(status);
}
//===================================================================================//
// 初始化
//===================================================================================//
void Init1335(void)
{
char loop;
LCD_WR_COM(SYSTEM_SET); //SYSTEM SET代码
for(loop=0;loop<8;loop++)
{ //送具体指令参数:无边界、8*8点阵字体、80-9FH范围字幅代码、内部字符发生器有效,
LCD_WR_DATA(SED1335Init1[loop]); //交流驱动波形、字符宽度7H,字符高度7H,有效显示长度27H,LCD工作频率时间常数,
} //LCD的点行数F0H,显示屏一行所占显示缓冲区的字节数0028H
LCD_WR_COM(SCROLL); //SCROLL代码
for(loop=0;loop<10;loop++)
{ //设置显示RAM区中各显示区的起始地址及所占有的显示行数,它与system set中的AP参数结合,可确定显示区所占的字节数,该指令有10个参数。
LCD_WR_DATA(SED1335Init2[loop]); //写入参数,分为4个显示区
}
LCD_WR_COM(CSRDIR_R); //光标自由移动方向向右
LCD_WR_COM(HDOT_SCR);//设置以点为单位的显示画面水平移动量,相当于一个字节内的卷动,带一个参数
LCD_WR_DATA(0x00); //0H->7H,显示左移;7H->0H,显示右移
LCD_WR_COM(OVLAY);//规定画面重叠显示的合成方式及显示一、三区的显示属性
LCD_WR_DATA(0x1C);//三重合成,三区:图形方式;一区:图形方式;合成关系:或
// LCD_WR_DATA(0x00);//2重合成,三区:文本方式;一区:文本方式;合成关系:或
LCD_WR_COM(DISP_ON);//开显示,并规定各显示区及光标的显示方式
LCD_WR_DATA(0x54);//三区:关闪烁;二、四区:关闪烁;一区:关闪烁;光标:关
// LCD_WR_DATA(0x10);
ClearScreen();
}
//===================================================================================//
//清显示RAM 区(清屏)
//===================================================================================//
void ClearScreen(void)
{
ClearLayer1();
ClearLayer2();
ClearLayer3();
}
void ClearLayer1(void)
{
int xdata i;
LCD_WR_COM(CSRW); //CSRW 代码
LCD_WR_DATA(SED1335LAY1_l); //设置参数光标指针低8位
LCD_WR_DATA(SED1335LAY1_h); //设置参数光标指针高8位
LCD_WR_COM(MWRITE);
for(i=0;i<(40*240);i++)
{
LCD_WR_DATA(0x00); //写入数据
}
}
void ClearLayer2(void)
{
int xdata i;
LCD_WR_COM(CSRW); //CSRW 代码
LCD_WR_DATA(SED1335LAY2_l); //设置参数光标指针低8位
LCD_WR_DATA(SED1335LAY2_h); //设置参数光标指针高8位
LCD_WR_COM(MWRITE);
for(i=0;i<(40*240);i++)
{
LCD_WR_DATA(0x00); //写入数据
}
}
void ClearLayer3(void)
{
int xdata i;
LCD_WR_COM(CSRW); //CSRW 代码
LCD_WR_DATA(SED1335LAY3_l); //设置参数光标指针低8位
LCD_WR_DATA(SED1335LAY3_h); //设置参数光标指针高8位
LCD_WR_COM(MWRITE);
for(i=0;i<(40*240*3);i++)
{
LCD_WR_DATA(0x00); //写入数据
}
}
//===================================================================================//
//写汉字子程序(图形)函数 range40 X 240 16*16
//===================================================================================//
void plot_Chinese(unsigned int layer ,unsigned int Px,unsigned int Py,unsigned char *Chinese)
{ unsigned int xdata i;
unsigned int xdata init_high8,init_low8;
unsigned int xdata offset,addr;
unsigned char LB,HB;
if(Px < 1 ||Px >40 ||Py <1 ||Py>240) return;
p=Chinese;
if(layer == 1)
{init_high8 = SED1335LAY1_h; init_low8 = SED1335LAY1_l;}
else if(layer == 2)
{init_high8 = SED1335LAY2_h; init_low8 = SED1335LAY2_l;}
else if(layer == 3)
{init_high8 = SED1335LAY3_h; init_low8 = SED1335LAY3_l;}
else
{return;}
offset = (Py-1)*40 + Px-1;
addr = (init_high8 << 8) + init_low8;
addr = addr + offset;
for(i=0;i<16;i++)
{ addr =addr +40;
LB = addr & 0x00ff;
HB = addr >> 8;
//set address ly1
LCD_WR_COM(CSRW); //CSRW 代码
LCD_WR_DATA(LB); //设置参数光标指针低8位
LCD_WR_DATA(HB); //设置参数光标指针高8位
//write data
LCD_WR_COM(MWRITE);
LCD_WR_DATA(*p++);
LCD_WR_DATA(*p++);
}
}
//===================================================================================//
//写number子程序(图形)函数 range40 X 240 8*16
//===================================================================================//
void plot_Number(unsigned int layer ,unsigned int Px,unsigned int Py,unsigned char *Numb)
{
unsigned int xdata i;
unsigned int xdata init_high8,init_low8;
unsigned int xdata offset,addr;
unsigned char xdata LB,HB;
if(Px < 1 ||Px >40 ||Py <1 ||Py>240) return;
p=Numb;
if(layer == 1)
{init_high8 = SED1335LAY1_h; init_low8 = SED1335LAY1_l;}
else if(layer == 2)
{init_high8 = SED1335LAY2_h; init_low8 = SED1335LAY2_l;}
else if(layer == 3)
{init_high8 = SED1335LAY3_h; init_low8 = SED1335LAY3_l;}
else
{return;}
offset = (Py-1)*40 + Px-1;
addr = (init_high8 << 8) + init_low8;
addr = addr + offset;
LB = addr & 0x00ff;
HB = addr >> 8;
LCD_WR_COM(CSRDIR_D); //光标自由移动方向向xia
//set address ly1
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -