?? lcd.h
字號:
#include <at89x52.h>
#include <intrins.h>
#define RS P2_3 /*"H" is send or read the data;"L" is the instruction*/
#define RW P3_4
#define E P2_5 /*Operation enable*/
#define CS1 P2_0
#define CS2 P2_2
#define CS3 P2_3
#define DATA P3
#define uchar unsigned char
#define uint unsigned int
/*----------------------------------------------------------------------------
Delay some time//延時
------------------------------------------------------------------------------*/
void delay10ms(unsigned char x)
{
unsigned char i,j,k;
for(i=0;i<x;i++)
for(j=0;j<10;j++)
for(k=0;k<120;k++);
}
/*----------------------------------------------------------------------------
Send the instruction to the First KS0108 window
------------------------------------------------------------------------------
--*/
void OutFI(uchar i)
{
unsigned char data_sta;
do{
E=0;RW=1;RS=0;CS1=0;_nop_();
E=1;_nop_();
data_sta=DATA;
E=0;RW=0;CS1=1;E=1;
}while(data_sta&0x80);
E=0;RW=0;RS=0;CS1=0;_nop_();
E=1;_nop_();
DATA=i;
_nop_();E=0;RW=1;CS1=1;E=1;
}
/*----------------------------------------------------------------------------
Send the instruction to the Second KS0108 window.
------------------------------------------------------------------------------
--*/
void OutSI(uchar i)
{
unsigned char data_sta;
do{
E=0;RW=1;RS=0;CS2=0;_nop_();
E=1;_nop_();
data_sta=DATA;
E=0;RW=0;CS2=1;E=1;
}while(data_sta&0x80);
E=0;RW=0;RS=0;CS2=0;_nop_();
E=1;_nop_();
DATA=i;
_nop_();E=0;RW=1;CS2=1;E=1;
}
/*----------------------------------------------------------------------------
Send the instruction to the Third KS0108 window
------------------------------------------------------------------------------
--*/
void OutTI(uchar i)
{
unsigned char data_sta;
do{
E=0;RW=1;RS=0;CS3=0;_nop_();
E=1;_nop_();
data_sta=DATA;
E=0;RW=0;CS3=1;E=1;
}while(data_sta&0x80);
E=0;RW=0;RS=0;CS3=0;_nop_();
E=1;_nop_();
DATA=i;
_nop_();E=0;RW=1;CS3=1;E=1;
}
/*----------------------------------------------------------------------------
Send the data to the First ks0108 Window
------------------------------------------------------------------------------
--*/
void OutFD(uchar i)
{
unsigned char data_sta;
do{
E=0;RW=1;RS=0;CS1=0;_nop_();
E=1;_nop_();
data_sta=DATA;
E=0;RW=0;CS1=1;E=1;
}while(data_sta&0x80);
E=0;RW=0;RS=1;CS1=0;_nop_();
E=1;_nop_();
DATA=i;
_nop_();E=0;RW=1;CS1=1;E=1;
}
/*----------------------------------------------------------------------------
Send the data to the Second ks0108 Window
------------------------------------------------------------------------------
--*/
void OutSD(uchar i)
{
unsigned char data_sta;
do{
E=0;RW=1;RS=0;CS2=0;_nop_();
E=1;_nop_();
data_sta=DATA;
E=0;RW=0;CS2=1;E=1;
}while(data_sta&0x80);
E=0;RW=0;RS=1;CS2=0;_nop_();
E=1;_nop_();
DATA=i;
_nop_();E=0;RW=1;CS2=1;E=1;
}
/*----------------------------------------------------------------------------
Send the data to the Third ks0108 Window
------------------------------------------------------------------------------
--*/
void OutTD(uchar i)
{
unsigned char data_sta;
do{
E=0;RW=1;RS=0;CS3=0;_nop_();
E=1;_nop_();
data_sta=DATA;
E=0;RW=0;CS3=1;E=1;
}while(data_sta&0x80);
E=0;RW=0;RS=1;CS3=0;_nop_();
E=1;_nop_();
DATA=i;
_nop_();E=0;RW=1;CS3=1;E=1;
}
/*----------------------------------------------------------------------------
Read the data to the First ks0108 Window
------------------------------------------------------------------------------
--*/
/*unsigned char RD_data_F()
{
unsigned char data_sta;
do{
E=0;RW=1;RS=0;CS1=0;_nop_();
E=1;_nop_();
data_sta=DATA;
E=0;RW=0;CS1=1;E=1;
}while(data_sta&0x80);
E=0;RW=1;RS=1;CS1=0;_nop_();
E=1;_nop_();_nop_();_nop_();
data_sta=DATA;
_nop_();E=0;RW=0;CS1=1;E=1;
return (data_sta);
}
/*----------------------------------------------------------------------------
Read the data to the Second ks0108 Window
------------------------------------------------------------------------------
--*/
/*unsigned char RD_data_S()
{
unsigned char data_sta;
do{
E=0;RW=1;RS=0;CS2=0;_nop_();
E=1;_nop_();_nop_();_nop_();
data_sta=DATA;
E=0;RW=0;CS2=1;E=1;
}while(data_sta&0x80);
E=0;RW=1;RS=1;CS2=0;_nop_();
E=1;_nop_();
data_sta=DATA;
_nop_();E=0;CS2=1;E=1;
return (data_sta);
}
/*----------------------------------------------------------------------------
Read the data to the Third ks0108 Window
------------------------------------------------------------------------------
--*/
/*unsigned char RD_data_T()
{
unsigned char data_sta;
do{
E=0;RW=1;RS=0;CS3=0;_nop_();
E=1;_nop_();_nop_();_nop_();
data_sta=DATA;
E=0;RW=0;CS3=1;E=1;
}while(data_sta&0x80);
E=0;RW=1;RS=1;CS3=0;_nop_();
E=1;_nop_();
data_sta=DATA;
_nop_();E=0;CS3=1;E=1;
return(data_sta);
}
/*------------------------------------------------------------------------------
Initialize the LCD,The system reset,invoke First time
--------------------------------------------------------------------------------
-*/
void InitLCD()
{
OutFI(0x40); /*Set the Y address 0 */
OutSI(0x40);
OutTI(0x40);
OutFI(0xb8); /*Set the Page 0 */
OutSI(0xb8);
OutTI(0xb8);
OutFI(0xc0); /*Set the display start line 0 */
OutSI(0xc0);
OutTI(0xc0);
OutFI(0x3f); /*Display ON */
OutSI(0x3f);
OutTI(0x3f);
}
/*------------------------------------------------------------------------------
Clear the three ks0108's display ram.
Clrscr screen
--------------------------------------------------------------------------------
-*/
void Clrscreen()
{
unsigned char i,j;
for(i=0;i<8;i++)
{
OutFI(0xb8|i);
for(j=0;j<64;j++)
{
OutFI(j|0x40);
OutFD(0);
}
}
for(i=0;i<8;i++)
{
OutSI(0xb8|i);
for(j=0;j<64;j++)
{
OutSI(j|0x40);
OutSD(0);
}
}
for(i=0;i<8;i++)
{
OutTI(0xb8|i);
for(j=0;j<64;j++)
{
OutTI(j|0x40);
OutTD(0);
}
}
}
/*------------------------------------------------------------------------------
--
Display Chinese ideograph;x_add is the x address;It has 4 layers,0,1,2,3;
Width is the Chinese ideograph width;bmp is the table's name
--------------------------------------------------------------------------------
-*/
void DrawBmp(uchar x_add,uchar layer,uchar width,uchar *bmp)
{
unsigned char x;
unsigned int i=0;
for(x=x_add;x<x_add+width;x++)
{
if (x>127) /*The Third KS0108*/
{
OutTI((x-128)|0x40); /*Set the x address*/
OutTI(layer|0xb8); /*Set the y address*/
OutTD(bmp[i]); /*Send thd data to LCD ram*/
OutTI((x-128)|0x40); /*Display the down screen*/
OutTI((layer|0xb8)+1);
i++; /*Display zimo table address add 1*/
OutTD(bmp[i]);
}
else if (x>63) /*The Second ks0108*/
{
OutSI((x-64)|0x40);
OutSI(layer|0xb8);
OutSD(bmp[i]);
OutSI((x-64)|0x40);
OutSI((layer|0xb8)+1);
i++;
OutSD(bmp[i]);
}
else /*The First ks0108*/
{
OutFI(x|0x40);
OutFI(layer|0xb8);
OutFD(bmp[i]);
OutFI(x|0x40);
OutFI((layer|0xb8)+1);
i++;
OutFD(bmp[i]);
}
i++;
}
}
/*------------------------------------------------------------------------------
--
Display Chinese ideograph;x_add is the x address;It has 4 layers,0,1,2,3;
Width is the Chinese ideograph width;bmp is the table's name.
--------------------------------------------------------------------------------
-*/
void DrawBmp_f(uchar x_add,uchar layer,uchar width,uchar *bmp)
{
unsigned char x;
unsigned int i=0;
for(x=x_add;x<x_add+width;x++)
{
if (x>127)
{
OutTI((x-128)|0x40);
OutTI(layer|0xb8);
OutTD(~bmp[i]);
OutTI((x-128)|0x40);
OutTI((layer|0xb8)+1);
i++;
OutTD(~bmp[i]);
}
else if (x>63)
{
OutSI((x-64)|0x40);
OutSI(layer|0xb8);
OutSD(~bmp[i]);
OutSI((x-64)|0x40);
OutSI((layer|0xb8)+1);
i++;
OutSD(~bmp[i]);
}
else
{
OutFI(x|0x40);
OutFI(layer|0xb8);
OutFD(~bmp[i]);
OutFI(x|0x40);
OutFI((layer|0xb8)+1);
i++;
OutFD(~bmp[i]);
}
i++;
}
}
/*------------------------------------------------------------------------------
--
Display indention; x_add is the x address;It has 4 layers,0,1,2,3;
Width is the Chinese ideograph width
--------------------------------------------------------------------------------
-*/
void _DrawBmp_(uchar x_add,uchar layer,uchar width)
{
unsigned char x;
for(x=x_add;x<x_add+width;x++)
{
if (x>127)
{
OutTI((x-128)|0x40);
OutTI(layer|0xb8);
OutTD(0);
OutTI((x-128)|0x40);
OutTI((layer|0xb8)+1);
OutTD(0);
}
else if (x>63)
{
OutSI((x-64)|0x40);
OutSI(layer|0xb8);
OutSD(0);
OutSI((x-64)|0x40);
OutSI((layer|0xb8)+1);
OutSD(0);
}
else
{
OutFI(x|0x40);
OutFI(layer|0xb8);
OutFD(0);
OutFI(x|0x40);
OutFI((layer|0xb8)+1);
OutFD(0);
}
}
}
/*------------------------------------------------------------------------------
--
Display indention; x_add is the x address;It has 4 layers,0,1,2,3;
Width is the Chinese ideograph width
--------------------------------------------------------------------------------
-*/
void _DrawBmp_black(uchar x_add,uchar layer,uchar width)
{
unsigned char x;
for(x=x_add;x<x_add+width;x++)
{
if (x>127)
{
OutTI((x-128)|0x40);
OutTI(layer|0xb8);
OutTD(0xff);
OutTI((x-128)|0x40);
OutTI((layer|0xb8)+1);
OutTD(0xff);
}
else if (x>63)
{
OutSI((x-64)|0x40);
OutSI(layer|0xb8);
OutSD(0xff);
OutSI((x-64)|0x40);
OutSI((layer|0xb8)+1);
OutSD(0xff);
}
else
{
OutFI(x|0x40);
OutFI(layer|0xb8);
OutFD(0xff);
OutFI(x|0x40);
OutFI((layer|0xb8)+1);
OutFD(0xff);
}
}
}
/*------------------------------------------------------------------------------
--
Display the line
display_data_graph is the display graph data
--------------------------------------------------------------------------------
-*/
void _DrawBmp_line(uchar x_add,uchar layer,uchar width,uchar display_data_graph)
{
unsigned char x;
unsigned int i=0;
for(x=x_add;x<x_add+width;x++)
{
if (x>127)
{
OutTI((x-128)|0x40);
OutTI(layer|0xb8);
OutTD(display_data_graph);
}
else if (x>63)
{
OutSI((x-64)|0x40);
OutSI(layer|0xb8);
OutSD(display_data_graph);
}
else
{
OutFI(x|0x40);
OutFI(layer|0xb8);
OutFD(display_data_graph);
}
i++;
}
}
/*------------------------------------------------------------------------------
--
Display the column
display_data_graph is the display graph data
--------------------------------------------------------------------------------
-*/
void _DrawBmp_column(uchar x,uchar width)
{
unsigned int i=0;
if (x>127)
{
for(i=0;i<width;i++)
{
OutTI((x-128)|0x40);
OutTI(i|0xb8);
OutTD(0xff);
}
}
else if (x>63)
{
for(i=0;i<width;i++)
{
OutSI((x-64)|0x40);
OutSI(i|0xb8);
OutSD(0xff);
}
}
else
{
for(i=0;i<width;i++)
{
OutFI(x|0x40);
OutFI(i|0xb8);
OutFD(0xff);
}
}
}
/************************************定義中文字庫***************************************/
uchar code Hzk[]={
0x00,0xF8,0x08,0x08,0x08,0x08,0x08,0xFF,0x08,0x08,0x08,0x08,0x08,0xFC,0x08,0x00, /*中*/
0x00,0x03,0x01,0x01,0x01,0x01,0x01,0xFF,0x01,0x01,0x01,0x01,0x01,0x03,0x00,0x00,
0x00,0xFE,0x02,0x0A,0x8A,0x8A,0x8A,0xFA,0x8A,0xCA,0x8E,0x0A,0x02,0xFF,0x02,0x00, /*國*/
0x00,0xFF,0x40,0x50,0x50,0x50,0x50,0x5F,0x50,0x52,0x54,0x50,0x40,0xFF,0x00,0x00,
0x24,0x24,0xA4,0xFE,0xA3,0x22,0x10,0x88,0x8C,0x57,0xE4,0x24,0x14,0x0C,0x00,0x00, /*移*/
0x04,0x02,0x01,0xFF,0x00,0x83,0x80,0x88,0x44,0x46,0x29,0x31,0x11,0x0D,0x03,0x00,
0x20,0x24,0x24,0xE4,0x26,0x34,0x20,0x10,0x10,0xFF,0x10,0x10,0x10,0xF8,0x10,0x00, /*動*/
0x08,0x1C,0x0B,0x08,0x08,0x8A,0x4C,0x30,0x0C,0x03,0x40,0x80,0x40,0x3F,0x00,0x00,
0x40,0x42,0x44,0xCC,0x00,0x00,0xF1,0x91,0x95,0xF9,0x95,0x93,0xF9,0x10,0x00,0x00, /*通*/
0x00,0x40,0x20,0x1F,0x20,0x40,0xBF,0x84,0x84,0xBF,0x94,0xA4,0x9F,0xC0,0x40,0x00,
0x80,0x40,0x20,0xF8,0x07,0x24,0x24,0x24,0x25,0x26,0x24,0x24,0xB4,0x26,0x04,0x00, /*信*/
0x00,0x00,0x00,0xFF,0x00,0x01,0xFD,0x45,0x45,0x45,0x45,0x45,0xFD,0x01,0x00,0x00,
0x20,0x10,0x08,0xFC,0x57,0x54,0x54,0xFD,0x56,0x54,0x54,0x56,0x04,0x00,0x00,0x00, /*集*/
0x04,0x44,0x44,0x27,0x15,0x0D,0x05,0xFF,0x05,0x0D,0x15,0x25,0x65,0x24,0x04,0x00,
0x00,0xFE,0x22,0x22,0x22,0x22,0xA2,0x62,0xFE,0x22,0x22,0x32,0x22,0xFF,0x02,0x00, /*團*/
0x00,0xFF,0x48,0x44,0x42,0x41,0x50,0x60,0x5F,0x40,0x40,0x40,0x40,0xFF,0x00,0x00,
0x00,0x00,0x80,0x40,0x30,0x0C,0x00,0xC0,0x06,0x18,0x20,0x40,0x80,0x80,0x80,0x00, /*公*/
0x01,0x01,0x00,0x30,0x28,0x24,0x23,0x20,0x20,0x28,0x30,0x60,0x00,0x01,0x00,0x00,
0x10,0x10,0x92,0x92,0x92,0x92,0x92,0x92,0xD2,0x9A,0x12,0x02,0xFF,0x02,0x00,0x00, /*司*/
0x00,0x00,0x3F,0x10,0x10,0x10,0x10,0x10,0x3F,0x00,0x40,0x80,0x7F,0x00,0x00,0x00
};
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -