基于89C51的LCM12832模块128X64点阵液晶应用(验证OK)
扫描二维码
随时随地手机看文章
/********************************************************
**这个程序是时钟程序用LCM12832作为显示.
**P1口作为键盘输入P1.0=增加键;P11为选择键
**时钟显示格式为:“时:分:秒”字体为16*16点阵
**修改方式为两键式选择键合修改键
**还可显示万年历:“年:月:日”
**需要子函数
**1、HEX->BCD子函数hex_bcd()
**2、显示子函数display()
**3、键盘子函数key()
**4、时钟子函数time()
**5、日历子函数day()
**6、显示控制子函数discommond()
**7、定时器中断0time0()
**8、初始化子函数 begin().
**9、初始屏显display_begin().
**10、时间屏显display_time().
**11、润年判断leapf().
**现有问题:键盘修改程序还未完成
**程序不够精简
*********************************************************/
#include
#define time_TH 0x3c;// time0 :50ms 12M
#define time_TL 0xba;
unsigned char data msecond=0;
bit data second_flag=0,day_flag=0,leap=0,display_flag=0,ku_flag;
unsigned char day_temp;
struct time_str{
unsigned char hour;
unsigned char minute;
unsigned char second;
}time_now;
struct day_str{
unsigned int year;
unsigned char month;
unsigned char day;
}day_now;
//显示缓冲区
unsigned char data display_bcd[13];
//每月天数表
unsigned char code day_num[]=
{31,28,31,30,31,30,31,31,30,31,30,31};
//时间显示位置表
unsigned char code time_LOC[][1]=
{0,2,0,3,0,4,0,5,0,8,0,9,0,12,0,13
,16,4,16,5,16,8,16,9,16,12,16,13};
//汉字显示位置表
//指定位置显示“年,月,日,时,分,秒”
unsigned char code zhi_loc[]=
{0x06,0x01,0x0a,0x01,0x0e,0x01,0x06,0x10,0x0a,0x10,0x0e,0x10};
/********************************************************************
**字库开始
**********************************************************************/
unsigned char code shi[]={
/*-- 文字: 年 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x08,0x00,0x0F,0xFC,0x10,0x80,0x10,0x80,0x20,0x80,0x4F,0xF8,0x88,0x80,0x08,0x80,
0x08,0x80,0x08,0x80,0xFF,0xFE,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80,
/*-- 文字: 月 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x07,0xF0,0x04,0x10,0x04,0x10,0x04,0x10,0x07,0xF0,0x04,0x10,0x04,0x10,0x04,0x10,
0x07,0xF0,0x04,0x10,0x08,0x10,0x08,0x10,0x10,0x10,0x20,0x50,0x40,0x20,0x00,0x00,
/*-- 文字: 日 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x00,0x00,0x1F,0xF0,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x1F,0xF0,0x10,0x10,
0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x1F,0xF0,0x10,0x10,0x00,0x00,0x00,0x00,
/*-- 文字: 时 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x00,0x10,0x00,0x10,0x7C,0x10,0x44,0x10,0x47,0xFE,0x44,0x10,0x7C,0x10,0x45,0x10,
0x44,0x90,0x44,0x90,0x7C,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x50,0x00,0x20,
/*-- 文字: 分 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x08,0x80,0x0C,0x80,0x08,0x40,0x10,0x20,0x10,0x30,0x20,0x18,0x40,0x0E,0x9F,0xE4,
0x04,0x20,0x04,0x20,0x04,0x20,0x04,0x20,0x08,0x20,0x10,0xA0,0x20,0x40,0x40,0x00,
/*-- 文字: 秒 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x0C,0x20,0xF0,0x20,0x10,0x20,0x11,0x28,0xFD,0xA4,0x11,0x22,0x32,0x22,0x3A,0x20,
0x54,0x22,0x54,0x22,0x90,0x04,0x10,0x08,0x10,0x10,0x10,0x60,0x11,0x80,0x16,0x00};
unsigned char code num[]={
/*-- 文字: 0 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0x00,0x00,0x18,0x24,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x24,0x18,0x00,0x00,
/*-- 文字: 1 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0x00,0x00,0x10,0x70,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x7C,0x00,0x00,
/*-- 文字: 2 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0x00,0x00,0x3C,0x42,0x42,0x42,0x04,0x04,0x08,0x10,0x20,0x42,0x7E,0x00,0x00,
/*-- 文字: 3 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0x00,0x00,0x3C,0x42,0x42,0x04,0x18,0x04,0x02,0x02,0x42,0x44,0x38,0x00,0x00,
/*-- 文字: 4 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0x00,0x00,0x04,0x0C,0x14,0x24,0x24,0x44,0x44,0x7E,0x04,0x04,0x1E,0x00,0x00,
/*-- 文字: 5 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0x00,0x00,0x7E,0x40,0x40,0x40,0x58,0x64,0x02,0x02,0x42,0x44,0x38,0x00,0x00,
/*-- 文字: 6 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0x00,0x00,0x1C,0x24,0x40,0x40,0x58,0x64,0x42,0x42,0x42,0x24,0x18,0x00,0x00,
/*-- 文字: 7 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0x00,0x00,0x7E,0x44,0x44,0x08,0x08,0x10,0x10,0x10,0x10,0x10,0x10,0x00,0x00,
/*-- 文字: 8 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0x00,0x00,0x3C,0x42,0x42,0x42,0x24,0x18,0x24,0x42,0x42,0x42,0x3C,0x00,0x00,
/*-- 文字: 9 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0x00,0x00,0x18,0x24,0x42,0x42,0x42,0x26,0x1A,0x02,0x02,0x24,0x38,0x00,0x00,
/*-- 文字: 0 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/
0xFF,0xFF,0xFF,0xE7,0xDB,0xBD,0xBD,0xBD,0xBD,0xBD,0xBD,0xBD,0xDB,0xE7,0xFF,0xFF,
/*-- 文字: 1 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/
0xFF,0xFF,0xFF,0xEF,0x8F,0xEF,0xEF,0xEF,0xEF,0xEF,0xEF,0xEF,0xEF,0x83,0xFF,0xFF,
/*-- 文字: 2 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/
0xFF,0xFF,0xFF,0xC3,0xBD,0xBD,0xBD,0xFB,0xFB,0xF7,0xEF,0xDF,0xBD,0x81,0xFF,0xFF,
/*-- 文字: 3 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/
0xFF,0xFF,0xFF,0xC3,0xBD,0xBD,0xFB,0xE7,0xFB,0xFD,0xFD,0xBD,0xBB,0xC7,0xFF,0xFF,
/*-- 文字: 4 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/
0xFF,0xFF,0xFF,0xFB,0xF3,0xEB,0xDB,0xDB,0xBB,0xBB,0x81,0xFB,0xFB,0xE1,0xFF,0xFF,
/*-- 文字: 5 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/
0xFF,0xFF,0xFF,0x81,0xBF,0xBF,0xBF,0xA7,0x9B,0xFD,0xFD,0xBD,0xBB,0xC7,0xFF,0xFF,
/*-- 文字: 6 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/
0xFF,0xFF,0xFF,0xE3,0xDB,0xBF,0xBF,0xA7,0x9B,0xBD,0xBD,0xBD,0xDB,0xE7,0xFF,0xFF,
/*-- 文字: 7 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/
0xFF,0xFF,0xFF,0x81,0xBB,0xBB,0xF7,0xF7,0xEF,0xEF,0xEF,0xEF,0xEF,0xEF,0xFF,0xFF,
/*-- 文字: 8 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/
0xFF,0xFF,0xFF,0xC3,0xBD,0xBD,0xBD,0xDB,0xE7,0xDB,0xBD,0xBD,0xBD,0xC3,0xFF,0xFF,
/*-- 文字: 9 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/
0xFF,0xFF,0xFF,0xE7,0xDB,0xBD,0xBD,0xBD,0xD9,0xE5,0xFD,0xFD,0xDB,0xC7,0xFF,0xFF,
};
unsigned char code ku[]={
/*-- 调入了一幅图像:这是哭的的图像 --*/
/*-- 宽度x高度=16x16 --*/
0x03,0xC0,0x0C,0x30,0x10,0x08,0x20,0x04,0x40,0x02,0x52,0x4A,0x8C,0x31,0x80,0x01,
0x80,0x01,0x81,0x81,0x42,0x42,0x44,0x22,0x20,0x04,0x10,0x08,0x0C,0x30,0x03,0xC0,
/*-- 调入了一幅图像:这是笑的的图像 --*/
/*-- 宽度x高度=16x16 --*/
0x03,0xC0,0x0C,0x30,0x10,0x08,0x20,0x04,0x40,0x02,0x40,0x02,0x8C,0x31,0x92,0x49,
0x80,0x01,0x80,0x01,0x44,0x22,0x42,0x42,0x21,0x84,0x10,0x08,0x0C,0x30,0x03,0xC0
};
/*****************************************************************************
**字库结束
******************************************************************************/
void day();
void time();
void begin();
void display(unsigned char *cpoint,unsigned char x_line,unsigned char y_line,unsigned char s_l);
unsigned char hex_bcd(unsigned char hex);
void display_begin();
void display_time(struct time_str time,struct day_str day);
bit leapf(unsigned int year);
void main()
{
begin();
display_begin();
while (1)
{
while (1)
{
time();
day();
if (display_flag)
{
display_flag=0;
display_time(time_now,day_now);
}
if (display_flag)
continue;
if((day_now.month==2)&leap)
{
leap=0;
day_temp=29;
}
}
}
}
/******************************************************
**time()子函数
**参数:second_flay
**
******************************************************/
void time(){
if(second_flag){
display_flag=1;
second_flag=0;
//day_flag=1;
time_now.second++;
if(time_now.second==60){
time_now.second=0;
time_now.minute++;
if(time_now.minute==60){
time_now.minute=0;
time_now.hour++;
if(time_now.hour==24){
time_now.hour=0;
day_flag=1;
}
}
}
}
}