找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 7439|回复: 14
打印 上一主题 下一主题
收起左侧

LCD12864万年历单片机程序+实物制作+Proteus仿真

  [复制链接]
跳转到指定楼层
楼主
制作出来的LCD12864万年历实物图如下:


LCD12864万年历仿真原理图如下(proteus仿真工程文件可到本帖附件中下载)


电路原理图如下:


单片机源程序如下:
  1. *-----------------------------------------------
  2.   名称:12864字库液晶显示
  3.   内容:通过显示字符、数字、汉字和图片测试液晶基本功能
  4. ------------------------------------------------*/
  5. #include <reg52.h>
  6. #include <intrins.h>
  7. #include "delay.h"
  8. sbit RS = P3^5;
  9. sbit RW = P3^6;
  10. sbit E  = P3^4;
  11. sbit RES = P1^7;
  12. sbit PSB = P1^6;
  13. sbit beep = P2^3;
  14. #define DataPort P0        //MCU P0<------> LCM
  15. //
  16. typedef unsigned char  U8;       /* defined for unsigned 8-bits integer variable    无符号8位整型变量  */
  17. typedef signed   char  S8;       /* defined for signed 8-bits integer variable    有符号8位整型变量  */
  18. typedef unsigned int   U16;      /* defined for unsigned 16-bits integer variable    无符号16位整型变量 */
  19. typedef signed   int   S16;      /* defined for signed 16-bits integer variable    有符号16位整型变量 */
  20. typedef unsigned long  U32;      /* defined for unsigned 32-bits integer variable    无符号32位整型变量 */
  21. typedef signed   long  S32;      /* defined for signed 32-bits integer variable    有符号32位整型变量 */
  22. typedef float          F32;      /* single precision floating point variable (32bits) 单精度浮点数(32位长度) */
  23. typedef double         F64;      /* double precision floating point variable (64bits) 双精度浮点数(64位长度) */
  24. //
  25. #define uchar unsigned char
  26. #define uint unsigned int
  27. #define   Data_0_time    4
  28. //----------------------------------------------//
  29. //----------------IO口定义区--------------------//
  30. //----------------------------------------------//
  31. sbit  P2_0  = P2^0 ;
  32. //----------------------------------------------//
  33. //----------------定义区--------------------//
  34. //----------------------------------------------//
  35. U8  U8FLAG,k;
  36. U8  U8count,U8temp;
  37. U8  U8T_data_H,U8T_data_L,U8RH_data_H,U8RH_data_L,U8checkdata;
  38. U8  U8comdata;
  39. U8  count;
  40. U8 flag;
  41. U8 jishi_flag = 0,count_up = 0;
  42. 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;
  43. unsigned char str1[]={"温度:00 "},str2[2],str3[]={"湿度:00%"},str4[2],dat=1,cal[10]={"0001-01-01"};
  44. #define uchar unsigned char
  45. #define uint  unsigned int
  46. //DS1302引脚定义
  47. sbit RST=P1^0;
  48. sbit IO=P1^1;
  49. sbit SCK=P1^2;
  50. //DS1302地址定义
  51. #define ds1302_sec_add   0x80  //秒数据地址
  52. #define ds1302_min_add   0x82  //分数据地址
  53. #define ds1302_hr_add   0x84  //时数据地址
  54. #define ds1302_date_add   0x86  //日数据地址
  55. #define ds1302_month_add  0x88  //月数据地址
  56. #define ds1302_day_add   0x8a  //星期数据地址
  57. #define ds1302_year_add   0x8c  //年数据地址
  58. #define ds1302_control_add  0x8e  //控制数据地址
  59. #define ds1302_charger_add  0x90      
  60. #define ds1302_clkburst_add  0xbe
  61. //初始时间定义
  62. uchar time_buf[8] = {0x20,0x16,0x12,0x31,0x22,0x16,0x00,0x06};
  63. void Delay18ms()  //@11.0592MHz
  64. {
  65. unsigned char i, j, k;
  66. _nop_();
  67. _nop_();
  68. i = 1;
  69. j = 194;
  70. k = 159;
  71. do
  72. {
  73.   do
  74.   {
  75.    while (--k);
  76.   } while (--j);
  77. } while (--i);
  78. }

  79. void Delay10us()  //@11.0592MHz
  80. {
  81. unsigned char i;
  82. _nop_();
  83. _nop_();
  84. _nop_();
  85. i = 24;
  86. while (--i);
  87. }
  88. //DS1302初始化函数
  89. void ds1302_init(void)
  90. {
  91. RST=0;   //RST脚置低
  92. SCK=0;   //SCK脚置低
  93. }
  94. //向DS1302写入一字节数据
  95. void ds1302_write_byte(uchar addr, uchar d)
  96. {
  97. uchar i;
  98. RST=1;     //启动DS1302总线
  99. //写入目标地址:addr
  100. addr = addr & 0xFE;   //最低位置零,寄存器0位为0时写,为1时读
  101. for (i = 0; i < 8; i ++) {
  102.   if (addr & 0x01) {
  103.    IO=1;
  104.    }
  105.   else {
  106.    IO=0;
  107.    }
  108.   SCK=1;      //产生时钟
  109.   SCK=0;
  110.   addr = addr >> 1;
  111.   }
  112. //写入数据:d
  113. for (i = 0; i < 8; i ++) {
  114.   if (d & 0x01) {
  115.    IO=1;
  116.    }
  117.   else {
  118.    IO=0;
  119.    }
  120.   SCK=1;    //产生时钟
  121.   SCK=0;
  122.   d = d >> 1;
  123.   }
  124. RST=0;  //停止DS1302总线
  125. }
  126. //从DS1302读出一字节数据
  127. uchar ds1302_read_byte(uchar addr) {
  128. uchar i,temp;
  129. RST=1;     //启动DS1302总线
  130. //写入目标地址:addr
  131. addr = addr | 0x01;    //最低位置高,寄存器0位为0时写,为1时读
  132. for (i = 0; i < 8; i ++) {
  133.   if (addr & 0x01) {
  134.    IO=1;
  135.    _nop_();
  136.    _nop_();
  137.    }
  138.   else {
  139.    IO=0;
  140.    _nop_();
  141.    _nop_();
  142.    }
  143.   SCK=1;
  144.   SCK=0;
  145.   addr = addr >> 1;
  146.   }
  147. //输出数据:temp
  148. for (i = 0; i < 8; i ++) {
  149.   temp = temp >> 1;
  150.   if (IO) {
  151.    temp |= 0x80;
  152.    }
  153.   else {
  154.    temp &= 0x7F;
  155.    }
  156.   SCK=1;
  157.   _nop_();
  158.   _nop_();
  159.   SCK=0;
  160.   _nop_();
  161.   _nop_();
  162.   }
  163. RST=0;     //停止DS1302总线
  164. _nop_();
  165. _nop_();
  166. return temp;
  167. }
  168. //向DS302写入时钟数据
  169. void ds1302_write_time(void)
  170. {
  171. ds1302_write_byte(ds1302_control_add,0x00);   //关闭写保护
  172. ds1302_write_byte(ds1302_sec_add,0x80);    //暂停时钟
  173. //ds1302_write_byte(ds1302_charger_add,0xa9);     //涓流充电
  174. ds1302_write_byte(ds1302_year_add,time_buf[1]);  //年
  175. ds1302_write_byte(ds1302_month_add,time_buf[2]); //月
  176. ds1302_write_byte(ds1302_date_add,time_buf[3]);  //日
  177. ds1302_write_byte(ds1302_hr_add,time_buf[4]);  //时
  178. ds1302_write_byte(ds1302_min_add,time_buf[5]);  //分
  179. ds1302_write_byte(ds1302_sec_add,time_buf[6]);  //秒
  180. ds1302_write_byte(ds1302_day_add,time_buf[7]);  //周
  181. ds1302_write_byte(0xc0,0xaa);
  182. ds1302_write_byte(ds1302_control_add,0x80);   //打开写保护     
  183. }
  184. //从DS302读出时钟数据
  185. void ds1302_read_time(void)  
  186. {
  187. time_buf[1]=ds1302_read_byte(ds1302_year_add);  //年
  188. time_buf[2]=ds1302_read_byte(ds1302_month_add);  //月
  189. time_buf[3]=ds1302_read_byte(ds1302_date_add);  //日
  190. time_buf[4]=ds1302_read_byte(ds1302_hr_add);  //时
  191. time_buf[5]=(ds1302_read_byte(ds1302_min_add));  //分
  192. time_buf[6]=(ds1302_read_byte(ds1302_sec_add))&0x3f;//秒,屏蔽秒的第7位,避免超出59
  193. time_buf[7]=ds1302_read_byte(ds1302_day_add);  //周  
  194. }



  195.         void  COM(void)
  196.       {
  197.      
  198.          U8 i;
  199.          
  200.        for(i=0;i<8;i++)   
  201.      {
  202.   
  203.          U8FLAG=2;
  204.      while((!P2_0)&&U8FLAG++);
  205.    Delay10us();
  206.       Delay10us();
  207.    Delay10us();
  208.      U8temp=0;
  209.       if(P2_0)U8temp=1;
  210.       U8FLAG=2;
  211.    while((P2_0)&&U8FLAG++);
  212.      //超时则跳出for循环   
  213.       if(U8FLAG==1)break;
  214.      //判断数据位是0还是1  
  215.         
  216.   // 如果高电平高过预定0高电平值则数据位为 1
  217.       
  218.      U8comdata<<=1;
  219.         U8comdata|=U8temp;        //0
  220.       }//rof
  221.    
  222. }
  223. //--------------------------------
  224. //-----湿度读取子程序 ------------
  225. //--------------------------------
  226. //----以下变量均为全局变量--------
  227. //----温度高8位== U8T_data_H------
  228. //----温度低8位== U8T_data_L------
  229. //----湿度高8位== U8RH_data_H-----
  230. //----湿度低8位== U8RH_data_L-----
  231. //----校验 8位 == U8checkdata-----
  232. //----调用相关子程序如下----------
  233. //---- Delay();, Delay_10us();,COM();
  234. //--------------------------------
  235. void RH(void)
  236. {
  237.    //主机拉低18ms
  238.        P2_0=0;
  239.     Delay18ms();
  240.     P2_0=1;
  241.   //总线由上拉电阻拉高 主机延时20us
  242.     Delay10us();
  243.     Delay10us();
  244.     Delay10us();
  245.     Delay10us();
  246.   //主机设为输入 判断从机响应信号
  247.     P2_0=1;
  248.   //判断从机是否有低电平响应信号 如不响应则跳出,响应则向下运行   
  249.     if(!P2_0)   //T !   
  250.     {
  251.     U8FLAG=2;
  252.   //判断从机是否发出 80us 的低电平响应信号是否结束  
  253.     while((!P2_0)&&U8FLAG++);
  254.     U8FLAG=2;
  255.   //判断从机是否发出 80us 的高电平,如发出则进入数据接收状态
  256.     while((P2_0)&&U8FLAG++);
  257.   //数据接收状态   
  258.     COM();
  259.     U8RH_data_H=U8comdata;
  260.     COM();
  261.     U8RH_data_L=U8comdata;
  262.     COM();
  263.     U8T_data_H=U8comdata;
  264.     COM();
  265.     U8T_data_L=U8comdata;
  266.     COM();
  267.     U8checkdata=U8comdata;
  268.     P2_0=1;
  269.     }//fi
  270. }


  271. unsigned char code user16x16[]={ //笑脸图片
  272. 0x0F,0xF0,0x10,0x08,0x20,0x04,0x40,0x02,0x9C,0x39,0xBE,0x7D,0x80,0x01,0x80,0x01,
  273. 0x80,0x01,0x88,0x11,0x84,0x21,0x43,0xC2,0x20,0x04,0x10,0x08,0x0F,0xF0,0x00,0x00,
  274. };
  275. unsigned char code pic1[]=      // 图片代码
  276. {
  277. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  278. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  279. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  280. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  281. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  282. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  283. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  284. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  285. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  286. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  287. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  288. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  289. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  290. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  291. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  292. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  293. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  294. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  295. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  296. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  297. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  298. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  299. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  300. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  301. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  302. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  303. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  304. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  305. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  306. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  307. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  308. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  309. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  310. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  311. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  312. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  313. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  314. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  315. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  316. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  317. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  318. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  319. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  320. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  321. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  322. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  323. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  324. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  325. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  326. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  327. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  328. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  329. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  330. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  331. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  332. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  333. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  334. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  335. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  336. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  337. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  338. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  339. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  340. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  341. };
  342. unsigned char code num[11][64]={
  343. {// 图片数字0
  344. 0x00,0x00,0x3F,0xFC,0x5F,0xFA,0x6F,0xF6,0x70,0x0E,0x70,0x0E,0x70,0x0E,0x70,0x0E,
  345. 0x70,0x0E,0x70,0x0E,0x70,0x0E,0x70,0x0E,0x70,0x0E,0x60,0x06,0x40,0x02,0x00,0x00,
  346. 0x40,0x02,0x60,0x06,0x70,0x0E,0x70,0x0E,0x70,0x0E,0x70,0x0E,0x70,0x0E,0x70,0x0E,
  347. 0x70,0x0E,0x70,0x0E,0x70,0x0E,0x6F,0xF6,0x5F,0xFA,0x3F,0xFC,0x00,0x00,0x00,0x00},
  348. {// 图片数字1
  349. 0x00,0x00,0x00,0x20,0x00,0x60,0x00,0xE0,0x00,0xE0,0x00,0xE0,0x00,0xE0,0x00,0xE0,
  350. 0x00,0xE0,0x00,0xE0,0x00,0xE0,0x00,0xE0,0x00,0x60,0x00,0x20,0x00,0x00,0x00,0x20,
  351. 0x00,0x60,0x00,0xE0,0x00,0xE0,0x00,0xE0,0x00,0xE0,0x00,0xE0,0x00,0xE0,0x00,0xE0,
  352. 0x00,0xE0,0x00,0xE0,0x00,0xE0,0x00,0x60,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00},
  353. {// 图片数字2
  354. 0x00,0x00,0x3F,0xFC,0x1F,0xFA,0x0F,0xF6,0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x0E,
  355. 0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x06,0x1F,0xFA,0x3F,0xFC,
  356. 0x5F,0xF8,0x60,0x00,0x70,0x00,0x70,0x00,0x70,0x00,0x70,0x00,0x70,0x00,0x70,0x00,
  357. 0x70,0x00,0x70,0x00,0x70,0x00,0x6F,0xF8,0x5F,0xFC,0x3F,0xFE,0x00,0x00,0x00,0x00},
  358. {// 图片数字3
  359. 0x00,0x00,0x3F,0xFC,0x1F,0xFA,0x0F,0xF6,0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x0E,
  360. 0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x06,0x1F,0xFA,0x3F,0xFC,
  361. 0x1F,0xFA,0x00,0x06,0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x0E,
  362. 0x00,0x0E,0x00,0x0E,0x00,0x0E,0x0F,0xF6,0x1F,0xFA,0x3F,0xFC,0x00,0x00,0x00,0x00},
  363. {// 图片数字4
  364. 0x00,0x00,0x40,0x02,0x60,0x06,0x70,0x0E,0x70,0x0E,0x70,0x0E,0x70,0x0E,0x70,0x0E,
  365. 0x70,0x0E,0x70,0x0E,0x70,0x0E,0x70,0x0E,0x70,0x0E,0x60,0x06,0x5F,0xFA,0x3F,0xFC,
  366. 0x1F,0xFA,0x00,0x06,0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x0E,
  367. 0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x06,0x00,0x02,0x00,0x00,0x00,0x00},
  368. {// 图片数字5
  369. 0x00,0x00,0x3F,0xFC,0x5F,0xF8,0x6F,0xF0,0x70,0x00,0x70,0x00,0x70,0x00,0x70,0x00,
  370. 0x70,0x00,0x70,0x00,0x70,0x00,0x70,0x00,0x70,0x00,0x60,0x00,0x5F,0xF8,0x3F,0xFC,
  371. 0x1F,0xFA,0x00,0x06,0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x0E,
  372. 0x00,0x0E,0x00,0x0E,0x00,0x0E,0x0F,0xF6,0x1F,0xFA,0x3F,0xFC,0x00,0x00,0x00,0x00},
  373. {// 图片数字6
  374. 0x00,0x00,0x3F,0xFC,0x5F,0xF8,0x6F,0xF0,0x70,0x00,0x70,0x00,0x70,0x00,0x70,0x00,
  375. 0x70,0x00,0x70,0x00,0x70,0x00,0x70,0x00,0x70,0x00,0x60,0x00,0x5F,0xF8,0x3F,0xFC,
  376. 0x5F,0xFA,0x60,0x06,0x70,0x0E,0x70,0x0E,0x70,0x0E,0x70,0x0E,0x70,0x0E,0x70,0x0E,
  377. 0x70,0x0E,0x70,0x0E,0x70,0x0E,0x6F,0xF6,0x5F,0xFA,0x3F,0xFC,0x00,0x00,0x00,0x00},
  378. {// 图片数字7
  379. 0x00,0x00,0x3F,0xFC,0x1F,0xFA,0x0F,0xF6,0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x0E,
  380. 0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x06,0x00,0x02,0x00,0x00,
  381. 0x00,0x02,0x00,0x06,0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x0E,
  382. 0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x06,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00},
  383. {// 图片数字8
  384. 0x00,0x00,0x3F,0xFC,0x5F,0xFA,0x6F,0xF6,0x70,0x0E,0x70,0x0E,0x70,0x0E,0x70,0x0E,
  385. 0x70,0x0E,0x70,0x0E,0x70,0x0E,0x70,0x0E,0x70,0x0E,0x60,0x06,0x5F,0xFA,0x3F,0xFC,
  386. 0x5F,0xFA,0x60,0x06,0x70,0x0E,0x70,0x0E,0x70,0x0E,0x70,0x0E,0x70,0x0E,0x70,0x0E,
  387. 0x70,0x0E,0x70,0x0E,0x70,0x0E,0x6F,0xF6,0x5F,0xFA,0x3F,0xFC,0x00,0x00,0x00,0x00},
  388. {// 图片数字9
  389. 0x00,0x00,0x3F,0xFC,0x5F,0xFA,0x6F,0xF6,0x70,0x0E,0x70,0x0E,0x70,0x0E,0x70,0x0E,
  390. 0x70,0x0E,0x70,0x0E,0x70,0x0E,0x70,0x0E,0x70,0x0E,0x60,0x06,0x5F,0xFA,0x3F,0xFC,
  391. 0x1F,0xFA,0x00,0x06,0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x0E,
  392. 0x00,0x0E,0x00,0x0E,0x00,0x0E,0x1F,0xF6,0x3F,0xFA,0x7F,0xFC,0x00,0x00,0x00,0x00},
  393. {// 图片":" 10
  394. //6X6方点
  395. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0xE0,0x07,0xE0,
  396. 0x07,0xE0,0x07,0xE0,0x07,0xE0,0x07,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  397. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0xE0,0x07,0xE0,0x07,0xE0,0x07,0xE0,
  398. 0x07,0xE0,0x07,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}
  399. };
  400. unsigned char code kongbai[]=
  401. {
  402. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  403. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  404. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  405. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  406. };

  407. /*------------------------------------------------
  408.                     检测忙位
  409. ------------------------------------------------*/
  410. void init_timer()
  411. {
  412. TMOD=0x21;//模式1,16位计时
  413. TH0=19555/256;
  414. TL0=19555%256;
  415. ET0=1;
  416. }
  417. void csh()
  418. {
  419.   SM0=0;
  420.   SM1=1;
  421.   REN=1;
  422.   TI=0;
  423.   RI=0;
  424.   PCON=0;
  425.   TH1=0xFD;
  426.   TL1=0XFD;
  427.   TMOD=0X21;
  428.   EA=1;
  429.   ET1=0;
  430.   ES=1;
  431.   TR1=1;
  432. }
  433. void Check_Busy()
  434. {  
  435.     RS=0;
  436.     RW=1;
  437.     E=1;
  438.     DataPort=0xff;
  439.     while((DataPort&0x80)==0x80);//忙则等待
  440.     E=0;
  441. }
  442. /*------------------------------------------------
  443.                    写命令
  444. ------------------------------------------------*/
  445. void Write_Cmd(unsigned char Cmd)
  446. {
  447. Check_Busy();
  448. RS=0;
  449. RW=0;
  450. E=1;
  451. DataPort=Cmd;
  452. DelayUs2x(5);
  453. E=0;
  454. DelayUs2x(5);
  455. }
  456. /*------------------------------------------------
  457.                     写数据
  458. ------------------------------------------------*/
  459. void Write_Data(unsigned char Data)
  460. {
  461. Check_Busy();
  462. RS=1;
  463. RW=0;
  464. E=1;
  465. DataPort=Data;
  466. DelayUs2x(5);
  467. E=0;
  468. DelayUs2x(5);
  469. }
  470. /*------------------------------------------------
  471.                    液晶屏初始化
  472. ------------------------------------------------*/
  473. void Init_ST7920()
  474. {  
  475.    DelayMs(40);           //大于40MS的延时程序
  476.    PSB=1;                 //设置为8BIT并口工作模式
  477.    DelayMs(1);            //延时
  478.    RES=0;                 //复位
  479.    DelayMs(1);            //延时
  480.    RES=1;                 //复位置高
  481.    DelayMs(10);
  482.    Write_Cmd(0x30);       //选择基本指令集
  483.    DelayUs2x(50);         //延时大于100us
  484.    Write_Cmd(0x30);       //选择8bit数据流
  485.    DelayUs2x(20);         //延时大于37us
  486.    Write_Cmd(0x0c);       //开显示(无游标、不反白)
  487.    DelayUs2x(50);         //延时大于100us
  488.    Write_Cmd(0x01);       //清除显示,并且设定地址指针为00H
  489.    DelayMs(15);           //延时大于10ms
  490.    //Write_Cmd(0x06);       //指定在资料的读取及写入时,设定游标的移动方向及指定显示的移位,光标从右向左加1位移动
  491.    DelayUs2x(50);         //延时大于100us
  492. }
  493. /*------------------------------------------------
  494.                    用户自定义字符
  495. ------------------------------------------------*/
  496. void CGRAM()
  497. {
  498.      int i;
  499.      Write_Cmd(0x30);
  500.      Write_Cmd(0x40);
  501.      for(i=0;i<16;i++)
  502.        {
  503.      Write_Data(user16x16[i*2]);
  504.         Write_Data(user16x16[i*2+1]);
  505.       }
  506. }   
  507. /*------------------------------------------------
  508.                    显示用户自定义字符
  509. ------------------------------------------------*/
  510. void DisplayCGRAM(unsigned char x,unsigned char y)
  511. {
  512. switch(y)
  513.      {
  514.    case 1: Write_Cmd(0x80+x);break;
  515.    case 2: Write_Cmd(0x90+x);break;
  516.    case 3: Write_Cmd(0x88+x);break;
  517.    case 4: Write_Cmd(0x98+x);break;
  518.       default:break;
  519.   }
  520.     Write_Data(00);
  521.     Write_Data(00);
  522. }         
  523. /*------------------------------------------------
  524.                    显示字符串
  525. x:横坐标值,范围0~8
  526. y:纵坐标值,范围1~4
  527. ------------------------------------------------*/
  528. void LCD_PutString(unsigned char x,unsigned char y,unsigned char *s)
  529. {
  530. switch(y)
  531.      {
  532.    case 1: Write_Cmd(0x80+x);break;
  533.    case 2: Write_Cmd(0x90+x);break;
  534.    case 3: Write_Cmd(0x88+x);break;
  535.    case 4: Write_Cmd(0x98+x);break;
  536.       default:break;
  537.   }
  538. while(*s>0)
  539.    {
  540.       Write_Data(*s);
  541.       s++;
  542.       DelayUs2x(50);
  543.    }
  544. }

  545. /*------------------------------------------------
  546.                       清屏
  547. ------------------------------------------------*/
  548. void ClrScreen()
  549. {
  550.    Write_Cmd(0x01);
  551.    DelayMs(15);
  552. }
  553.    
  554. /*------------------------------------------------
  555.                    显示图片
  556. ------------------------------------------------*/
  557. void LCD_PutGraphic(unsigned char code *img)
  558. {
  559. int i,j;
  560. //显示上半屏内容设置
  561.    for(i=0;i<32;i++)            
  562.     {
  563.       Write_Cmd(0x80 + i); //SET  垂直地址 VERTICAL ADD
  564.       Write_Cmd(0x80);     //SET  水平地址 HORIZONTAL ADD
  565.       for(j=0;j<16;j++)
  566.        {
  567.          Write_Data(*img);
  568.          img++;
  569.        }
  570.     }
  571. //显示下半屏内容设置
  572.    for(i=0;i<32;i++)            
  573.     {
  574.       Write_Cmd(0x80 + i); //SET 垂直地址 VERTICAL ADD
  575.       Write_Cmd(0x88);     //SET 水平地址 HORIZONTAL ADD
  576.       for(j=0;j<16;j++)
  577.        {
  578.          Write_Data(*img);
  579.          img++;
  580.        }
  581.     }  
  582.            
  583. }

  584. /*------------------------------------------------
  585.                  设置到绘图模式
  586. ------------------------------------------------*/
  587. void SetGraphicMode()
  588. {
  589.    Write_Cmd(0x36);       //选择8bit数据流 图形模式
  590.    DelayUs2x(20);
  591. }
  592. void SetNormalMode()
  593. {
  594.    Write_Cmd(0x30);       //选择8bit数据流 图形模式
  595.    DelayUs2x(20);
  596. }
  597. void huatu(unsigned char x,unsigned char code *img)
  598. {
  599. unsigned char i,j;
  600. SetGraphicMode();
  601. for(i=0;i<32;i++)
  602. {
  603.   if(i<16)
  604.   {
  605.    Write_Cmd(0x80+16+i);
  606.    Write_Cmd(0x80+x);
  607.   }
  608.   if(i>=16)
  609.   {
  610.    Write_Cmd(0x80+i-16);
  611.    Write_Cmd(0x88+x);
  612.   }
  613.   for(j=0;j<2;j++)
  614.   {
  615.    Write_Data(*img);
  616.          img++;
  617.   }
  618. }
  619. SetNormalMode();
  620. }

  621. /*------------------------------------------------
  622.                  主程序
  623. ------------------------------------------------*/
  624. main()
  625. {
  626. ds1302_init();  //DS1302初始化
  627. flag =  ds1302_read_byte(0xc0);
  628. Delay10us();
  629. Delay10us();
  630. flag =  ds1302_read_byte(0xc0);
  631. Delay10us();
  632. Delay10us();
  633. if(flag != 0xaa)
  634. {
  635.   ds1302_write_time(); //写入初始值
  636.   Delay10us();
  637.   Delay10us();
  638.   ds1302_write_time(); //写入初始值
  639.   Delay10us();
  640.   Delay10us();
  641. }
  642. EA=1;
  643. ET0=1;
  644. TR0=1;
  645. init_timer();
  646. SetGraphicMode();     //设置成绘图模式
  647. LCD_PutGraphic(pic1);    //清屏
  648. beep = 0;
  649.    while(1)
  650.    {
  651.       RH();
  652.    //ds1302_read_time();  //读取时间
  653.     cal[0] = (time_buf[0]>>4) + 48; //年   
  654.     cal[1] = (time_buf[0]&0x0f) + 48;
  655.    
  656.     cal[2] = (time_buf[1]>>4) + 48;   
  657.     cal[3] = (time_buf[1]&0x0f) + 48;
  658.    

  659.    
  660.    
  661.     cal[5] = (time_buf[2]>>4) + 48; //月  
  662.     cal[6] = (time_buf[2]&0x0f) + 48;
  663.    

  664.     cal[8] = (time_buf[3]>>4) + 48; //日   
  665.     cal[9] = (time_buf[3]&0x0f) + 48;
  666.    
  667.     dat=(time_buf[7]&0x07); //星期
  668.    
  669.     ss=(time_buf[4]>>4); //时   
  670.     sg=(time_buf[4]&0x0f);   

  671.    

  672.     fs=(time_buf[5]>>4); //分   
  673.     fg=(time_buf[5]&0x0f);   

  674.     ms=(time_buf[6]>>4); //秒
  675.     mg=(time_buf[6]&0x0f);
  676.     if((time_buf[5] ==0x59 && time_buf[6] == 0x59) || (time_buf[5] ==0x00 && time_buf[6] == 0x00))
  677.       beep = 1;
  678.     else
  679.       beep = 0;
  680.    huatu(0,num[ss]);
  681.    huatu(1,num[sg]);
  682.   if(count>=5 && count<=15)
  683.   {
  684.     huatu(2,num[10]);
  685.   }
  686.   else
  687.   {
  688.    huatu(2,kongbai);
  689.   }
  690.   
  691.    huatu(3,num[fs]);
  692.    huatu(4,num[fg]);
  693.    
  694.    if(count>=5 && count<=15)
  695.   {
  696.     huatu(5,num[10]);
  697.   }
  698.   else
  699.   {
  700.    huatu(5,kongbai);
  701.   }
  702.    
  703.    
  704.    huatu(6,num[ms]);
  705.    huatu(7,num[mg]);
  706.    str1[5]=(U8T_data_H - 4) / 10 + 48; //温度
  707.    str1[6]=(U8T_data_H - 4) %10 + 48;   
  708.    
  709.    str3[5]=(U8RH_data_H / 10) + 48; //湿度
  710.    str3[6]=(U8RH_data_H % 10)+48;
  711.    LCD_PutString(0,1,cal);
  712.    if(dat==1) LCD_PutString(5,1,"星期一");
  713.    if(dat==2) LCD_PutString(5,1,"星期二");
  714.    if(dat==3) LCD_PutString(5,1,"星期叁");
  715.    if(dat==4) LCD_PutString(5,1,"星期四");
  716.    if(dat==5) LCD_PutString(5,1,"星期五");
  717.    if(dat==6) LCD_PutString(5,1,"星期六");
  718.    if(dat==7) LCD_PutString(5,1,"星期天");
  719.    LCD_PutString(0,4,str1);
  720.    LCD_PutString(4,4,str3);
  721.    }
  722. }

  723. void Timer0_INT() interrupt 1
  724. {
  725.   count++;
  726. if(count==20)//count=20,计时一秒
  727. {
  728.   ds1302_read_time();  //读取时间
  729.   count=0;
  730.   if(time_buf[6] == 0x39)
  731.   {
  732.    jishi_flag = 1;
  733.   }
  734.   if((jishi_flag == 1)&&(time_buf[6] != 0x39))
  735.   {
  736.    count_up++;
  737.    time_buf[6] = time_buf[6] + 0x40;
  738.    if(count_up == 20)
  739.    {
  740.     count_up = 0;
  741.     jishi_flag = 0;
  742.    }
  743.   }
  744. }
  745. TH0=19500/256;
  746. TL0=19500%256;
  747. }


复制代码

所有资料51hei提供下载:
万年历.7z (523.7 KB, 下载次数: 318)


评分

参与人数 1黑币 +50 收起 理由
admin + 50 共享资料的黑币奖励!

查看全部评分

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏7 分享淘帖 顶2 踩
回复

使用道具 举报

沙发
ID:328014 发表于 2019-4-17 02:17 | 只看该作者
好资料,51黑有你更精彩!!!
回复

使用道具 举报

板凳
ID:318492 发表于 2019-4-25 20:41 | 只看该作者
谢谢分享
回复

使用道具 举报

地板
ID:475424 发表于 2019-4-28 01:37 来自手机 | 只看该作者
感谢分享
回复

使用道具 举报

5#
ID:525478 发表于 2019-5-26 10:15 | 只看该作者
谢谢分享    51黑有你更精彩!!!
回复

使用道具 举报

6#
ID:551354 发表于 2019-5-30 19:39 | 只看该作者
非常感谢
回复

使用道具 举报

7#
ID:558331 发表于 2019-6-10 10:38 | 只看该作者
感谢分享666
回复

使用道具 举报

8#
ID:568756 发表于 2019-8-31 18:35 | 只看该作者
这是什么程序啊,根本就编译不了!
回复

使用道具 举报

9#
ID:605988 发表于 2019-9-1 09:49 | 只看该作者
牛逼大哥~
回复

使用道具 举报

10#
ID:573664 发表于 2019-9-11 21:23 | 只看该作者
你好,请问你这个数字的照片哪里弄,或者能发我一份吗?我想弄32*32的字体大小。我邮箱150187
回复

使用道具 举报

11#
ID:236933 发表于 2019-11-15 15:58 | 只看该作者
你们下载过的有运行这个仿真吗??验证之后,12864是没有任何显示内容的!管理者关注一下很多仿真都没法运行
回复

使用道具 举报

12#
ID:465554 发表于 2019-11-28 21:48 | 只看该作者
很不错的样子
回复

使用道具 举报

13#
ID:676106 发表于 2019-12-30 15:38 | 只看该作者
仿真12864都不显示的。
回复

使用道具 举报

14#
ID:655761 发表于 2019-12-30 16:37 | 只看该作者
为什么电路原理图里面这么多元件
回复

使用道具 举报

15#
ID:308632 发表于 2020-1-7 10:34 | 只看该作者
你的仿真图都没有DS1302,你是怎么实现的。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表