#incl- #include "STC12C5A60S2.h"
- #include <intrins.h>
- #define uchar unsigned char
- #define uint unsigned int
- uchar l_tmpDate[]={0,0,0,1,1,1,13};//秒分时日月周年08-05-15 12:00:00
- uchar l_tmpdisplay[15];
- code uchar Write_rtc_address[7]={0x80,0x82,0x84,0x86,0x88,0x8a,0x8c}; //秒分时日月周年 最低位读写位
- code uchar Read_RTC_address[7]={0x81,0x83,0x85,0x87,0x89,0x8b,0x8d};
- sbit SCK = P1^3; //DS1302时钟;
- sbit SDA = P1^4; //DS1302数据;
- sbit RST = P1^5;// DS1302复位;
- uchar set=0; //按键选择标志位;
- char key_flag=0;//按键加减标志位;
- uchar menue=0; //菜单选择标志位;
- uchar ok=0; //确认标志位;
- char miao,fen,shi,ri,yue,zhou,nian;/*时间日期数值标志位;*/
- /////////////DS1302写一个字节/////
- void Write_Ds1302_Byte(uchar temp)
- {
- uchar i;
- for (i=0;i<8;i++) //循环8次 写入数据
- {
- SCK=0;
- SDA=temp&0x01; //每次传输低字节
- temp>>=1; //右移一位
- SCK=1;
- }
- }
- /*****************/ /*
- 写入DS1302
- */ /************************/
- void Write_Ds1302(uchar address,uchar dat )
- {
- RST=0; _nop_();
- SCK=0; _nop_();
- RST=1; _nop_(); //启动
- Write_Ds1302_Byte(address); //发送地址
- Write_Ds1302_Byte(dat); //发送数据
- RST=0; //恢复
- }
- /***************/ /*
- 读出DS1302数据
- */ /*********************/
- uchar Read_Ds1302 ( uchar address )
- {
- uchar i,temp=0x00;
- RST=0; _nop_(); _nop_();
- SCK=0; _nop_(); _nop_();
- RST=1; _nop_();
- _nop_();
- Write_Ds1302_Byte(address);
- for (i=0;i<8;i++) //循环8次 读取数据
- {
- if(SDA)
- {
- temp|=0x80;
- } //每次传输低字节
- temp>>=1; //右移一位
- SCK=1; _nop_(); _nop_();
- SCK=0;
- }
- RST=0; _nop_();
- //以下为DS1302复位的稳定时间
- _nop_();
- RST=0;
- SCK=0; _nop_(); _nop_(); _nop_(); _nop_();
- SCK=1; _nop_(); _nop_();
- SDA=0; _nop_(); _nop_();
- SDA=1; _nop_(); _nop_();
- return (temp); //返回
- }
- /**************************/ /*
- 读时钟数据
- */ /***********************/
- void Read_RTC(void) //读取 日历
- {
- uchar i,*p;
- p=Read_RTC_address; //地址传递
- for(i=0;i<7;i++) //分7次读取 秒分时日月周年
- {
- l_tmpDate[i]=Read_Ds1302(*p);
- p++;
- }
- }
- /***************************/ /*
- 设定时钟数据
- */ /************************/
- void Set_RTC(void) //设定 日历
- {
- uchar i,*p,tmp;
- for(i=0;i<7;i++)
- { //BCD处理
- tmp=l_tmpDate[i]/10;
- l_tmpDate[i]=l_tmpDate[i]%10;
- l_tmpDate[i]=l_tmpDate[i]+tmp*16;
- }
- Write_Ds1302(0x8E,0X00); //关闭写保护;
- p=Write_rtc_address; //传地址
- for(i=0;i<7;i++) //7次写入 秒分时日月周年
- {
- Write_Ds1302(*p,l_tmpDate[i]);
- p++;
- }
- Write_Ds1302(0x8E,0x80); //打开写保护;
- }
- /*********8x16字模 ****************************/
- //取模方式:逐行式 逆向 阴码 宽x高=8x16
- uchar code table[]={
- /*-- 文字: 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,0x08,0x0E,0x08,0x08,0x08,0x08,0x08,0x08,0x08,
- 0x08,0x3E,0x00,0x00,
- /*-- 文字: 2 --*/ /*-- 宋体12;
- 此字体下对应的点阵为:宽x高=8x16 --*/
- 0x00,0x00,0x00,0x3C,0x42,0x42,0x42,0x20,0x20,0x10,0x08,0x04,
- 0x42,0x7E,0x00,0x00,
- /*-- 文字: 3 --*/ /*-- 宋体12;
- 此字体下对应的点阵为:宽x高=8x16 --*/
- 0x00,0x00,0x00,0x3C,0x42,0x42,0x20,0x18,0x20,0x40,0x40,0x42,
- 0x22,0x1C,0x00,0x00,
- /*-- 文字: 4 --*/ /*-- 宋体12;
- 此字体下对应的点阵为:宽x高=8x16 --*/
- 0x00,0x00,0x00,0x20,0x30,0x28,0x24,0x24,0x22,0x22,0x7E,0x20,
- 0x20,0x78,0x00,0x00,
- /*-- 文字: 5 --*/ /*-- 宋体12;
- 此字体下对应的点阵为:宽x高=8x16 --*/
- 0x00,0x00,0x00,0x7E,0x02,0x02,0x02,0x1A,0x26,0x40,0x40,0x42,
- 0x22,0x1C,0x00,0x00,
- /*-- 文字: 6 --*/ /*-- 宋体12;
- 此字体下对应的点阵为:宽x高=8x16 --*/
- 0x00,0x00,0x00,0x38,0x24,0x02,0x02,0x1A,0x26,0x42,0x42,0x42,
- 0x24,0x18,0x00,0x00,
- /*-- 文字: 7 --*/ /*-- 宋体12;
- 此字体下对应的点阵为:宽x高=8x16 --*/
- 0x00,0x00,0x00,0x7E,0x22,0x22,0x10,0x10,0x08,0x08,0x08,0x08,
- 0x08,0x08,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,0x64,0x58,0x40,0x40,
- 0x24,0x1C,0x00,0x00,
- /*-- 文字: - --*///10; /*-- 宋体12;
- //此字体下对应的点阵为:宽x高=8x16 --*/
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFE,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,
- /*-- 文字: : --*///11; /*-- 宋体12;
- //此字体下对应的点阵为:宽x高=8x16 --*/
- ////0x00,0x00,0x00,0x18,0x18,0x00,0x00,0x00,0x00,0x00,
- //0x18,0x18,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x00,0x00,0x00,0x00,
- 0x18,0x18,0x00,0x00,
- /*-- 文字: _ --*///12 /*-- 宋体12;
- //此字体下对应的点阵为:宽x高=8x16 --*/
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0xFF,
- /****************空格****13*****************/
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,/*" ",0*/
- //////////////C//14//////////////
- //取模方式:逐行式 逆向 阴码 宽x高=8x16
- 0x00,0x00,0x3C,0x3E,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,
- 0x02,0x3E,0x3C,0x00,
- //14 'a'-83;
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3C, 0x42,0x78,0x44,
- 0x42,0x42,0xFC,0x00,0x00,/*"a",0*/
- 0x00,0x00,0x00,0x03,0x02,0x02,0x02,0x1A,
- 0x26,0x42,0x42,0x42,0x26,0x1A,0x00,0x00,/*"b",1*/
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x38,
- 0x44,0x02,0x02,0x02,0x44,0x38,0x00,0x00,/*"c",2*/
- 0x00,0x00,0x00,0x60,0x40,0x40,0x40,0x78,
- 0x44,0x42,0x42,0x42,0x64,0xD8,0x00,0x00,/*"d",3*/
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3C,
- 0x42,0x7E,0x02,0x02,0x42,0x3C,0x00,0x00,/*"e",4*/
- 0x00,0x00,0x00,0xF0,0x88,0x08,0x08,0x7E,
- 0x08,0x08,0x08,0x08,0x08,0x3E,0x00,0x00,/*"f",5*/
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7C,
- 0x22,0x22,0x1C,0x02,0x3C,0x42,0x42,0x3C,/*"g",6*/
- 0x00,0x00,0x00,0x03,0x02,0x02,0x02,0x3A,
- 0x46,0x42,0x42,0x42,0x42,0xE7,0x00,0x00,/*"h",7*/
- 0x00,0x00,0x00,0x0C,0x0C,0x00,0x00,0x0E,
- 0x08,0x08,0x08,0x08,0x08,0x3E,0x00,0x00,/*"i",8*/
- 0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x38,
- 0x20,0x20,0x20,0x20,0x20,0x20,0x22,0x1E,/*"j",9*/
- 0x00,0x00,0x00,0x03,0x02,0x02,0x02,0x72,
- 0x12,0x0A,0x16,0x12,0x22,0x77,0x00,0x00,/*"k",10*/
- 0x00,0x00,0x00,0x0E,0x08,0x08,0x08,0x08,
- 0x08,0x08,0x08,0x08,0x08,0x3E,0x00,0x00,/*"l",11*/
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,
- 0x92,0x92,0x92,0x92,0x92,0xB7,0x00,0x00,/*"m",12*/
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3B,
- 0x46,0x42,0x42,0x42,0x42,0xE7,0x00,0x00,/*"n",13*/
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3C,
- 0x42,0x42,0x42,0x42,0x42,0x3C,0x00,0x00,/*"o",14*/
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1B,
- 0x26,0x42,0x42,0x42,0x22,0x1E,0x02,0x07,/*"p",15*/
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x78,
- 0x44,0x42,0x42,0x42,0x44,0x78,0x40,0xE0,/*"q",16*/
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x77,
- 0x4C,0x04,0x04,0x04,0x04,0x1F,0x00,0x00,/*"r",17*/
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7C,
- 0x42,0x02,0x3C,0x40,0x42,0x3E,0x00,0x00,/*"s",18*/
- 0x00,0x00,0x00,0x00,0x00,0x08,0x08,0x3E,
- 0x08,0x08,0x08,0x08,0x08,0x30,0x00,0x00,/*"t",19*/
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x63,
- 0x42,0x42,0x42,0x42,0x62,0xDC,0x00,0x00,/*"u",20*/
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xE7,
- 0x42,0x24,0x24,0x14,0x08,0x08,0x00,0x00,/*"v",21*/
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xEB,
- 0x49,0x49,0x55,0x55,0x22,0x22,0x00,0x00,/*"w",22*/
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x76,
- 0x24,0x18,0x18,0x18,0x24,0x6E,0x00,0x00,/*"x",23*/
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xE7,
- 0x42,0x24,0x24,0x14,0x18,0x08,0x08,0x07,/*"y",24*/
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7E,
- 0x22,0x10,0x08,0x08,0x44,0x7E,0x00,0x00,/*"z",25*/
- };
- /************16x16 字模 ***************/
- //取模方式:逐行式 逆向 阴码 宽x高=16x16
- uchar code table1[]={
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x7F,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*"一",0*/
- 0x00,0x00,0x00,0x00,0x00,0x00,0xFC,0x1F,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0xFF,0x7F,0x00,0x00,0x00,0x00,0x00,0x00,/*"二",1*/
-
- 0x00,0x00,0x00,0x00,0xFE,0x3F,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0xFC,0x1F,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0xFF,0x7F,0x00,0x00,0x00,0x00,/*"三",2*/
-
- 0x00,0x00,0x00,0x00,0xFE,0x3F,0x22,0x22,
- 0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,
- 0x12,0x22,0x12,0x3C,0x0A,0x20,0x06,0x20,
- 0x02,0x20,0xFE,0x3F,0x02,0x20,0x00,0x00,/*"四",3*/
- 0x00,0x00,0xFE,0x3F,0x40,0x00,0x40,0x00,
- 0x40,0x00,0x40,0x00,0xFC,0x0F,0x20,0x08,
- 0x20,0x08,0x20,0x08,0x20,0x08,0x10,0x08,
- 0x10,0x08,0x10,0x08,0xFF,0x7F,0x00,0x00,/*"五",4*/
- 0x40,0x00,0x80,0x00,0x00,0x01,0x00,0x01,
- 0x00,0x00,0xFF,0x7F,0x00,0x00,0x00,0x00,
- 0x20,0x02,0x20,0x04,0x10,0x08,0x10,0x10,
- 0x08,0x10,0x04,0x20,0x02,0x20,0x00,0x00,/*"六",5*/
- 0x00,0x00,0xF8,0x0F,0x08,0x08,0x08,0x08,
- 0x08,0x08,0x08,0x08,0x08,0x08,0xF8,0x0F,
- 0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,
- 0x08,0x08,0x08,0x08,0xF8,0x0F,0x08,0x08,/*"日",6*/
- 0x00,0x00,0xF8,0x0F,0x08,0x08,0xF8,0x0F,
- 0x08,0x08,0xF8,0x0F,0x80,0x00,0x88,0x00,
- 0xF8,0x1F,0x84,0x00,0x82,0x00,0xF8,0x0F,
- 0x80,0x00,0x80,0x00,0xFE,0x3F,0x00,0x00,/*"星",7*/
- 0x44,0x00,0x44,0x3E,0xFE,0x22,0x44,0x22,
- 0x44,0x22,0x7C,0x3E,0x44,0x22,0x44,0x22,
- 0x7C,0x22,0x44,0x3E,0x44,0x22,0xFF,0x22,
- 0x20,0x21,0x44,0x21,0x82,0x28,0x41,0x10,/*"期",8*/
-
- 0x00,0x00,0xE0,0x0F,0x62,0x0C,0xE6,0x0F,0x6C,0x0C,
- 0xEA,0x0F,0x06,0x00,0xF4,0x1F,0x3C,0x18,0xB0,0x1A,
- 0xBC,0x1A,0xB4,0x1A,0xB2,0x1A,0xFB,0x3F,0xF9,0x3F,
- 0x00,0x00, /////////////////////温////9//
- 0x00,0x00,0xC0,0x00,0x80,0x00,0xFC,0x0F,0x0C,0x00,
- 0x6C,0x03,0xFC,0x0F,0x6C,0x03,0xEC,0x03,0x0C,0x00,
- 0xEC,0x07,0x6C,0x06,0xCC,0x03,0x66,0x06,0x33,0x0C,
- 0x00,0x00,/////////////////度、、、、、、10//
- 0x00,0x00,0x0C,0x00,0xFC,0x1F,0x0C,0x00,0xF6,0x07,
- 0xB0,0x01,0xB0,0x01,0xB0,0x01,0xFC,0x0F,0x80,0x01,
- 0x80,0x01,0x80,0x01,0x80,0x01,0x80,0x01,0x00,0x00,
- 0x00,0x00,///////////年、、、、、、、、、11//
- 0x00,0x00,0xF8,0x0F,0x18,0x0C,0x18,0x0C,0x18,0x0C,
- 0xF8,0x0D,0x18,0x0C,0x18,0x0C,0xF8,0x0D,0x18,0x0C,
- 0x18,0x0C,0x1C,0x0C,0x1C,0x0C,0x0E,0x0F,0x06,0x06,
- 0x00,0x00,///////////月////////////12///
- //0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- //0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- //9; //0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- //0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- };
复制代码 ude "macroandconst.h" 文件。 |