制作出来的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,
上一篇:NRF24L01的使用方法和简单操作介绍(附参考程序)
下一篇:基于51单片机的电子音乐盒的课程设计
推荐阅读最新更新时间:2024-11-05 19:31
设计资源 培训 开发板 精华推荐
- ADR365A 5V 输出低功耗、低噪声电压基准的典型应用,具有灌/拉能力
- LTC4058EDD-4.2 演示板、锂离子电池充电器、4.25V 至 6.3Vin、800mA 输出
- LTC1473 演示板,双电源路径开关驱动器
- LT3091IT7 重合跟踪电源的典型应用
- RT9048 2A、低输入电压、超低压差调节的典型应用
- 使用 Analog Devices 的 LTC2908ITS8-C1 的参考设计
- 使用 Analog Devices 的 LTC3803IS6-5 的参考设计
- 使用 Diodes Incorporated 的 ZXCT1023DFGTA 的参考设计
- AC160214-1, DALI Adapter 使照明通讯主板可以作为 DALI 控制装置 (Receiver) 或 DALI 控制装置 (Controller) 运作
- LT4276CHUFD 25.5W(类型 2)PoE+ 电源在反激模式下的典型应用电路,具有 24V、1A 输出