12864图形点阵液晶显示模块51程序
扫描二维码
随时随地手机看文章
// 12864图形点阵液晶显示模块程序 (不带字库)
// 根据金鹏电子程序修改
#include
#include
#include
#define disp_off 0x3e // 显示关
#define disp_on 0x3f // 显示开
#define disp_x 0xb8 // 页地址
#define disp_z 0xc0 // 行地址
#define disp_y 0x40 // 列地址
#define comm 0 // 命令
#define dat 1 // 数据
#define lcd_bus P0 // 数据总线
sbit rs =P3^2; //数据&指令选择,H:写数据,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复位,低有效
sbit bf =P0^7; //忙闲状态标志位,H:内部正执行操作,L:空闲
sbit res=P0^4; //复位状态标志位,H:处于复位初始化状态,L:正常状态
void delayus(unsigned char us);//延时子程序us
void delayms(unsigned int ms);//延时子程序ms
void wr_lcd(unsigned char dat_comm,unsigned char content);//写数据或命令到LCD
unsigned char rd_lcd(void);//读LCD数据
void chk_busy(void);//检测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; 此字体下对应的点阵为:宽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; 此字体下对应的点阵为:宽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; 此字体下对应的点阵为:宽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; 此字体下对应的点阵为:宽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);
}
/*--------------检测LCD忙闲---------------*/
void chk_busy(void)
{
lcd_bus=0xff;
rs=0;
rw=1;
;
e=1;
while(bf||res==1);
e=0;
}
/*------------写数据或命令到LCD--------------*/
void wr_lcd(unsigned char dat_comm,unsigned char content)
{
chk_busy();
rs=dat_comm;//H:写数据,L:写指令
rw=0;
lcd_bus=content;//内容
e=1;
;
e=0;
}
/*--------------读LCD数据---------------*/
unsigned char rd_lcd(void)
{
unsigned char rd_da
chk_busy();//检测忙闲
rs=1;
rw=1;
e=1;
;
rd_da
e=0;
return rd_da
}
/*--------------写点阵------------------*/
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页
{
wr_lcd(comm,disp_x+j);//写页地址
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 个)汉字( 大小 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
// 起始页地址 起始列地址 字高/8 字宽 行数 列数 数组首地址
// x 页地址, y 列地址, xl 字高除8, yl 字宽, row_xl 行数, row_yl 列数, *chn 数组首地址
{
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页 )
{
wr_lcd(comm,disp_x+x+m*xl+j); //写页地址(从哪一页开始写)
// m*xl代表跳过m行字的页数
wr_lcd(comm,disp_z); //写起始行地址
wr_lcd(comm,disp_y+y+k*yl); //写列地址 (从哪一列开始写)
// k*yl 代表跳过k列字的列数
a=m*xl*yl*row_yl+k*xl*yl+j*yl; // a 确定从数组的哪个位置开始连续读数据
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);
}
/*---------------延时子程序us----------------*/
void delayus(unsigned char us)
{
while(--us); // 一个循环2us
}
/*---------------延时子程序ms----------------*/
void delayms(unsigned int ms) //延时 n ms
{
while(ms)
{
int i;
i=110;
while(i--);
ms=ms-1;
}
}