LCD12864万年历单片机程序+实物制作+Proteus仿真
2019-11-29 来源:51hei
制作出来的LCD12864万年历实物图如下:
LCD12864万年历仿真原理图如下(proteus仿真工程文件可到本帖附件中下载)
电路原理图如下:
单片机源程序如下:
*-----------------------------------------------
名称:12864字库液晶显示
内容:通过显示字符、数字、汉字和图片测试液晶基本功能
------------------------------------------------*/
#include #include #include 'delay.h' sbit RS = P3^5; sbit RW = P3^6; sbit E = P3^4; sbit RES = P1^7; sbit PSB = P1^6; sbit beep = P2^3; #define DataPort P0 //MCU P0<------> LCM // typedef unsigned char U8; /* defined for unsigned 8-bits integer variable 无符号8位整型变量 */ typedef signed char S8; /* defined for signed 8-bits integer variable 有符号8位整型变量 */ typedef unsigned int U16; /* defined for unsigned 16-bits integer variable 无符号16位整型变量 */ typedef signed int S16; /* defined for signed 16-bits integer variable 有符号16位整型变量 */ typedef unsigned long U32; /* defined for unsigned 32-bits integer variable 无符号32位整型变量 */ typedef signed long S32; /* defined for signed 32-bits integer variable 有符号32位整型变量 */ typedef float F32; /* single precision floating point variable (32bits) 单精度浮点数(32位长度) */ typedef double F64; /* double precision floating point variable (64bits) 双精度浮点数(64位长度) */ // #define uchar unsigned char #define uint unsigned int #define Data_0_time 4 //----------------------------------------------// //----------------IO口定义区--------------------// //----------------------------------------------// sbit P2_0 = P2^0 ; //----------------------------------------------// //----------------定义区--------------------// //----------------------------------------------// U8 U8FLAG,k; U8 U8count,U8temp; U8 U8T_data_H,U8T_data_L,U8RH_data_H,U8RH_data_L,U8checkdata; U8 U8comdata; U8 count; U8 flag; U8 jishi_flag = 0,count_up = 0; unsigned char count=0,ss=0,sg=0,fs=0,fg=0,ms=0,mg=0,m=0,f=0,s=0,yue=1,ri=1; unsigned char str1[]={'温度:00 '},str2[2],str3[]={'湿度:00%'},str4[2],dat=1,cal[10]={'0001-01-01'}; #define uchar unsigned char #define uint unsigned int //DS1302引脚定义 sbit RST=P1^0; sbit IO=P1^1; sbit SCK=P1^2; //DS1302地址定义 #define ds1302_sec_add 0x80 //秒数据地址 #define ds1302_min_add 0x82 //分数据地址 #define ds1302_hr_add 0x84 //时数据地址 #define ds1302_date_add 0x86 //日数据地址 #define ds1302_month_add 0x88 //月数据地址 #define ds1302_day_add 0x8a //星期数据地址 #define ds1302_year_add 0x8c //年数据地址 #define ds1302_control_add 0x8e //控制数据地址 #define ds1302_charger_add 0x90 #define ds1302_clkburst_add 0xbe //初始时间定义 uchar time_buf[8] = {0x20,0x16,0x12,0x31,0x22,0x16,0x00,0x06}; void Delay18ms() //@11.0592MHz { unsigned char i, j, k; _nop_(); _nop_(); i = 1; j = 194; k = 159; do { do { while (--k); } while (--j); } while (--i); } void Delay10us() //@11.0592MHz { unsigned char i; _nop_(); _nop_(); _nop_(); i = 24; while (--i); } //DS1302初始化函数 void ds1302_init(void) { RST=0; //RST脚置低 SCK=0; //SCK脚置低 } //向DS1302写入一字节数据 void ds1302_write_byte(uchar addr, uchar d) { uchar i; RST=1; //启动DS1302总线 //写入目标地址:addr addr = addr & 0xFE; //最低位置零,寄存器0位为0时写,为1时读 for (i = 0; i < 8; i ++) { if (addr & 0x01) { IO=1; } else { IO=0; } SCK=1; //产生时钟 SCK=0; addr = addr >> 1; } //写入数据:d for (i = 0; i < 8; i ++) { if (d & 0x01) { IO=1; } else { IO=0; } SCK=1; //产生时钟 SCK=0; d = d >> 1; } RST=0; //停止DS1302总线 } //从DS1302读出一字节数据 uchar ds1302_read_byte(uchar addr) { uchar i,temp; RST=1; //启动DS1302总线 //写入目标地址:addr addr = addr | 0x01; //最低位置高,寄存器0位为0时写,为1时读 for (i = 0; i < 8; i ++) { if (addr & 0x01) { IO=1; _nop_(); _nop_(); } else { IO=0; _nop_(); _nop_(); } SCK=1; SCK=0; addr = addr >> 1; } //输出数据:temp for (i = 0; i < 8; i ++) { temp = temp >> 1; if (IO) { temp |= 0x80; } else { temp &= 0x7F; } SCK=1; _nop_(); _nop_(); SCK=0; _nop_(); _nop_(); } RST=0; //停止DS1302总线 _nop_(); _nop_(); return temp; } //向DS302写入时钟数据 void ds1302_write_time(void) { ds1302_write_byte(ds1302_control_add,0x00); //关闭写保护 ds1302_write_byte(ds1302_sec_add,0x80); //暂停时钟 //ds1302_write_byte(ds1302_charger_add,0xa9); //涓流充电 ds1302_write_byte(ds1302_year_add,time_buf[1]); //年 ds1302_write_byte(ds1302_month_add,time_buf[2]); //月 ds1302_write_byte(ds1302_date_add,time_buf[3]); //日 ds1302_write_byte(ds1302_hr_add,time_buf[4]); //时 ds1302_write_byte(ds1302_min_add,time_buf[5]); //分 ds1302_write_byte(ds1302_sec_add,time_buf[6]); //秒 ds1302_write_byte(ds1302_day_add,time_buf[7]); //周 ds1302_write_byte(0xc0,0xaa); ds1302_write_byte(ds1302_control_add,0x80); //打开写保护 } //从DS302读出时钟数据 void ds1302_read_time(void) { time_buf[1]=ds1302_read_byte(ds1302_year_add); //年 time_buf[2]=ds1302_read_byte(ds1302_month_add); //月 time_buf[3]=ds1302_read_byte(ds1302_date_add); //日 time_buf[4]=ds1302_read_byte(ds1302_hr_add); //时 time_buf[5]=(ds1302_read_byte(ds1302_min_add)); //分 time_buf[6]=(ds1302_read_byte(ds1302_sec_add))&0x3f;//秒,屏蔽秒的第7位,避免超出59 time_buf[7]=ds1302_read_byte(ds1302_day_add); //周 } void COM(void) { U8 i; for(i=0;i<8;i++) { U8FLAG=2; while((!P2_0)&&U8FLAG++); Delay10us(); Delay10us(); Delay10us(); U8temp=0; if(P2_0)U8temp=1; U8FLAG=2; while((P2_0)&&U8FLAG++); //超时则跳出for循环 if(U8FLAG==1)break; //判断数据位是0还是1 // 如果高电平高过预定0高电平值则数据位为 1 U8comdata<<=1; U8comdata|=U8temp; //0 }//rof } //-------------------------------- //-----湿度读取子程序 ------------ //-------------------------------- //----以下变量均为全局变量-------- //----温度高8位== U8T_data_H------ //----温度低8位== U8T_data_L------ //----湿度高8位== U8RH_data_H----- //----湿度低8位== U8RH_data_L----- //----校验 8位 == U8checkdata----- //----调用相关子程序如下---------- //---- Delay();, Delay_10us();,COM(); //-------------------------------- void RH(void) { //主机拉低18ms P2_0=0; Delay18ms(); P2_0=1; //总线由上拉电阻拉高 主机延时20us Delay10us(); Delay10us(); Delay10us(); Delay10us(); //主机设为输入 判断从机响应信号 P2_0=1; //判断从机是否有低电平响应信号 如不响应则跳出,响应则向下运行 if(!P2_0) //T ! { U8FLAG=2; //判断从机是否发出 80us 的低电平响应信号是否结束 while((!P2_0)&&U8FLAG++); U8FLAG=2; //判断从机是否发出 80us 的高电平,如发出则进入数据接收状态 while((P2_0)&&U8FLAG++); //数据接收状态 COM(); U8RH_data_H=U8comdata; COM(); U8RH_data_L=U8comdata; COM(); U8T_data_H=U8comdata; COM(); U8T_data_L=U8comdata; COM(); U8checkdata=U8comdata; P2_0=1; }//fi } unsigned char code user16x16[]={ //笑脸图片 0x0F,0xF0,0x10,0x08,0x20,0x04,0x40,0x02,0x9C,0x39,0xBE,0x7D,0x80,0x01,0x80,0x01, 0x80,0x01,0x88,0x11,0x84,0x21,0x43,0xC2,0x20,0x04,0x10,0x08,0x0F,0xF0,0x00,0x00, }; unsigned char code pic1[]= // 图片代码 { 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,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,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,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,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,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,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,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,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,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,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,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 }; unsigned char code num[11][64]={ {// 图片数字0 0x00,0x00,0x3F,0xFC,0x5F,0xFA,0x6F,0xF6,0x70,0x0E,0x70,0x0E,0x70,0x0E,0x70,0x0E, 0x70,0x0E,0x70,0x0E,0x70,0x0E,0x70,0x0E,0x70,0x0E,0x60,0x06,0x40,0x02,0x00,0x00, 0x40,0x02,0x60,0x06,0x70,0x0E,0x70,0x0E,0x70,0x0E,0x70,0x0E,0x70,0x0E,0x70,0x0E, 0x70,0x0E,0x70,0x0E,0x70,0x0E,0x6F,0xF6,0x5F,0xFA,0x3F,0xFC,0x00,0x00,0x00,0x00}, {// 图片数字1 0x00,0x00,0x00,0x20,0x00,0x60,0x00,0xE0,0x00,0xE0,0x00,0xE0,0x00,0xE0,0x00,0xE0, 0x00,0xE0,0x00,0xE0,0x00,0xE0,0x00,0xE0,0x00,0x60,0x00,0x20,0x00,0x00,0x00,0x20, 0x00,0x60,0x00,0xE0,0x00,0xE0,0x00,0xE0,0x00,0xE0,0x00,0xE0,0x00,0xE0,0x00,0xE0, 0x00,0xE0,0x00,0xE0,0x00,0xE0,0x00,0x60,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00}, {// 图片数字2 0x00,0x00,0x3F,0xFC,0x1F,0xFA,0x0F,0xF6,0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x0E, 0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x06,0x1F,0xFA,0x3F,0xFC, 0x5F,0xF8,0x60,0x00,0x70,0x00,0x70,0x00,0x70,0x00,0x70,0x00,0x70,0x00,0x70,0x00, 0x70,0x00,0x70,0x00,0x70,0x00,0x6F,0xF8,0x5F,0xFC,0x3F,0xFE,0x00,0x00,0x00,0x00}, {// 图片数字3 0x00,0x00,0x3F,0xFC,0x1F,0xFA,0x0F,0xF6,0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x0E, 0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x06,0x1F,0xFA,0x3F,0xFC, 0x1F,0xFA,0x00,0x06,0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x0E, 0x00,0x0E,0x00,0x0E,0x00,0x0E,0x0F,0xF6,0x1F,0xFA,0x3F,0xFC,0x00,0x00,0x00,0x00}, {// 图片数字4 0x00,0x00,0x40,0x02,0x60,0x06,0x70,0x0E,0x70,0x0E,0x70,0x0E,0x70,0x0E,0x70,0x0E, 0x70,0x0E,0x70,0x0E,0x70,0x0E,0x70,0x0E,0x70,0x0E,0x60,0x06,0x5F,0xFA,0x3F,0xFC, 0x1F,0xFA,0x00,0x06,0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x0E, 0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x06,0x00,0x02,0x00,0x00,0x00,0x00}, {// 图片数字5 0x00,0x00,0x3F,0xFC,0x5F,0xF8,0x6F,0xF0,0x70,0x00,0x70,0x00,0x70,0x00,0x70,0x00, 0x70,0x00,0x70,0x00,0x70,0x00,0x70,0x00,0x70,0x00,0x60,0x00,0x5F,0xF8,0x3F,0xFC, 0x1F,0xFA,0x00,0x06,0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x0E, 0x00,0x0E,0x00,0x0E,0x00,0x0E,0x0F,0xF6,0x1F,0xFA,0x3F,0xFC,0x00,0x00,0x00,0x00}, {// 图片数字6 0x00,0x00,0x3F,0xFC,0x5F,0xF8,0x6F,0xF0,0x70,0x00,0x70,0x00,0x70,0x00,0x70,0x00, 0x70,0x00,0x70,0x00,0x70,0x00,0x70,0x00,0x70,0x00,0x60,0x00,0x5F,0xF8,0x3F,0xFC, 0x5F,0xFA,0x60,0x06,0x70,0x0E,0x70,0x0E,0x70,0x0E,0x70,0x0E,0x70,0x0E,0x70,0x0E, 0x70,0x0E,0x70,0x0E,0x70,0x0E,0x6F,0xF6,0x5F,0xFA,0x3F,0xFC,0x00,0x00,0x00,0x00}, {// 图片数字7 0x00,0x00,0x3F,0xFC,0x1F,0xFA,0x0F,0xF6,0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x0E, 0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x06,0x00,0x02,0x00,0x00, 0x00,0x02,0x00,0x06,0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x0E, 0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x06,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00}, {// 图片数字8 0x00,0x00,0x3F,0xFC,0x5F,0xFA,0x6F,0xF6,0x70,0x0E,0x70,0x0E,0x70,0x0E,0x70,0x0E, 0x70,0x0E,0x70,0x0E,0x70,0x0E,0x70,0x0E,0x70,0x0E,0x60,0x06,0x5F,0xFA,0x3F,0xFC, 0x5F,0xFA,0x60,0x06,0x70,0x0E,0x70,0x0E,0x70,0x0E,0x70,0x0E,0x70,0x0E,0x70,0x0E, 0x70,0x0E,0x70,0x0E,0x70,0x0E,0x6F,0xF6,0x5F,0xFA,0x3F,0xFC,0x00,0x00,0x00,0x00}, {// 图片数字9 0x00,0x00,0x3F,0xFC,0x5F,0xFA,0x6F,0xF6,0x70,0x0E,0x70,0x0E,0x70,0x0E,0x70,0x0E, 0x70,0x0E,0x70,0x0E,0x70,0x0E,0x70,0x0E,0x70,0x0E,0x60,0x06,0x5F,0xFA,0x3F,0xFC, 0x1F,0xFA,0x00,0x06,0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x0E, 0x00,0x0E,0x00,0x0E,0x00,0x0E,0x1F,0xF6,0x3F,0xFA,0x7F,0xFC,0x00,0x00,0x00,0x00}, {// 图片':' 10 //6X6方点 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0xE0,0x07,0xE0, 0x07,0xE0,0x07,0xE0,0x07,0xE0,0x07,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0xE0,0x07,0xE0,0x07,0xE0,0x07,0xE0, 0x07,0xE0,0x07,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00} }; unsigned char code kongbai[]= { 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 }; /*------------------------------------------------ 检测忙位 ------------------------------------------------*/ void init_timer() { TMOD=0x21;//模式1,16位计时 TH0=19555/256; TL0=19555%256; ET0=1; } void csh() { SM0=0; SM1=1; REN=1; TI=0; RI=0; PCON=0; TH1=0xFD; TL1=0XFD; TMOD=0X21; EA=1; ET1=0; ES=1; TR1=1; } void Check_Busy() { RS=0; RW=1; E=1; DataPort=0xff; while((DataPort&0x80)==0x80);//忙则等待 E=0; } /*------------------------------------------------ 写命令 ------------------------------------------------*/ void Write_Cmd(unsigned char Cmd) { Check_Busy(); RS=0; RW=0; E=1; DataPort=Cmd; DelayUs2x(5); E=0; DelayUs2x(5); } /*------------------------------------------------ 写数据 ------------------------------------------------*/ void Write_Data(unsigned char Data) { Check_Busy(); RS=1; RW=0; E=1; DataPort=Data; DelayUs2x(5); E=0; DelayUs2x(5); } /*------------------------------------------------ 液晶屏初始化 ------------------------------------------------*/ void Init_ST7920() { DelayMs(40); //大于40MS的延时程序 PSB=1; //设置为8BIT并口工作模式 DelayMs(1); //延时 RES=0; //复位 DelayMs(1); //延时 RES=1; //复位置高 DelayMs(10); Write_Cmd(0x30); //选择基本指令集 DelayUs2x(50); //延时大于100us Write_Cmd(0x30); //选择8bit数据流 DelayUs2x(20); //延时大于37us Write_Cmd(0x0c); //开显示(无游标、不反白) DelayUs2x(50); //延时大于100us Write_Cmd(0x01); //清除显示,并且设定地址指针为00H DelayMs(15); //延时大于10ms //Write_Cmd(0x06); //指定在资料的读取及写入时,设定游标的移动方向及指定显示的移位,光标从右向左加1位移动 DelayUs2x(50); //延时大于100us } /*------------------------------------------------ 用户自定义字符 ------------------------------------------------*/ void CGRAM() { int i; Write_Cmd(0x30); Write_Cmd(0x40); for(i=0;i<16;i++) { Write_Data(user16x16[i*2]); Write_Data(user16x16[i*2+1]); } } /*------------------------------------------------ 显示用户自定义字符 ------------------------------------------------*/ void DisplayCGRAM(unsigned char x,unsigned char y) { switch(y) { case 1: Write_Cmd(0x80+x);break; case 2: Write_Cmd(0x90+x);break; case 3: Write_Cmd(0x88+x);break; case 4: Write_Cmd(0x98+x);break; default:break; } Write_Data(00); Write_Data(00); } /*------------------------------------------------ 显示字符串 x:横坐标值,范围0~8 y:纵坐标值,范围1~4 ------------------------------------------------*/ void LCD_PutString(unsigned char x,unsigned char y,unsigned char *s) { switch(y) { case 1: Write_Cmd(0x80+x);break; case 2: Write_Cmd(0x90+x);break; case 3: Write_Cmd(0x88+x);break; case 4: Write_Cmd(0x98+x);break; default:break; } while(*s>0) { Write_Data(*s); s++; DelayUs2x(50); } } /*------------------------------------------------ 清屏 ------------------------------------------------*/ void ClrScreen() { Write_Cmd(0x01); DelayMs(15); } /*------------------------------------------------ 显示图片 ------------------------------------------------*/ void LCD_PutGraphic(unsigned char code *img) { int i,j; //显示上半屏内容设置 for(i=0;i<32;i++) { Write_Cmd(0x80 + i); //SET 垂直地址 VERTICAL ADD Write_Cmd(0x80); //SET 水平地址 HORIZONTAL ADD for(j=0;j<16;j++) { Write_Data(*img); img++; } } //显示下半屏内容设置 for(i=0;i<32;i++) { Write_Cmd(0x80 + i); //SET 垂直地址 VERTICAL ADD Write_Cmd(0x88); //SET 水平地址 HORIZONTAL ADD for(j=0;j<16;j++) { Write_Data(*img); img++; } } } /*------------------------------------------------ 设置到绘图模式 ------------------------------------------------*/ void SetGraphicMode() { Write_Cmd(0x36); //选择8bit数据流 图形模式 DelayUs2x(20); } void SetNormalMode() { Write_Cmd(0x30); //选择8bit数据流 图形模式 DelayUs2x(20); } void huatu(unsigned char x,unsigned char code *img) { unsigned char i,j; SetGraphicMode(); for(i=0;i<32;i++) { if(i<16) { Write_Cmd(0x80+16+i); Write_Cmd(0x80+x); } if(i>=16) { Write_Cmd(0x80+i-16); Write_Cmd(0x88+x); } for(j=0;j<2;j++) { Write_Data(*img); img++; } } SetNormalMode(); } /*------------------------------------------------ 主程序 ------------------------------------------------*/ main() { ds1302_init(); //DS1302初始化 flag = ds1302_read_byte(0xc0); Delay10us(); Delay10us(); flag = ds1302_read_byte(0xc0); Delay10us(); Delay10us(); if(flag != 0xaa) { ds1302_write_time(); //写入初始值 Delay10us(); Delay10us(); ds1302_write_time(); //写入初始值 Delay10us(); Delay10us(); } EA=1; ET0=1; TR0=1; init_timer(); SetGraphicMode(); //设置成绘图模式 LCD_PutGraphic(pic1); //清屏 beep = 0; while(1) { RH(); //ds1302_read_time(); //读取时间 cal[0] = (time_buf[0]>>4) + 48; //年 cal[1] = (time_buf[0]&0x0f) + 48; cal[2] = (time_buf[1]>>4) + 48; cal[3] = (time_buf[1]&0x0f) + 48; cal[5] = (time_buf[2]>>4) + 48; //月 cal[6] = (time_buf[2]&0x0f) + 48; cal[8] = (time_buf[3]>>4) + 48; //日 cal[9] = (time_buf[3]&0x0f) + 48; dat=(time_buf[7]&0x07); //星期 ss=(time_buf[4]>>4); //时 sg=(time_buf[4]&0x0f); fs=(time_buf[5]>>4); //分 fg=(time_buf[5]&0x0f); ms=(time_buf[6]>>4); //秒 mg=(time_buf[6]&0x0f); if((time_buf[5] ==0x59 && time_buf[6] == 0x59) || (time_buf[5] ==0x00 && time_buf[6] == 0x00)) beep = 1; else beep = 0; huatu(0,num[ss]); huatu(1,num[sg]); if(count>=5 && count<=15) { huatu(2,num[10]); } else { huatu(2,kongbai); } huatu(3,num[fs]); huatu(4,num[fg]); if(count>=5 && count<=15) { huatu(5,num[10]); } else { huatu(5,kongbai); } huatu(6,num[ms]); huatu(7,num[mg]); str1[5]=(U8T_data_H - 4) / 10 + 48; //温度 str1[6]=(U8T_data_H - 4) %10 + 48; str3[5]=(U8RH_data_H / 10) + 48; //湿度 str3[6]=(U8RH_data_H % 10)+48; LCD_PutString(0,1,cal); if(dat==1) LCD_PutString(5,1,'星期一'); if(dat==2) LCD_PutString(5,1,'星期二'); if(dat==3) LCD_PutString(5,1,'星期叁'); if(dat==4) LCD_PutString(5,1,'星期四'); if(dat==5) LCD_PutString(5,1,'星期五'); if(dat==6) LCD_PutString(5,1,'星期六'); if(dat==7) LCD_PutString(5,1,'星期天'); LCD_PutString(0,4,str1); LCD_PutString(4,4,str3); } } void Timer0_INT() interrupt 1 { count++; if(count==20)//count=20,计时一秒 { ds1302_read_time(); //读取时间 count=0; if(time_buf[6] == 0x39) { jishi_flag = 1; } if((jishi_flag == 1)&&(time_buf[6] != 0x39)) { count_up++; time_buf[6] = time_buf[6] + 0x40; if(count_up == 20) { count_up = 0; jishi_flag = 0; } } } TH0=19500/256; TL0=19500%256; }