12864圖形點(diǎn)陣液晶顯示模塊51程序
掃描二維碼
隨時(shí)隨地手機(jī)看文章
// 12864圖形點(diǎn)陣液晶顯示模塊程序 (不帶字庫(kù))
// 根據(jù)金鵬電子程序修改
#include
#include
#include
#define disp_off 0x3e // 顯示關(guān)
#define disp_on 0x3f // 顯示開
#define disp_x 0xb8 // 頁(yè)地址
#define disp_z 0xc0 // 行地址
#define disp_y 0x40 // 列地址
#define comm 0 // 命令
#define dat 1 // 數(shù)據(jù)
#define lcd_bus P0 // 數(shù)據(jù)總線
sbit rs =P3^2; //數(shù)據(jù)&指令選擇,H:寫數(shù)據(jù),L:寫指令
sbit rw =P3^3; //讀&寫選擇,H:read,L:write
sbit e =P3^4; //讀寫使能
sbit cs1=P3^0; //cs1=H,選擇左半屏
sbit cs2=P3^1; //cs2=H,選擇右半屏
sbit rst=P3^5; //LCD復(fù)位,低有效
sbit bf =P0^7; //忙閑狀態(tài)標(biāo)志位,H:內(nèi)部正執(zhí)行操作,L:空閑
sbit res=P0^4; //復(fù)位狀態(tài)標(biāo)志位,H:處于復(fù)位初始化狀態(tài),L:正常狀態(tài)
void delayus(unsigned char us);//延時(shí)子程序us
void delayms(unsigned int ms);//延時(shí)子程序ms
void wr_lcd(unsigned char dat_comm,unsigned char content);//寫數(shù)據(jù)或命令到LCD
unsigned char rd_lcd(void);//讀LCD數(shù)據(jù)
void chk_busy(void);//檢測(cè)LCD忙閑
void lat_disp(unsigned char da
void chn_disp(unsigned char x,unsigned char y,unsigned char xl,unsigned char yl,unsigned char row_xl,unsigned char row_yl,unsigned char co
void init_lcd (void);//LCD初始化
void disp1(void);
unsigned char co
/*-- 宋體12; 此字體下對(duì)應(yīng)的點(diǎn)陣為:寬x高=16x16 --*/
/*-- 文字: 金 --*/
0x40,0x40,0x20,0x20,0x50,0x48,0x44,0xC3,0x44,0x48,0x50,0x50,0x20,0x60,0x20,0x00,
0x40,0x40,0x42,0x42,0x4A,0x72,0x42,0x7F,0x42,0x62,0x5A,0x42,0x42,0x40,0x40,0x00,
/*-- 文字: 鵬 --*/
0x00,0xFE,0x12,0xFE,0x00,0xFE,0x12,0xFE,0x00,0xFC,0x0E,0x35,0x44,0x7C,0x00,0x00,
0x20,0x1F,0x21,0x7F,0x20,0x1F,0x41,0x7F,0x08,0x09,0x09,0x29,0x49,0x21,0x1F,0x00,
/*-- 文字: 科 --*/
0x10,0x12,0x92,0x72,0xFE,0x51,0x91,0x00,0x22,0xCC,0x00,0x00,0xFF,0x00,0x00,0x00,
0x04,0x02,0x01,0x00,0xFF,0x00,0x04,0x04,0x04,0x02,0x02,0x02,0xFF,0x01,0x01,0x00,
/*-- 文字: 技 --*/
0x08,0x08,0x88,0xFF,0x48,0x28,0x00,0xC8,0x48,0x48,0x7F,0x48,0xC8,0x48,0x08,0x00,
0x01,0x41,0x80,0x7F,0x00,0x40,0x40,0x20,0x13,0x0C,0x0C,0x12,0x21,0x60,0x20,0x00,
/*-- 文字: 奧 --*/
0xFF,0xFF,0x01,0xDD,0xD5,0x4D,0x9C,0x01,0x9D,0x4D,0x55,0xDD,0x01,0xFF,0xFF,0xFF,
0x7F,0x7B,0xBA,0xBB,0xDA,0xEB,0xF3,0xF8,0xF3,0xEB,0xDA,0xDB,0xBA,0x3B,0xBB,0xFF,
/*-- 文字: 可 --*/
0xFF,0xFD,0xFD,0x0D,0xED,0xED,0xED,0xED,0x0D,0xFD,0xFD,0xFD,0x01,0xFD,0xFD,0xFF,
0xFF,0xFF,0xFF,0xF8,0xFD,0xFD,0xFD,0xFD,0xF8,0xEF,0xDF,0xBF,0xC0,0xFF,0xFF,0xFF,
/*-- 文字: 拉 --*/
0xEF,0xEF,0xEF,0x00,0x6F,0xAF,0xFF,0xB7,0x76,0xF5,0xF1,0xF7,0x17,0xB7,0xF7,0xFF,
0xFD,0xBD,0x7E,0x80,0xFF,0xDF,0xDF,0xDF,0xDE,0xC1,0xDF,0xC3,0xDC,0xDF,0xDF,0xFF,
/*-- 文字: 液 --*/
0xEF,0x9E,0xF9,0x1F,0xE7,0x7B,0x1B,0xE3,0x7B,0x9A,0x41,0xDB,0x5B,0x9B,0xFB,0xFF,
0xFB,0xFB,0x00,0xFF,0xFE,0xFF,0x00,0xBE,0xDE,0xED,0xF3,0xE4,0x9E,0x3F,0xBF,0xFF};
unsigned char co
/*-- 宋體12; 此字體下對(duì)應(yīng)的點(diǎn)陣為:寬x高=16x16 --*/
/*-- 文字: 有 --*/
0x00,0x04,0x84,0x44,0xE4,0x34,0x2C,0x27,0x24,0x24,0x24,0xE4,0x04,0x04,0x04,0x00,
0x02,0x01,0x00,0x00,0xFF,0x09,0x09,0x09,0x29,0x49,0xC9,0x7F,0x00,0x00,0x00,0x00,
/*-- 文字: 限 --*/
0xFE,0x02,0x32,0x4E,0x82,0x00,0xFE,0x4A,0xCA,0x4A,0x4A,0x4A,0x7E,0x00,0x00,0x00,
0xFF,0x00,0x02,0x04,0x03,0x00,0xFF,0x40,0x20,0x03,0x0C,0x12,0x21,0x60,0x20,0x00,
/*-- 文字: 公 --*/
0x00,0x00,0x80,0x40,0x30,0x0E,0x84,0x00,0x00,0x0E,0x10,0x60,0xC0,0x80,0x80,0x00,
0x00,0x01,0x20,0x70,0x28,0x24,0x23,0x31,0x10,0x10,0x14,0x78,0x30,0x01,0x00,0x00,
/*-- 文字: 司 --*/
0x00,0x10,0x92,0x92,0x92,0x92,0x92,0x92,0x92,0x92,0x12,0x02,0x02,0xFE,0x00,0x00,
0x00,0x00,0x1F,0x04,0x04,0x04,0x04,0x04,0x04,0x0F,0x00,0x20,0x40,0x3F,0x00,0x00,
/*-- 文字: 晶 --*/
0xFF,0xFF,0xFF,0xFF,0x81,0xD5,0xD5,0xD5,0xD5,0xD5,0xD5,0x81,0xFF,0xFF,0xFF,0xFF,
0xFF,0x80,0xDA,0xDA,0xDA,0xDA,0x80,0xFF,0xFF,0x80,0xDA,0xDA,0xDA,0xDA,0x80,0xFF,
/*-- 文字: 顯 --*/
0xFF,0xFF,0xFF,0xC1,0xD5,0x15,0xD5,0xD5,0xD5,0x15,0xD5,0xC1,0xFF,0xFF,0xFF,0xFF,
0xDF,0xDE,0xDD,0xD3,0xDF,0xC0,0xDF,0xDF,0xDF,0xC0,0xD7,0xDB,0xDC,0xDF,0xDF,0xFF,
/*-- 文字: 示 --*/
0xFF,0xDF,0xDF,0xDD,0xDD,0xDD,0xDD,0x1D,0xDD,0xDD,0xDD,0xDD,0xDD,0xDF,0xDF,0xFF,
0xEF,0xF7,0xFB,0xFC,0xFF,0xBF,0x7F,0x80,0xFF,0xFF,0xFE,0xFD,0xF3,0xE7,0xFF,0xFF,
/*-- 文字: 器 --*/
0xBF,0xBF,0xB0,0xB6,0xB6,0x36,0x30,0x8F,0x3F,0x30,0xB6,0xA6,0x96,0xB0,0xFF,0xFF,
0xFD,0xFD,0x81,0xBA,0xBA,0xBB,0x83,0xFF,0x83,0xBB,0xBA,0xBA,0x81,0xF9,0xFD,0xFF};
unsigned char co
/*-- 宋體12; 此字體下對(duì)應(yīng)的點(diǎn)陣為:寬x高=8x16 --*/
/*-- 文字: G --*/
0xC0,0x30,0x08,0x08,0x08,0x38,0x00,0x00,0x07,0x18,0x20,0x20,0x22,0x1E,0x02,0x00,
/*-- 文字: o --*/
0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00,
/*-- 文字: l --*/
0x00,0x08,0x08,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,
/*-- 文字: d --*/
0x00,0x00,0x00,0x80,0x80,0x88,0xF8,0x00,0x00,0x0E,0x11,0x20,0x20,0x10,0x3F,0x20,
/*-- 文字: e --*/
0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x22,0x22,0x22,0x22,0x13,0x00,
/*-- 文字: n --*/
0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20,
/*-- 文字: --*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*-- 文字: P --*/
0x08,0xF8,0x08,0x08,0x08,0x08,0xF0,0x00,0x20,0x3F,0x21,0x01,0x01,0x01,0x00,0x00,
/*-- 文字: T --*/
0xE7,0xF7,0xF7,0x07,0xF7,0xF7,0xE7,0xFF,0xFF,0xFF,0xDF,0xC0,0xDF,0xFF,0xFF,0xFF,
/*-- 文字: E --*/
0xF7,0x07,0x77,0x77,0x17,0xF7,0xEF,0xFF,0xDF,0xC0,0xDF,0xDF,0xDC,0xDF,0xE7,0xFF,
/*-- 文字: L --*/
0xF7,0x07,0xF7,0xFF,0xFF,0xFF,0xFF,0xFF,0xDF,0xC0,0xDF,0xDF,0xDF,0xDF,0xCF,0xFF,
/*-- 文字: : --*/
0xFF,0xFF,0xFF,0x3F,0x3F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xCF,0xCF,0xFF,0xFF,0xFF,
/*-- 文字: 0 --*/
0xFF,0x1F,0xEF,0xF7,0xF7,0xEF,0x1F,0xFF,0xFF,0xF0,0xEF,0xDF,0xDF,0xEF,0xF0,0xFF,
/*-- 文字: 7 --*/
0xFF,0xC7,0xF7,0xF7,0x37,0xC7,0xF7,0xFF,0xFF,0xFF,0xFF,0xC0,0xFF,0xFF,0xFF,0xFF,
/*-- 文字: 5 --*/
0xFF,0x07,0xF7,0x77,0x77,0xF7,0xF7,0xFF,0xFF,0xE6,0xDE,0xDF,0xDF,0xEE,0xF1,0xFF,
/*-- 文字: 8 --*/
0xFF,0x8F,0x77,0xF7,0xF7,0x77,0x8F,0xFF,0xFF,0xE3,0xDD,0xDE,0xDE,0xDD,0xE3,0xFF};
unsigned char co
/*-- 宋體12; 此字體下對(duì)應(yīng)的點(diǎn)陣為:寬x高=8x16 --*/
/*-- 文字: a --*/
0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x19,0x24,0x22,0x22,0x22,0x3F,0x20,
/*-- 文字: l --*/
0x00,0x08,0x08,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,
/*-- 文字: m --*/
0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x20,0x3F,0x20,0x00,0x3F,0x20,0x00,0x3F,
/*-- 文字: --*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*-- 文字: T --*/
0x18,0x08,0x08,0xF8,0x08,0x08,0x18,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00,
/*-- 文字: E --*/
0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x20,0x3F,0x20,0x20,0x23,0x20,0x18,0x00,
/*-- 文字: C --*/
0xC0,0x30,0x08,0x08,0x08,0x08,0x38,0x00,0x07,0x18,0x20,0x20,0x20,0x10,0x08,0x00,
/*-- 文字: H --*/
0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,0x20,0x3F,0x21,0x01,0x01,0x21,0x3F,0x20,
/*-- 文字: - --*/
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,
/*-- 文字: 2 --*/
0xFF,0x8F,0xF7,0xF7,0xF7,0x77,0x8F,0xFF,0xFF,0xCF,0xD7,0xDB,0xDD,0xDE,0xCF,0xFF,
/*-- 文字: 2 --*/
0xFF,0x8F,0xF7,0xF7,0xF7,0x77,0x8F,0xFF,0xFF,0xCF,0xD7,0xDB,0xDD,0xDE,0xCF,0xFF,
/*-- 文字: 6 --*/
0xFF,0x1F,0xEF,0x77,0x77,0xE7,0xFF,0xFF,0xFF,0xF0,0xEE,0xDF,0xDF,0xEE,0xF1,0xFF,
/*-- 文字: 3 --*/
0xFF,0xCF,0xF7,0x77,0x77,0xB7,0xCF,0xFF,0xFF,0xE7,0xDF,0xDF,0xDF,0xEE,0xF1,0xFF,
/*-- 文字: 8 --*/
0xFF,0x8F,0x77,0xF7,0xF7,0x77,0x8F,0xFF,0xFF,0xE3,0xDD,0xDE,0xDE,0xDD,0xE3,0xFF,
/*-- 文字: 5 --*/
0xFF,0x07,0xF7,0x77,0x77,0xF7,0xF7,0xFF,0xFF,0xE6,0xDE,0xDF,0xDF,0xEE,0xF1,0xFF,
/*-- 文字: 8 --*/
0xFF,0x8F,0x77,0xF7,0xF7,0x77,0x8F,0xFF,0xFF,0xE3,0xDD,0xDE,0xDE,0xDD,0xE3,0xFF};
void main()
{
delayms(200);
init_lcd(); //LCD初始化
while(1)
{
lat_disp(0xff,0x00);
delayms(1000); //1秒
disp1(); //顯示一屏字
delayms(1000); //1秒
}
}
/*------------------LCD初始化-----------------*/
void init_lcd(void)
{
rst=0;
delayus(50);
rst=1;
cs1=1;cs2=1;
wr_lcd(comm,disp_off);
wr_lcd(comm,disp_on);
}
/*--------------檢測(cè)LCD忙閑---------------*/
void chk_busy(void)
{
lcd_bus=0xff;
rs=0;
rw=1;
;
e=1;
while(bf||res==1);
e=0;
}
/*------------寫數(shù)據(jù)或命令到LCD--------------*/
void wr_lcd(unsigned char dat_comm,unsigned char content)
{
chk_busy();
rs=dat_comm;//H:寫數(shù)據(jù),L:寫指令
rw=0;
lcd_bus=content;//內(nèi)容
e=1;
;
e=0;
}
/*--------------讀LCD數(shù)據(jù)---------------*/
unsigned char rd_lcd(void)
{
unsigned char rd_da
chk_busy();//檢測(cè)忙閑
rs=1;
rw=1;
e=1;
;
rd_da
e=0;
return rd_da
}
/*--------------寫點(diǎn)陣------------------*/
void lat_disp(unsigned char da
{
unsigned char i,j;
cs1=1;cs2=1; //左半屏有效,右半屏有效
wr_lcd(comm,disp_on);// 開顯示
for(j=0;j<8;j++) //8頁(yè)
{
wr_lcd(comm,disp_x+j);//寫頁(yè)地址
wr_lcd(comm,disp_z); //寫起始行地址
wr_lcd(comm,disp_y); //寫列地址
for(i=0;i<32;i++) //寫32次,1次兩列
{
wr_lcd(dat,da
wr_lcd(dat,da
}
}
}
/*---指定位置(x,y)顯示 row_xl 行(每行 row_yl 個(gè))漢字( 大小 8xl * yl )---*/
void chn_disp(unsigned char x,unsigned char y,unsigned char xl,unsigned char yl,unsigned char row_xl,unsigned char row_yl,unsigned char co
// 起始頁(yè)地址 起始列地址 字高/8 字寬 行數(shù) 列數(shù) 數(shù)組首地址
// x 頁(yè)地址, y 列地址, xl 字高除8, yl 字寬, row_xl 行數(shù), row_yl 列數(shù), *chn 數(shù)組首地址
{
unsigned char i,j,k,m,a;
wr_lcd(comm,disp_on); //開顯示
for(m=0;m
for(k=0;k
for(j=0;j
// 字高 8行,xl=1,要寫1頁(yè) )
{
wr_lcd(comm,disp_x+x+m*xl+j); //寫頁(yè)地址(從哪一頁(yè)開始寫)
// m*xl代表跳過(guò)m行字的頁(yè)數(shù)
wr_lcd(comm,disp_z); //寫起始行地址
wr_lcd(comm,disp_y+y+k*yl); //寫列地址 (從哪一列開始寫)
// k*yl 代表跳過(guò)k列字的列數(shù)
a=m*xl*yl*row_yl+k*xl*yl+j*yl; // a 確定從數(shù)組的哪個(gè)位置開始連續(xù)讀數(shù)據(jù)
for(i=0;i
}
}
}
}
/*---------------顯示1-----------------*/
void disp1(void)
{
lat_disp(0x00,0x00); //清屏
cs1=1;cs2=0;
chn_disp(0,0,2,16,2,4,hz11);
cs1=0;cs2=1;
chn_disp(0,0,2,16,2,4,hz12);
cs1=1;cs2=0;
chn_disp(4,0,2,8,2,8,hz31);
cs1=0;cs2=1;
chn_disp(4,0,2,8,2,8,hz32);
}
/*---------------延時(shí)子程序us----------------*/
void delayus(unsigned char us)
{
while(--us); // 一個(gè)循環(huán)2us
}
/*---------------延時(shí)子程序ms----------------*/
void delayms(unsigned int ms) //延時(shí) n ms
{
while(ms)
{
int i;
i=110;
while(i--);
ms=ms-1;
}
}