?? 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 + -