自己做的12864万年历,分享给51黑电子论坛的朋友们
所有资料打包下载:
万年历12864资料.zip
(901.26 KB, 下载次数: 82)
DS1302用现成模块,可以自己网上找电路图焊
DS18B20引脚看清楚不要搞错
12864为并行方式,PSB跟RST接高电平就行,对比度通过103电位器调背光,可用单片机控制或
用热释电模块控制。
闹钟数据掉电会丢失,可以自己改改程序,用24C02或其它芯片
电路图没有,因为简单,接线时看程序接或自己接好后改程序的定义
所需元器件:
1.单片机最小系统,包括上电复位电路跟时钟电路
2.12864液晶屏1个
3.DS18B20数字温度芯片(三脚)
4.DS1302模块
5.蜂鸣器(有源跟无源各一),三极管8050(3个),103电位器用在12864调对比度
6.按键4个,热释电模块一个,开关一个,导线若干,烙铁,焊锡,
7.其他自己发挥扩展
部分源码预览:
- #include<reg52.h>
- #include<intrins.h>
- #include"lcd12864.h"
- sbit DSPORT=P3^6; //ds18b20接口
- sbit DSIO=P2^1; //ds1302接口
- sbit RST=P2^3;
- sbit SCLK=P2^2;
- sbit zz=P2^4; //有源蜂鸣器 用三极管8050驱动
- sbit s1=P1^0; //调节时间
- sbit s2=P1^1; //加
- sbit s3=P1^2; //减
- sbit s4=P1^3; //调节闹钟
- sbit Beep=P1^7; //扬声器 用三极管8050驱动
- //---定义全局函数---//
- void Ds1302Write(uchar addr, uchar dat);
- uchar Ds1302Read(uchar addr);
- void Ds1302Init();
- void Ds1302ReadTime();
- //---加入全局变量--//
- uchar timeji=0,n=0,keysun=2;
- char SetPlace=-1,naoshi=0x08,naofen=0x00,linsheng=1; //参数定义
- bit biaozhi=1;
- bit biaozhi1=1;
- bit naobiao=0;
- uchar code READ_RTC_ADDR[7] = {0x81, 0x83, 0x85, 0x87, 0x89, 0x8b, 0x8d};
- uchar code WRITE_RTC_ADDR[7] = {0x80, 0x82, 0x84, 0x86, 0x88, 0x8a, 0x8c};
- //---DS1302时钟初始化2013年1月1日星期二12点00分00秒。---//
- //---存储顺序是秒分时日月周年,存储格式是用BCD码---//
- char TIME[7] = {0x00, 0x57, 0x10, 0x01, 0x01, 0x05, 0x16};
- void Delay1ms(unsigned int );
- unsigned char Ds18b20Init();
- void Ds18b20WriteByte(unsigned char com);
- unsigned char Ds18b20ReadByte();
- void Ds18b20ChangTemp();
- void Ds18b20ReadTempCom();
- int Ds18b20ReadTemp();
- uchar code CharCode[]=" 调整时间 年 月 日周 时间 点 分 秒 ";
- uchar code CharCode1[]="20 - - 周 . ℃";
- uchar code xiqi[]=" 一二三四五六日开关";
- uchar code naozhong[]=" 设置闹钟 点 分 铃声选择 ";
- uchar code naozhonglinshen[]="1.天空之城 2.月亮代表我的心3.你是风儿我是沙4.莫斯科郊外的晚5.经典铃声 嘀嘀";
- uchar code tab[11][64]={
- {/*-- 调入了一幅图像:D:\设计\打印\数字取模图片\0.bmp --*/
- /*-- 宽度x高度=16x32 --*/
- 0x0F,0xF0,0x3F,0xFC,0x7F,0xFE,0x7F,0xFE,0xFC,0x3F,0xF8,0x1F,0xF0,0x0F,0xF0,0x0F,
- 0xF0,0x0F,0xF0,0x0F,0xF0,0x0F,0xF0,0x0F,0xF0,0x0F,0xF0,0x0F,0xF0,0x0F,0xF0,0x0F,
- 0xF0,0x0F,0xF0,0x0F,0xF0,0x0F,0xF0,0x0F,0xF0,0x0F,0xF0,0x0F,0xF0,0x0F,0xF0,0x0F,
- 0xF0,0x0F,0xF0,0x0F,0xF8,0x1F,0xFC,0x3F,0x7F,0xFE,0x7F,0xFE,0x3F,0xFC,0x0F,0xF0,},
- {/*-- 1 --*/
- /*-- 宽度x高度=16x32 --*/
- 0x01,0x80,0x07,0xC0,0x0F,0xC0,0x1F,0xE0,0x3F,0xE0,0x7F,0xE0,0xFF,0xE0,0xE3,0xE0,
- 0x03,0xE0,0x03,0xE0,0x03,0xE0,0x03,0xE0,0x03,0xE0,0x03,0xE0,0x03,0xE0,0x03,0xE0,
- 0x03,0xE0,0x03,0xE0,0x03,0xE0,0x03,0xE0,0x03,0xE0,0x03,0xE0,0x03,0xE0,0x03,0xE0,
- 0x03,0xE0,0x03,0xE0,0x03,0xE0,0x07,0xF0,0x3F,0xFC,0x7F,0xFE,0x7F,0xFE,0x00,0x00,},
- {/*-- 2 --*/
- /*-- 宽度x高度=16x32 --*/
- 0x0F,0xF0,0x3F,0xFC,0x7F,0xFE,0xFF,0xFE,0xFC,0x3F,0xF0,0x1F,0xE0,0x0F,0x00,0x0F,
- 0x00,0x0F,0x00,0x0F,0x00,0x0F,0x00,0x0F,0x00,0x1F,0x00,0x3F,0x00,0x7F,0x00,0xFE,
- 0x03,0xFC,0x07,0xF8,0x0F,0xF0,0x1F,0xC0,0x3F,0x80,0x7F,0x00,0x7E,0x00,0xFC,0x00,
- 0xFC,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,},
- {/*-- 调入了一幅图像:D:\设计\打印\数字取模图片\3.bmp --*/
- /*-- 宽度x高度=16x32 --*/
- 0x0F,0xF0,0x3F,0xFC,0x7F,0xFE,0x7F,0xFE,0xFC,0x3F,0xF0,0x1F,0xE0,0x1F,0xE0,0x0F,
- 0xC0,0x0F,0x00,0x0F,0x00,0x1F,0x00,0x1E,0x00,0x3E,0x00,0xFC,0x1F,0xFC,0x1F,0xF8,
- 0x1F,0xFC,0x1F,0xFC,0x00,0x7E,0x00,0x3F,0x00,0x1F,0x00,0x1F,0x00,0x1F,0x00,0x1F,
- 0x00,0x1F,0x00,0x1F,0xC0,0x3F,0xF0,0x7F,0xFF,0xFE,0xFF,0xFE,0xFF,0xFC,0x3F,0xF0,},
- {/*-- 调入了一幅图像:D:\设计\打印\数字取模图片\4.bmp --*/
- /*-- 宽度x高度=16x32 --*/
- 0x00,0x0E,0x00,0x1E,0x00,0x3E,0x00,0x7E,0x00,0xFE,0x01,0xFE,0x03,0xFE,0x03,0xFE,
- 0x07,0xFE,0x0F,0xFE,0x1F,0xFE,0x1F,0xBE,0x3F,0x3E,0x3E,0x3E,0x7E,0x3E,0x7C,0x3E,
- 0xFC,0x3E,0xF8,0x3E,0xF8,0x3E,0xF0,0x3E,0xF0,0x3E,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
- 0xFF,0xFF,0xFF,0xFF,0x00,0x3E,0x00,0x3E,0x00,0x3E,0x00,0x3E,0x00,0x3E,0x00,0x3E,},
- {/*-- 调入了一幅图像:D:\设计\打印\数字取模图片\5.bmp --*/
- /*-- 宽度x高度=16x32 --*/
- 0x1F,0xFF,0x3F,0xFF,0x7F,0xFF,0x7F,0xFF,0xFF,0xFF,0xFC,0x00,0xF8,0x00,0xF8,0x00,
- 0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xFC,0x00,0xFF,0xE0,0x7F,0xFC,0x7F,0xFE,
- 0x3F,0xFF,0x07,0xFF,0x00,0x7F,0x00,0x1F,0x00,0x0F,0x00,0x0F,0x00,0x0F,0x00,0x0F,
- 0x00,0x1F,0x00,0x1F,0xF0,0x3F,0xFC,0x7F,0x7F,0xFE,0x7F,0xFE,0x3F,0xFC,0x0F,0xF0,},
- {/*-- 调入了一幅图像:D:\设计\打印\数字取模图片\6.bmp --*/
- /*-- 宽度x高度=16x32 --*/
- 0x00,0x00,0x00,0x00,0x00,0x3E,0x00,0xFE,0x03,0xFE,0x07,0xFC,0x0F,0xF0,0x1F,0xC0,
- 0x3F,0x00,0x7E,0x00,0x7C,0x00,0x7C,0x00,0xF8,0x00,0xF8,0x00,0xFF,0xE0,0xFF,0xF8,
- 0xFF,0xFE,0xFF,0xFE,0xF8,0x7E,0xF0,0x3F,0xF0,0x1F,0xF0,0x1F,0xF0,0x1F,0xF0,0x1F,
- 0xF0,0x1F,0xF0,0x1F,0xF8,0x3F,0xFE,0xFF,0x7F,0xFE,0x7F,0xFE,0x3F,0xFC,0x0F,0xF0,},
- {/*-- 调入了一幅图像:D:\设计\打印\数字取模图片\7.bmp --*/
- /*-- 宽度x高度=16x32 --*/
- 0xFF,0xFC,0xFF,0xFE,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x1F,0x00,0x0F,0x00,0x0F,
- 0x00,0x0F,0x00,0x1F,0x00,0x1F,0x00,0x1F,0x00,0x1F,0x00,0x3E,0x00,0x3E,0x00,0x3E,
- 0x00,0x3C,0x00,0x7C,0x00,0x78,0x00,0xF8,0x00,0xF8,0x00,0xF0,0x01,0xF0,0x01,0xF0,
- 0x01,0xE0,0x01,0xE0,0x03,0xE0,0x03,0xE0,0x03,0xC0,0x07,0xC0,0x07,0xC0,0x07,0xC0,},
- {/*-- 调入了一幅图像:D:\设计\打印\数字取模图片\8.bmp --*/
- /*-- 宽度x高度=16x32 --*/
- 0x0F,0xF0,0x1F,0xF8,0x3F,0xFC,0x7F,0xFE,0xFC,0x3F,0xF8,0x1F,0xF0,0x0F,0xF0,0x0F,
- 0xF0,0x0F,0xF0,0x0F,0xF0,0x0F,0xF0,0x0F,0xF8,0x1F,0xFC,0x3F,0x7F,0xFE,0x3F,0xFC,
- 0x1F,0xF8,0x3F,0xFC,0x7F,0xFE,0xFC,0x3F,0xF8,0x1F,0xF0,0x0F,0xF0,0x0F,0xF0,0x0F,
- 0xF0,0x0F,0xF0,0x0F,0xF8,0x1F,0xFC,0x3F,0x7F,0xFE,0x3F,0xFC,0x1F,0xF8,0x0F,0xF0,},
- {/*-- 调入了一幅图像:D:\设计\打印\数字取模图片\6.bmp --*/
- /*-- 宽度x高度=16x32 --*/
- 0x0F,0xF0,0x3F,0xFC,0x7F,0xFE,0x7F,0xFE,0xFF,0x7F,0xFC,0x1F,0xF8,0x0F,0xF8,0x0F,
- 0xF8,0x0F,0xF8,0x0F,0xF8,0x0F,0xF8,0x0F,0xF8,0x0F,0x7C,0x1F,0x7F,0xFF,0x7F,0xFF,
- 0x3F,0xFF,0x03,0xFF,0x00,0x3F,0x00,0x1F,0x00,0x3F,0x00,0x3E,0x00,0x7E,0x00,0xFC,
- 0x03,0xF8,0x0F,0xF0,0x3F,0xE0,0x7F,0xC0,0x7F,0x80,0x7E,0x00,0x38,0x00,0x00,0x00,},
- {/*-- 调入了一幅图像:这是您新建的图像 --*/
- /*-- 宽度x高度=16x32 --*/
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x80,
- 0x07,0xC0,0x05,0x40,0x07,0xC0,0x06,0xC0,0x03,0x80,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x80,0x07,0xC0,0x05,0x40,0x07,0xC0,0x06,0xC0,
- 0x03,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,}
- };
- unsigned int code music_tab[4][201] ={{ //天空之城
- 0x39,0x20,0x33,0x20,0x30,0x30,0x33,0x10,0x30,0x40,0x26,0x40,0x33,0x80,
- 0x4c,0x40,0x39,0x30,0x40,0x10,0x39,0x40,0x30,0x40,0x40,0x80,0x4c,0x20,
- 0x4c,0x20,0x48,0x30,0x4c,0x10,0x48,0x40,0x30,0x40,0x4c,0x80,0x30,0x20,
- 0x30,0x20,0x33,0x30,0x48,0x10,0x48,0x40,0x33,0x40,0x33,0x80,0x39,0x20,
- 0x33,0x20,0x30,0x30,0x33,0x10,0x30,0x40,0x26,0x40,0x33,0x80,0x4c,0x40,
- 0x39,0x30,0x40,0x10,0x39,0x40,0x30,0x40,0x40,0x80,0x55,0x20,0x4c,0x20,
- 0x48,0x40,0x30,0x20,0x33,0x30,0x30,0x20,0x2b,0x10,0x2b,0x30,0x26,0x10,
- 0x30,0x80,0x30,0x20,0x33,0x20,0x39,0x20,0x39,0x20,0x33,0x20,0x40,0x20,
- 0x39,0x80,0x30,0x20,0x2b,0x20,0x26,0x30,0x2b,0x10,0x26,0x40,0x20,0x40,
- 0x2b,0xc0,0x30,0x40,0x30,0x20,0x33,0x20,0x30,0x40,0x26,0x40,0x26,0xc0,
- 0x33,0x20,0x30,0x40,0x33,0x20,0x30,0x20,0x2b,0x40,0x30,0x60,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00},
- { //月亮代表我的心
- 0x40,0x20,0x30,0x60,0x26,0x20,0x20,0x60,0x30,0x20,0x33,0x60,0x26,0x20,
- 0x20,0x60,0x20,0x20,0x1c,0x60,0x19,0x20,0x20,0xc0,0x26,0x20,0x2b,0x20,
- 0x30,0x60,0x30,0x10,0x30,0x40,0x26,0x20,0x2b,0x20,0x30,0x60,0x30,0x10,
- 0x30,0x40,0x2b,0x20,0x26,0x20,0x2b,0x60,0x39,0x10,0x33,0x40,0x30,0xc0,
- 0x26,0x40,0x26,0x60,0x2b,0x10,0x30,0x40,0x20,0x40,0x33,0xc0,0x39,0x20,
- 0x33,0x20,0x39,0x60,0x33,0x10,0x39,0x60,0x40,0x10,0x26,0xc0,0x20,0x40,
- 0x26,0x60,0x2b,0x10,0x30,0x40,0x20,0x40,0x33,0xc0,0x39,0x20,0x33,0x20,
- 0x30,0x60,0x30,0x10,0x30,0x40,0x2b,0x40,0x2b,0xc0,0x40,0x20,0x30,0x60,
- 0x26,0x10,0x20,0x60,0x30,0x10,0x33,0x60,0x26,0x10,0x20,0x60,0x20,0x10,
- 0x1c,0x60,0x19,0x10,0x20,0x80,0x26,0x20,0x2b,0x20,0x30,0x60,0x30,0x10,
- 0x30,0x40,0x26,0x20,0x2b,0x20,0x30,0x60,0x30,0x10,0x30,0x40,0x2b,0x20,
- 0x26,0x20,0x2b,0x60,0x39,0x10,0x33,0x40,0x2b,0x40,0x30,0xc0,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00},
- { //你是风儿我是沙
- 0x26,0x30,0x20,0x10,0x18,0x20,0x1c,0x60,0x1c,0x30,0x20,0x10,0x20,0xc0,
- 0x1c,0x20,0x20,0x20,0x26,0x20,0x2b,0x80,0x39,0x20,0x26,0x20,0x26,0xc0,
- 0x26,0x30,0x20,0x10,0x18,0x20,0x1c,0x60,0x1c,0x30,0x20,0x10,0x20,0xc0,
- 0x1c,0x20,0x20,0x20,0x26,0x20,0x2b,0x80,0x39,0x20,0x30,0x20,0x30,0xc0,
- 0x26,0x20,0x2b,0x20,0x26,0x20,0x20,0x20,0x26,0x10,0x2b,0x10,0x30,0x20,
- 0x39,0x20,0x30,0x60,0x2b,0x10,0x26,0x80,0x2b,0x10,0x26,0x10,0x39,0x60,
- 0x2b,0x10,0x24,0x60,0x2b,0x10,0x26,0x20,0x26,0x60,0x30,0x60,0x39,0x10,
- 0x40,0x80,0x30,0x20,0x39,0x20,0x39,0x20,0x30,0x20,0x26,0x20,0x26,0x20,
- 0x26,0x20,0x26,0x20,0x2b,0x40,0x39,0x20,0x2b,0x60,0x30,0x20,0x39,0x20,
- 0x39,0x20,0x39,0x20,0x30,0x20,0x2b,0x20,0x2b,0x20,0x2b,0x20,0x26,0x40,
- 0x2b,0x20,0x30,0x80,0x26,0x20,0x20,0x20,0x18,0x20,0x1c,0x80,0x1c,0x30,
- 0x20,0x10,0x20,0xc0,0x1c,0x20,0x20,0x20,0x26,0x20,0x2b,0x80,0x39,0x20,
- 0x26,0x20,0x26,0x80,0x26,0x30,0x20,0x10,0x18,0x20,0x1c,0x60,0x1c,0x30,
- 0x20,0x10,0x20,0xc0,0x1c,0x20,0x20,0x20,0x26,0x20,0x2b,0x80,0x39,0x20,
- 0x26,0x20,0x26,0xc0,0x00,},
- { // 莫斯科郊外的晚上
- 0x39,0x20,0x30,0x20,0x26,0x20,0x30,0x20,0x2b,0x40,0x30,0x20,0x33,0x20,
- 0x26,0x60,0x2b,0x40,0x39,0x80,0x30,0x20,0x26,0x20,0x20,0x20,0x20,0x20,
- 0x1c,0x40,0x20,0x20,0x24,0x20,0x26,0x80,0x24,0x40,0x20,0x40,0x19,0x20,
- 0x1c,0x20,0x26,0x40,0x33,0x40,0x39,0x20,0x26,0x20,0x2b,0x20,0x24,0x60,
- 0x20,0x20,0x24,0x20,0x26,0x40,0x2b,0x20,0x30,0x20,0x26,0x40,0x2b,0x40,
- 0x39,0x80,0x39,0x20,0x30,0x20,0x26,0x20,0x30,0x20,0x2b,0x40,0x30,0x20,
- 0x33,0x20,0x26,0x60,0x2b,0x40,0x39,0x80,0x30,0x20,0x26,0x20,0x20,0x20,
- 0x20,0x20,0x1c,0x40,0x20,0x20,0x24,0x20,0x26,0x80,0x24,0x40,0x20,0x40,
- 0x19,0x20,0x1c,0x20,0x26,0x40,0x33,0x40,0x39,0x20,0x26,0x20,0x2b,0x20,
- 0x24,0x60,0x20,0x20,0x24,0x20,0x26,0x40,0x2b,0x20,0x30,0x20,0x26,0x40,
- 0x2b,0x40,0x39,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,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 jiemian();
- void LcdDisplay(int temp);
- void display();
- void zhudisplay();
- void TimerConfiguration();
- void key();
- void naoxian();
- void didi();
- void naoxianguangbiao();
- void linshengbofang();
- void sfmxiangao(uchar add,uchar bata);
- void sfmxiandi(uchar acc,uchar datb);
- void zhujiemian();
- void shua_display();
- void nyrdisplay();
- void delay (unsigned char m); //控制频率延时
- void delayms(unsigned char a); //豪秒延时子程序
- void main()
- {
- zz=0;
- Beep=0;
- LCD12864_ClearScreen(); //清CGrom
- LCD12864_WriteCmd(0x01); //清屏
- LCD12864_Init();
- zhujiemian();
- TimerConfiguration();
- while(1)
- {
- key();
- if(biaozhi1==1)
- {
- shua_display();
- if(biaozhi==0)
- {
- biaozhi=1;
- LcdDisplay(Ds18b20ReadTemp());
- }
- if((naoshi==TIME[2])&&(naofen==TIME[1])&&(naobiao==1))//闹钟
- {
- if(linsheng<5)
- {
- linshengbofang();
- }
- if(linsheng==5)
- {
- didi();
- }
- }
- }
- }
- }
- void nyrdisplay()
- {
- LCD12864_SetWindow(0, 1);
- LCD12864_WriteData(0x30+TIME[6]/16); // 年
- LCD12864_WriteData(0x30+(TIME[6]&0x0f));
- LCD12864_WriteData(0x2d);
- LCD12864_WriteData(0x30+TIME[4]/16); //月
- LCD12864_WriteData(0x30+(TIME[4]&0x0f));
- LCD12864_WriteData(0x2d);
- LCD12864_WriteData(0x30+TIME[3]/16); //日
- LCD12864_WriteData(0x30+(TIME[3]&0x0f));
- LCD12864_SetWindow(0, 7);
- LCD12864_WriteData(xiqi[(TIME[5]&0x07)*2]); //星期
- LCD12864_WriteData(xiqi[(TIME[5]&0x07)*2+1]);
- }
- void zhujiemian()
- {
- unsigned char i=0,j=0,k=0;
- LCD12864_SetWindow(0, 0);
- while(CharCode1[i]!='\0')
- {
- LCD12864_WriteData(CharCode1[i]);
- i++;
- if(i==16) //第一行满写第三行
- {
- LCD12864_SetWindow(1,0);
- }
- if(i==32) //第三行满写第四行
- {
- LCD12864_SetWindow(2,0);
- }
- if(i==48) //第三行满写第四行
- {
- LCD12864_SetWindow(3,0);
- }
- }
- zhudisplay();
- LCD12864_WriteCmd(0x36); //开启拓展指令集
- for(i=0;i<16;i++)
- {
- LCD12864_WriteCmd(0x90+i);
- LCD12864_WriteCmd(0x90+2);
- LCD12864_WriteData(tab[10][j++]);
- LCD12864_WriteData(tab[10][j++]); //显示笑脸
- LCD12864_WriteCmd(0x90+i);
- LCD12864_WriteCmd(0x90+5);
- LCD12864_WriteData(tab[10][k++]);
- LCD12864_WriteData(tab[10][k++]);
- }
- for(i=0;i<16;i++)
- {
- LCD12864_WriteCmd(0x80+i);
- LCD12864_WriteCmd(0x98+2);
- LCD12864_WriteData(tab[10][j++]); //显示笑脸
- LCD12864_WriteData(tab[10][j++]);
- LCD12864_WriteCmd(0x80+i);
- LCD12864_WriteCmd(0x98+5);
- LCD12864_WriteData(tab[10][k++]);
- LCD12864_WriteData(tab[10][k++]);
- }
- LCD12864_WriteCmd(0x30); //恢复基本指令集
- }
- void shua_display()
- {
- Ds1302ReadTime();
- if((TIME[2]==0x00)&&(TIME[0]<=5))
- nyrdisplay();
- if((TIME[1]==0x00)&&(TIME[0]<=3))
- {
- if((TIME[2]&0x0f)==0)
- sfmxiangao(0,TIME[2]);
- sfmxiandi(1,TIME[2]); //时
- didi(); //整点报时
- }
- if(TIME[0]<=2)
- {
- if((TIME[1]&0x0f)==0)
- sfmxiangao(3,TIME[1]); //分
- sfmxiandi(4,TIME[1]);
- }
- if((TIME[0]&0x0f)==0)
- sfmxiangao(6,TIME[0]); //秒
- sfmxiandi(7,TIME[0]);
- }
- void zhudisplay()
- {
- Ds1302ReadTime();
- nyrdisplay();
- sfmxiangao(0,TIME[2]);
- sfmxiandi(1,TIME[2]); //时
- sfmxiangao(3,TIME[1]); //分
- sfmxiandi(4,TIME[1]);
- sfmxiangao(6,TIME[0]); //秒
- sfmxiandi(7,TIME[0]);
- }
- void int1() interrupt 3 //采用定时中断1 控制节拍
- { TH1=0xd8;
- TL1=0xef;
- n--;
- }
- void delay (unsigned char m) //控制频率延时
- {
- unsigned i=3*m;
- while(--i);
- }
- void delayms(unsigned char a) //豪秒延时子程序
- {
- while(--a); //采用while(--a) 不要采用while(a--); 各位可编译一下看看汇编结果就知道了!
- }
- void linshengbofang()
- { unsigned char p=0,m; //m为频率常数变量
- unsigned char i=0,j;
- for(j=0;j<150;j++)
- {
- a:p=music_tab[linsheng][i];
- if(p==0x00) { i=0, delayms(1000); return;} //如果碰到结束符,延时1秒,回到开始再来一遍
- else if(p==0xff) { i=i+1;delayms(100),TR0=0; goto a;} //若碰到休止符,延时100ms,继续取下一音符
- else {m=music_tab[linsheng-1][i++], n=music_tab[linsheng-1][i++];} //取频率常数 和 节拍常数
- TR1=1; //开定时器1
- while(n!=0) Beep=~Beep,delay(m); //等待节拍完成, 通过P1口输出音频(可多声道哦!)
- TR1=0; //关定时器1
- }
- }
- void naojie()
- {
- unsigned char i=0;
- LCD12864_SetWindow(0, 0);
- while(naozhong[i]!='\0')
- {
- LCD12864_WriteData(naozhong[i]);
- i++;
- if(i==16) //第一行满写第三行
- LCD12864_SetWindow(1,0);
- if(i==32) //第三行满写第四行
- LCD12864_SetWindow(2,0);
- if(i==48) //第三行满写第四行
- LCD12864_SetWindow(3,0);
- }
- }
- void naoxianguangbiao()
- {
- if(SetPlace==0)
- LCD12864_SetWindow(2, 6);
- if(SetPlace==1)
- LCD12864_SetWindow(2, 4);
- if(SetPlace==2)
- LCD12864_SetWindow(2, 2);
- if(SetPlace==3)
- LCD12864_SetWindow(1, 4);
- if(SetPlace==4)
- LCD12864_SetWindow(1, 2);
- if(SetPlace==5)
- LCD12864_SetWindow(1, 7);
- if(SetPlace==8) //闹钟设置
- LCD12864_SetWindow(0, 6);
- if(SetPlace==9)
- LCD12864_SetWindow(1, 2);
- if(SetPlace==10)
- LCD12864_SetWindow(1, 4);
- if(SetPlace==11)
- LCD12864_SetWindow(3, 0);
- }
- void sfmxiangao(uchar add,uchar bata)
- {
- uchar i,j=0;
- LCD12864_WriteCmd(0x36); //开启拓展指令集
- for(i=0;i<16;i++)
- {
- LCD12864_WriteCmd(0x90+i);
- LCD12864_WriteCmd(0x90+add);
- LCD12864_WriteData(tab[bata/16][j++]);
- LCD12864_WriteData(tab[bata/16][j++]);
- }
- for(i=0;i<16;i++)
- {
- LCD12864_WriteCmd(0x80+i);
- LCD12864_WriteCmd(0x98+add);
- LCD12864_WriteData(tab[bata/16][j++]);
- LCD12864_WriteData(tab[bata/16][j++]);
- }
- LCD12864_WriteCmd(0x30); //恢复基本指令集
- }
- void sfmxiandi(uchar acc,uchar datb)
- {
- uchar i,j=0;
- LCD12864_WriteCmd(0x36); //开启拓展指令集
- for(i=0;i<16;i++)
- {
- LCD12864_WriteCmd(0x90+i);
- LCD12864_WriteCmd(0x90+acc);
- LCD12864_WriteData(tab[datb&0x0f][j++]);
- LCD12864_WriteData(tab[datb&0x0f][j++]);
- }
- for(i=0;i<16;i++)
- {
- LCD12864_WriteCmd(0x80+i);
- LCD12864_WriteCmd(0x98+acc);
- LCD12864_WriteData(tab[datb&0x0f][j++]);
- LCD12864_WriteData(tab[datb&0x0f][j++]);
- }
- LCD12864_WriteCmd(0x30); //恢复基本指令集
- }
- void shixian() //调节时间显示
- {
- if(SetPlace==0)
- {
- LCD12864_WriteData(0x30+(TIME[0]/16)); //秒
- LCD12864_WriteData(0x30+(TIME[0]&0x0f));
- LCD12864_SetWindow(2, 6);
- }
- if(SetPlace==1)
- {
- LCD12864_WriteData(0x30+(TIME[1]/16)); //分
- LCD12864_WriteData(0x30+(TIME[1]&0x0f));
- LCD12864_SetWindow(2, 4);
- }
- if(SetPlace==2)
- {
- LCD12864_WriteData(0x30+(TIME[2]/16)); //时
- LCD12864_WriteData(0x30+(TIME[2]&0x0f));
- LCD12864_SetWindow(2, 2);
- }
- if(SetPlace==3)
- {
- LCD12864_WriteData(0x30+(TIME[3]/16)); //日
- LCD12864_WriteData(0x30+(TIME[3]&0x0f));
- LCD12864_SetWindow(1, 4);
- }
- if(SetPlace==4)
- {
- LCD12864_WriteData(0x30+(TIME[4]/16)); //月
- LCD12864_WriteData(0x30+(TIME[4]&0x0f));
- LCD12864_SetWindow(1, 2);
- }
- if(SetPlace==5)
- {
- LCD12864_WriteData(xiqi[(TIME[5]&0x07)*2]); //星期
- LCD12864_WriteData(xiqi[(TIME[5]&0x07)*2+1]);
- LCD12864_SetWindow(1, 7);
- }
- }
- void naoxian()
- {
- uchar zishu=0;
- if(SetPlace==8) //闹钟设置
- {
- LCD12864_SetWindow(0, 6);
- }
- if(SetPlace==9)
- {
- LCD12864_WriteData(0x30+(naoshi/16)); //时
- LCD12864_WriteData(0x30+(naoshi&0x0f));
- LCD12864_SetWindow(1, 2);
- }
- if(SetPlace==10)
- {
- LCD12864_WriteData(0x30+(naofen/16)); //分
- LCD12864_WriteData(0x30+(naofen&0x0f));
- LCD12864_SetWindow(1, 4);
- }
- if(SetPlace==11)
- {
- if(linsheng==1) //显示铃声名字
- {
- for(zishu=0;zishu<16;zishu++)
- {
- LCD12864_WriteData(naozhonglinshen[zishu]);
- }
- }
- if(linsheng==2)
- for(zishu=16;zishu<32;zishu++)
- {
- LCD12864_WriteData(naozhonglinshen[zishu]);
- }
- if(linsheng==3)
- for(zishu=32;zishu<48;zishu++)
- {
- LCD12864_WriteData(naozhonglinshen[zishu]);
- }
- if(linsheng==4)
- for(zishu=48;zishu<64;zishu++)
- {
- LCD12864_WriteData(naozhonglinshen[zishu]);
- }
- if(linsheng==5)
- for(zishu=64;zishu<80;zishu++)
- {
- LCD12864_WriteData(naozhonglinshen[zishu]);
- }
- LCD12864_SetWindow(3, 0);
- }
- }
- void didi()
- {
- zz=1;
- Delay1ms(80);
- zz=0;
- Delay1ms(80);
- zz=1;
- Delay1ms(80);
- zz=0;
- Delay1ms(80);
- zz=1;
- Delay1ms(80);
- zz=0;
- Delay1ms(80);
- zz=1;
- Delay1ms(200);
- zz=0;
- }
- void key()
- {
- uchar zishu=0;
- if(s1==0) //检测按键K1是否按下
- {
- Delay1ms(10); //消除抖动
- if((s1==0)&&(keysun>=2))
- {
- while(s1==0); //松手检测
- if(SetPlace==-1)
- {
- LCD12864_WriteCmd(0x01);
- biaozhi1=0;
- keysun=3;
- jiemian();
- display();
- }
- SetPlace++;
- LCD12864_WriteCmd(0x0f); //显示开,开光标
- if(SetPlace==6)
- {
- LCD12864_WriteCmd(0x0c); //显示开,关光标
- SetPlace=-1;keysun=2;
- biaozhi1=1;
- Ds1302Init();
- zhujiemian();
- }
- naoxianguangbiao();
- }
- }
- if(s4==0)
- {
- Delay1ms(10);
- if((s4==0)&&(keysun<=2))
- {
- while(s4==0); //松手检测
- biaozhi1=0;
- keysun=1;
- if(SetPlace==-1)
- {
- LCD12864_WriteCmd(0x01);
- naojie();
- SetPlace=7;
- LCD12864_SetWindow(0, 6);
- if(naobiao==0)
- {
- LCD12864_WriteData(xiqi[18]);
- LCD12864_WriteData(xiqi[19]); //显示关
- }
- else
- {
- LCD12864_WriteData(xiqi[16]);
- LCD12864_WriteData(xiqi[17]); //显示开
- }
- LCD12864_SetWindow(1, 2);
- LCD12864_WriteData(0x30+(naoshi/16)); //时
- LCD12864_WriteData(0x30+(naoshi&0x0f));
- LCD12864_SetWindow(1, 4);
- LCD12864_WriteData(0x30+(naofen/16)); //分
- LCD12864_WriteData(0x30+(naofen&0x0f));
- LCD12864_SetWindow(3, 0);
- if(linsheng==1)
- {
- for(zishu=0;zishu<16;zishu++)
- {
- LCD12864_WriteData(naozhonglinshen[zishu]);
- }
- }
- if(linsheng==2)
- for(zishu=16;zishu<32;zishu++)
- {
- LCD12864_WriteData(naozhonglinshen[zishu]);
- }
- if(linsheng==3)
- for(zishu=32;zishu<48;zishu++)
- {
- LCD12864_WriteData(naozhonglinshen[zishu]);
- }
- if(linsheng==4)
- for(zishu=48;zishu<64;zishu++)
- {
- LCD12864_WriteData(naozhonglinshen[zishu]);
- }
- if(linsheng==5)
- for(zishu=64;zishu<80;zishu++)
- {
- LCD12864_WriteData(naozhonglinshen[zishu]);
- }
- }
- SetPlace++;
- LCD12864_WriteCmd(0x0f); //显示开,开光标
- if(SetPlace>=12)
- {
- LCD12864_WriteCmd(0x0c); //显示开,关光标
- SetPlace=-1;keysun=2;
- biaozhi1=1;
- LCD12864_WriteCmd(0x01);
- zhujiemian();
- }
- naoxianguangbiao();
- naoxian();
- }
- }
- if(biaozhi1==0)
- {
- if(s2==0) //检测按键K2是否按下
- {
- Delay1ms(10); //消除抖动
- if(s2==0)
- {
- while(s2==0); //松手检测
- if(SetPlace<=6)
- {
- TIME[SetPlace]++;
- if((TIME[SetPlace]&0x0f)>9) //换成BCD码。
- TIME[SetPlace]=TIME[SetPlace]+6;
- if((TIME[SetPlace]>=0x60)&&(SetPlace<2)) //分秒只能到59
- TIME[SetPlace]=0;
- if((TIME[SetPlace]>=0x24)&&(SetPlace==2)) //小时只能到23
- TIME[SetPlace]=0;
- if((TIME[SetPlace]>=0x32)&&(SetPlace==3)) //日只能到31
- TIME[SetPlace]=1;
- if((TIME[SetPlace]>=0x13)&&(SetPlace==4)) //月只能到12
- TIME[SetPlace]=1;
- if((TIME[SetPlace]>=0x8)&&(SetPlace==5)) //周只能到7
- TIME[SetPlace]=1;
- }
- else
- {
- if(SetPlace==8)
- {
- naobiao=~naobiao;
- if(naobiao==0)
- {
- LCD12864_WriteData(xiqi[18]);
- LCD12864_WriteData(xiqi[19]);
- }
- else
- {
- LCD12864_WriteData(xiqi[16]);
- LCD12864_WriteData(xiqi[17]);
- }
- }
- if(SetPlace==9)
- {
- naoshi++;
- if((naoshi&0x0f)>9) //换成BCD码。
- naoshi=naoshi+6;
- if(naoshi>=0x24)
- naoshi=0;
- }
- if(SetPlace==10)
- {
- naofen++;
- if((naofen&0x0f)>9) //换成BCD码。
- naofen=naofen+6;
- if(naofen>=0x60)
- naofen=0;
- }
- if(SetPlace==11)
- {
- linsheng++;
- if(linsheng==6)
- linsheng=1;
- }
- }
- }
- shixian();
- naoxian();
- }
- if(s3==0) //检测按键K3是否按下
- {
- Delay1ms(10); //消除抖动
- if(s3==0)
- {
- while(s3==0); //松手检测
- if(SetPlace<=6)
- {
- TIME[SetPlace]--;
- if((TIME[SetPlace]&0x0f)>9) //换成BCD码。
- TIME[SetPlace]=TIME[SetPlace]-6;
- if((TIME[SetPlace]<=-1)&&(SetPlace<2)) //分秒只能到59
- TIME[SetPlace]=0x59;
- if((TIME[SetPlace]<=-1)&&(SetPlace==2)) //小时只能到23
- TIME[SetPlace]=0x23;
- if((TIME[SetPlace]<=0)&&(SetPlace==3)) //日只能到31
- TIME[SetPlace]=0x31;
- if((TIME[SetPlace]<=0)&&(SetPlace==4)) //月只能到12
- TIME[SetPlace]=0x12;
- if((TIME[SetPlace]<=0)&&(SetPlace==5)) //周只能到7
- TIME[SetPlace]=7;
- }
- else
- {
- if(SetPlace==8)
- {
- naobiao=~naobiao;
- if(naobiao==0)
- {
- LCD12864_WriteData(xiqi[18]);
- LCD12864_WriteData(xiqi[19]); //显示开关
- }
- else
- {
- LCD12864_WriteData(xiqi[16]);
- LCD12864_WriteData(xiqi[17]); //显示开关
- }
- }
- if(SetPlace==9) //闹钟时
- {
- naoshi--;
- if((naoshi&0x0f)>9) //换成BCD码。
- naoshi=naoshi-6;
- if(naoshi<0)
- naoshi=0x23;
- }
- if(SetPlace==10) //闹钟分
- {
- naofen--;
- if((naofen&0x0f)>9) //换成BCD码。
- naofen=naofen-6;
- if(naofen<0)
- naofen=0x59;
- }
- if(SetPlace==11) //铃声选择
- {
- linsheng--;
- if(linsheng==0)
- linsheng=5;
- }
- }
- }
- naoxian();
- shixian();
- }
- }
- }
- void jiemian()
- {
- unsigned char i=0;
- LCD12864_SetWindow(0, 0);
- while(CharCode[i]!='\0')
- {
- LCD12864_WriteData(CharCode[i]);
- i++;
- if(i==16) //第一行满写第二行
- LCD12864_SetWindow(1,0);
- if(i==32) //第二行满写第三行
- LCD12864_SetWindow(2,0);
- if(i==48) //第三行满写第四行
- LCD12864_SetWindow(3,0);
- }
- }
- void Delay1ms(unsigned int y)
- {
- unsigned int x;
- for(y;y>0;y--)
- for(x=110;x>0;x--);
- }
- /*******************************************************************************
- * 函数名 : Ds18b20Init
- * 函数功能 : 初始化
- * 输入 : 无
- * 输出 : 初始化成功返回1,失败返回0
- *******************************************************************************/
- unsigned char Ds18b20Init()
- {
- unsigned int i;
- DSPORT=0; //将总线拉低480us~960us
- i=70;
- while(i--);//延时642us
- DSPORT=1; //然后拉高总线,如果DS18B20做出反应会将在15us~60us后总线拉低
- i=0;
- while(DSPORT) //等待DS18B20拉低总线
- {
- i++;
- if(i>5000)//等待>5MS
- return 0;//初始化失败
- }
- return 1;//初始化成功
- }
- /*******************************************************************************
- * 函数名 : Ds18b20WriteByte
- * 函数功能 : 向18B20写入一个字节
- * 输入 : com
- * 输出 : 无
- *******************************************************************************/
- void Ds18b20WriteByte(unsigned char dat)
- {
- unsigned int i,j;
- for(j=0;j<8;j++)
- {
- DSPORT=0; //每写入一位数据之前先把总线拉低1us
- i++;
- DSPORT=dat&0x01; //然后写入一个数据,从最低位开始
- i=6;
- while(i--); //延时68us,持续时间最少60us
- DSPORT=1; //然后释放总线,至少1us给总线恢复时间才能接着写入第二个数值
- dat>>=1;
- }
- }
- /*******************************************************************************
- * 函数名 : Ds18b20ReadByte
- * 函数功能 : 读取一个字节
- * 输入 : com
- * 输出 : 无
- *******************************************************************************/
- unsigned char Ds18b20ReadByte()
- {
- unsigned char byte,bi;
- unsigned int i,j;
- for(j=8;j>0;j--)
- {
- DSPORT=0;//先将总线拉低1us
- i++;
- DSPORT=1;//然后释放总线
- i++;
- i++;//延时6us等待数据稳定
- bi=DSPORT; //读取数据,从最低位开始读取
- /*将byte左移一位,然后与上右移7位后的bi,注意移动之后移掉那位补0。*/
- byte=(byte>>1)|(bi<<7);
- i=4; //读取完之后等待48us再接着读取下一个数
- while(i--);
- }
- return byte;
- }
- /*******************************************************************************
- * 函数名 : Ds18b20ChangTemp
- * 函数功能 : 让18b20开始转换温度
- * 输入 : com
- * 输出 : 无
- *******************************************************************************/
- void Ds18b20ChangTemp()
- {
- Ds18b20Init();
- Delay1ms(1);
- Ds18b20WriteByte(0xcc); //跳过ROM操作命令
- Ds18b20WriteByte(0x44); //温度转换命令
- Delay1ms(100); //等待转换成功,而如果你是一直刷着的话,就不用这个延时了
- }
- /*******************************************************************************
- * 函数名 : Ds18b20ReadTempCom
- * 函数功能 : 发送读取温度命令
- * 输入 : com
- * 输出 : 无
- *******************************************************************************/
- void Ds18b20ReadTempCom()
- {
- Ds18b20Init();
- Delay1ms(1);
- Ds18b20WriteByte(0xcc); //跳过ROM操作命令
- Ds18b20WriteByte(0xbe); //发送读取温度命令
- }
- /*******************************************************************************
- * 函数名 : Ds18b20ReadTemp
- * 函数功能 : 读取温度
- * 输入 : com
- * 输出 : 无
- *******************************************************************************/
- int Ds18b20ReadTemp()
- {
- int temp=0;
- unsigned char tmh,tml;
- Ds18b20ChangTemp(); //先写入转换命令
- Ds18b20ReadTempCom(); //然后等待转换完后发送读取温度命令
- tml=Ds18b20ReadByte(); //读取温度值共16位,先读低字节
- tmh=Ds18b20ReadByte(); //再读高字节
- temp=tmh;
- temp<<=8;
- temp|=tml;
- return temp;
- }
- void LcdDisplay(int temp) //lcd显示
- {
-
- unsigned char datas[] = {0, 0, 0, 0, 0}; //定义数组
- float tp;
- if(temp< 0) //当温度值为负数
- {
- LCD12864_SetWindow(3, 5);
- LCD12864_WriteData(0x2d); //显示负
- //因为读取的温度是实际温度的补码,所以减1,再取反求出原码
- temp=temp-1;
- temp=~temp;
- tp=temp;
- temp=tp*0.0625*100+0.5;
- //留两个小数点就*100,+0.5是四舍五入,因为C语言浮点数转换为整型的时候把小数点
- //后面的数自动去掉,不管是否大于0.5,而+0.5之后大于0.5的就是进1了,小于0.5的就
- //算由?.5,还是在小数点后面。
- datas[2] = temp % 1000 / 100;
- datas[3] = temp % 100 / 10;
- //写地址 80表示初始地址
- LCD12864_WriteData(0x30+datas[2]); //个位
- LCD12864_WriteData(0x2e); //显示 ‘.’
- LCD12864_WriteData(0x30+datas[3]); //显示小数点
-
- }
- else
- {
- LCD12864_SetWindow(3, 5);
- tp=temp;//因为数据处理有小数点所以将温度赋给一个浮点型变量
- //如果温度是正的那么,那么正数的原码就是补码它本身
- temp=tp*0.0625*100+0.5;
- //留两个小数点就*100,+0.5是四舍五入,因为C语言浮点数转换为整型的时候把小数点
- //后面的数自动去掉,不管是否大于0.5,而+0.5之后大于0.5的就是进1了,小于0.5的就
- //算加上0.5,还是在小数点后面。
-
- datas[1] = temp % 10000 / 1000;
- datas[2] = temp % 1000 / 100;
- datas[3] = temp % 100 / 10;
- //写地址
- LCD12864_WriteData(0x30+datas[1]); //十位
- LCD12864_WriteData(0x30+datas[2]); //个位
- LCD12864_WriteData(0x2e); //显示 ‘.’
- LCD12864_WriteData(0x30+datas[3]); //显示小数点
- }
- }
- void Ds1302Write(uchar addr, uchar dat)
- {
- uchar n;
- RST = 0;
- _nop_();
- SCLK = 0;//先将SCLK置低电平。
- _nop_();
- RST = 1; //然后将RST(CE)置高电平。
- _nop_();
- for (n=0; n<8; n++)//开始传送八位地址命令
- {
- DSIO = addr & 0x01;//数据从低位开始传送
- addr >>= 1;
- SCLK = 1;//数据在上升沿时,DS1302读取数据
- _nop_();
- SCLK = 0;
- _nop_();
- }
- for (n=0; n<8; n++)//写入8位数据
- {
- DSIO = dat & 0x01;
- dat >>= 1;
- SCLK = 1;//数据在上升沿时,DS1302读取数据
- _nop_();
- SCLK = 0;
- _nop_();
- }
-
- RST = 0;//传送数据结束
- _nop_();
- }
- uchar Ds1302Read(uchar addr)
- {
- uchar n,dat,dat1;
- RST = 0;
- _nop_();
- SCLK = 0;//先将SCLK置低电平。
- _nop_();
- RST = 1;//然后将RST(CE)置高电平。
- _nop_();
- for(n=0; n<8; n++)//开始传送八位地址命令
- {
- DSIO = addr & 0x01;//数据从低位开始传送
- addr >>= 1;
- SCLK = 1;//数据在上升沿时,DS1302读取数据
- _nop_();
- SCLK = 0;//DS1302下降沿时,放置数据
- _nop_();
- }
- _nop_();
- for(n=0; n<8; n++)//读取8位数据
- {
- dat1 = DSIO;//从最低位开始接收
- dat = (dat>>1) | (dat1<<7);
- SCLK = 1;
- _nop_();
- SCLK = 0;//DS1302下降沿时,放置数据
- _nop_();
- }
- RST = 0;
- _nop_(); //以下为DS1302复位的稳定时间,必须的。
- SCLK = 1;
- _nop_();
- DSIO = 0;
- _nop_();
- DSIO = 1;
- _nop_();
- return dat;
- }
- void Ds1302Init()
- {
- uchar n;
- Ds1302Write(0x8E,0X00); //禁止写保护,就是关闭写保护功能
- for (n=0; n<7; n++)//写入7个字节的时钟信号:分秒时日月周年
- {
- Ds1302Write(WRITE_RTC_ADDR[n],TIME[n]);
- }
- Ds1302Write(0x8E,0x80); //打开写保护功能
- }
- void Ds1302ReadTime()
- {
- uchar n;
- for (n=0; n<7; n++)//读取7个字节的时钟信号:分秒时日月周年
- {
- TIME[n] = Ds1302Read(READ_RTC_ADDR[n]);
- }
- }
- void TimerConfiguration()
- {
- TMOD = 0x11; //选择工作方式1
- TH0 = 0x3C; //设置初始值,定时50MS
- TL0 = 0xB0;
- EA = 1; //打开总中断
- ET0 = 1; //打开定时器0中断
- TR0 = 1; //启动定时器0
- zz=0;//关蜂鸣器
- TH1=0xd8;TL1=0xef;
- ET1=1;
- }
- void Timer0() interrupt 1
- {
- TH0 = 0x3C; //设置初始值
- TL0 = 0xB0;
- timeji++;
- if(timeji==200)
- {
- timeji=0;
- biaozhi=0;
- }
- }
- void display()
- {
- LCD12864_SetWindow(1, 0);
- LCD12864_WriteData(0x30+TIME[6]/16); // 年
- LCD12864_WriteData(0x30+(TIME[6]&0x0f));
- LCD12864_SetWindow(1, 2);
- LCD12864_WriteData(0x30+TIME[4]/16); //月
- LCD12864_WriteData(0x30+(TIME[4]&0x0f));
- LCD12864_SetWindow(1, 4);
- LCD12864_WriteData(0x30+TIME[3]/16); //日
- LCD12864_WriteData(0x30+(TIME[3]&0x0f));
- LCD12864_SetWindow(1, 7);
- LCD12864_WriteData(xiqi[(TIME[5]&0x07)*2]); //星期
- LCD12864_WriteData(xiqi[(TIME[5]&0x07)*2+1]);
- LCD12864_SetWindow(2, 2);
- LCD12864_WriteData(0x30+TIME[2]/16); //时
- LCD12864_WriteData(0x30+(TIME[2]&0x0f));
- LCD12864_SetWindow(2, 4);
- LCD12864_WriteData(0x30+TIME[1]/16); //分
- LCD12864_WriteData(0x30+(TIME[1]&0x0f));
- LCD12864_SetWindow(2, 6);
- LCD12864_WriteData(0x30+TIME[0]/16); //秒
- LCD12864_WriteData(0x30+(TIME[0]&0x0f));
- }
复制代码
|