LCD12864程序
#include
#include
#include
#define uchar unsigned char
#define uint unsigned int
#define DPORT P3 // 命令數(shù)據(jù)輸出端口
sbit RS =P2^7 ;
sbit RW =P2^6 ;
sbit E =P2^5 ;
sbit CS2=P2^4 ;
sbit CS1=P2^3 ;
#define disp_start 0xc0//顯示起始行設(shè)置.
#define page_add 0xb8//頁面地址設(shè)置.(第 0 頁)
#define col_add 0x40//列地址設(shè)置. (第 0 列)
#define disp_on 0x3f//打開顯示.
#define disp_off 0x3e //關(guān)閉顯示.
/*--函數(shù)聲明--*/
void Led_init(void);
void Lcd_clr(void);
void Wr_com(uchar);
void Wr_dat(uchar);
void Rstatue(void);
uchar Rdat(void);
void Display_ch(uchar,uchar,uchar*); // 僅僅只能顯示 16*16 漢字
void Position(uchar,uchar);
void Draw_ph(uchar,uchar*); // 畫 128*16 的圖片 (占兩頁)
void Delay(uint);
/***********************************************************************************************/
/****************************** 主 函 數(shù) *****************************************/
void main(void)
{
Delay(50);
Led_init(); // LCD初始化
Wr_com(disp_off);//關(guān)閉顯示.
Lcd_clr(); // LCD清屏
Wr_com(disp_on); //打開顯示.
Delay(1000);
//Wr_com(disp_off);//關(guān)閉顯示.
Draw_ph(0,XTCSH);// 0 表示 頁(<7); XTCSH 圖片首地址 (128*16)
//Wr_com(disp_on); //打開顯示.
Delay(6000);
Lcd_clr(); // LCD清屏
Wr_com(disp_off);//關(guān)閉顯示.
Draw_ph(2,ZZR);
Display_ch(4,65,WANG); // 5 表示 頁(<8); 65 表示 列(<128)[相鄰兩個漢字列差為 16] ;WANG 顯示漢字首地址
Display_ch(4,81,XUE);
Display_ch(4,97,FAN);
Draw_ph(6,NYR);
Wr_com(disp_on); //打開顯示.
while(1);
}
/**********************************************************************************************/
/*---------------------- LCD12864 顯示部分 (控制芯片 KS0108 )---------------------------*/
/**********************************************************************************************/
/*----------------LCD初始化-------------------------------------*/
void Led_init(void)
{
P2=0;
Wr_com(disp_start);//顯示起始行設(shè)置.
Wr_com(page_add);//頁面地址設(shè)置.
Wr_com(col_add);//列地址設(shè)置.
Wr_com(disp_on);//打開顯示.
}
/*---------------------LCD清屏---------------------------------*/
void Lcd_clr(void)
{
uchar page,col;
CS1=0;
CS2=0;
for (page=0;page<8;page++)
{
Wr_com(page_add | page);
Wr_com(col_add);
for (col=0;col<64;col++) Wr_dat(0x00);//列地址自動加一.
}
}
/*---------------------寫命令----------------------------------*/
void Wr_com(uchar c)
{
Rstatue();
RS=0;
RW=0;
DPORT=c; // "寫" (下降沿有效)
E=1;
E=0;
}
/*---------------------寫數(shù)據(jù)----------------------------------*/
void Wr_dat(uchar c)
{
Rstatue();
RS=1;
RW=0;
DPORT=c; // "寫" (下降沿有效)
E=1;
E=0;
}
/*----------------------讀狀態(tài)---------------------------------*/
void Rstatue(void)
{
uchar da
DPORT=0xff;
RS=0;
RW=1;
while(1) // 有必要讓 E 的上升沿在循環(huán)體中
{
E=0;
temp=(DPORT&0x90); // "讀" (上升沿有效)
E=1;
if(temp==0) break;
}
E=0;
}
/*-----------------------讀數(shù)據(jù)--------------------------------*/
/*uchar Rdat(void)
{
uchar da
Rstatue();
RS=1;
RW=1;
temp=DPORT; // "讀" (上升沿有效)
E=0;
E=1;
return temp;
}
/*----------------------單個顯示漢字程序( 16*16 )----------------------------*/
void Display_ch(uchar page,uchar col,uchar *p)
{
uchar i,j,X,Y;
X=page;
Y=col;
CS1=0;
CS2=1;
for(j=0;j<2;j++)
{
for(i=0;i<16;i++)
{
if(Y>63) // 到了右便半屏幕
{
Y=Y-64 ;
CS1=1 ;
CS2=0 ;
}
if(i<1||Y!=0) Position(X,Y);
Wr_dat(*p); // 列 自動加 1
Y++;
p++;
}
X++;
Y=col;
}
CS1=0;
CS2=0;
}
/*---------------------定位顯示坐標(biāo)---------------------*/
void Position(uchar page,uchar col)
{
uchar X,Y; // X 表示行, Y 表示列
X= page | page_add ;
Y= col | col_add ;
Wr_com(X) ;
Wr_com(Y) ;
}
/*------------------ 畫圖程序(128*16 ; 二頁) -------------------*/
void Draw_ph(uchar page,uchar *p)
{
uchar i,j;
uchar temp=page;
for(j=0;j<2;j++)
{
CS1=0; // 左半屏幕
CS2=1;
Wr_com(page_add|temp);
Wr_com(col_add);
for(i=0;i<64;i++)
{
Wr_dat(*p); // 列 自動加 1
p++;
}
CS1=1; // 右半屏幕
CS2=0;
Wr_com(page_add|temp);
Wr_com(col_add);
for(i=0;i<64;i++)
{
Wr_dat(*p); // 列 自動加 1
p++;
}
temp++;
}
CS1=0;
CS2=0;
}
/*---------------------延時程序-------------------------*/
void Delay(uint delay)
{
uchar da
while(delay)
{
for(i=0;i<125;i++) {;}
delay--;
}
}
/**********************************************************************************************/
/***************************************************************************************************************/
/* 漢 字 字 模(下面代碼保存為Zhiku.h文件)
/***************************************************************************************************************/
#define uchar unsigned char
// " 制作人: "
uchar co
0x80,0x40,0x20,0xF8,0x07,0x22,0x18,0x0C,0xFB,0x48,0x48,0x48,0x68,0x48,0x08,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0x3F,0xC2,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, //
0x00,0x00,0x3F,0x01,0x01,0xFF,0x21,0x61,0x3F,0x00,0x0F,0x40,0x80,0x7F,0x00,0x00,
0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0xFF,0x04,0x04,0x04,0x04,0x06,0x04,0x00,
0x00,0x40,0x20,0x10,0x0C,0x03,0x00,0x00,0x01,0x06,0x0C,0x18,0x30,0x60,0x20,0x00,
0x00,0x00,0x36,0x36,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 };
// 系統(tǒng)初始化
uchar co
0x20,0x30,0x2C,0xA3,0x60,0x10,0x84,0xC4,0xA4,0x9D,0x86,0x84,0xA4,0xC4,0x84,0x00,
0x00,0x08,0x88,0xC9,0x2E,0x98,0x48,0x00,0x08,0x08,0xF8,0x08,0x08,0xFC,0x08,0x00,
0x10,0x90,0x70,0x1F,0x12,0xF0,0x00,0x20,0x70,0x28,0x27,0x22,0x28,0x70,0x20,0x00,
0x80,0x40,0x20,0xF8,0x07,0x02,0x00,0x00,0xFF,0xC0,0x60,0x30,0x1C,0x08,0x00,0x00,
0x00,0x00,0xFC,0x08,0x08,0x08,0x08,0xFF,0x08,0x08,0x08,0x08,0xFC,0x08,0x00,0x00,
0x00,0xC0,0xC0,0x00,0x00,0x00,0xC0,0xC0,0x00,0x00,0x00,0xC0,0xC0,0x00,0x00,0x00,
0x00,0xC0,0xC0,0x00,0x00,0x00,0xC0,0xC0,0x00,0x00,0x00,0xC0,0xC0,0x00,0x00,0x00,
0x00,0x40,0x21,0x13,0x09,0x05,0x41,0x81,0x7F,0x01,0x05,0x09,0x13,0x62,0x00,0x00,
0x20,0x22,0x23,0x12,0x12,0x92,0x40,0x30,0x0F,0x00,0x00,0x3F,0x40,0x41,0x70,0x00,
0x02,0x01,0x00,0x7F,0x01,0x02,0x44,0x20,0x10,0x0C,0x03,0x20,0x40,0x3F,0x00,0x00,
0x40,0x21,0x12,0x0C,0x06,0x09,0x30,0x00,0x7F,0x21,0x21,0x21,0x21,0x7F,0x00,0x00,
0x00,0x00,0x00,0x7F,0x00,0x04,0x02,0x01,0x3F,0x40,0x40,0x40,0x40,0x78,0x00,0x00,
0x00,0x00,0x07,0x02,0x02,0x02,0x02,0xFF,0x02,0x02,0x02,0x02,0x07,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,};
// 2008.08.16
uchar co
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,
0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,
0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00,
0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00,
0x00,0x30,0x30,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00,
0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00,0x00,0x30,0x30,0x00,0x00,0x00,0x00,0x00,
0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00};
// " 王 "
uchar co
0x40,0x40,0x41,0x41,0x41,0x41,0x41,0x7F,0x41,0x41,0x41,0x41,0x41,0x61,0x40,0x00};
// " 雪 "
uchar co
0x00,0x00,0x42,0x4A,0x4A,0x4A,0x4A,0x4A,0x4A,0x4A,0x4A,0x4A,0xFE,0x00,0x00,0x00};
// " 凡 "
uchar co
0x00,0x40,0x20,0x10,0x0F,0x00,0x00,0x00,0x00,0x00,0x3F,0x40,0x40,0x40,0x70,0x00 };
/**********************************************************************************************/
評論