/******************************************************************************/
/* Name: LCD12864(KS0108+KS0107)+DS1302+DS18B20+S52 */
/* */
/* Designed by : 李 海 群 */
/* */
/* http://www.mculover.net */
/* http://www.mculover.net/whoami Date : 2005/12/13 */
/******************************************************************************/
#include
***it Bell_Out = P3 ^ 7;//闹钟管脚输出。低电平有效
***it Bak_Light = P2 ^ 0;//LCD背光控制,低电平有效
***it DQ = P3 ^ 5;//ds1820data
***it clock_clk = P1 ^ 3;//ds1302_clk
***it clock_dat = P1 ^ 4;//ds1302_dat
***it clock_Rst = P1 ^ 5;//ds1302_Rst
#define Disp_On 0x3f //定义12864管脚的指令值
#define Disp_Off 0x3e
#define Col_Add 0x40
#define Page_Add 0xb8
#define Start_Line 0xc0
#define Lcd_Bus P0 //定义12864数据口
***it Mcs = P2 ^ 7; //12864CS1
***it Scs = P2 ^ 6; //CS2
***it Enable = P1 ^ 2; //Enable
***it Di = P1 ^ 0; //di
***it RW = P1 ^ 1; //rw
***it Lcd_Rst= P2 ^ 5; //rst
//键盘扫描
***it Add_Key = P1 ^ 6;//加1键,S1
***it Dec_Key = P1 ^ 7;//减1键,S2
***it OK_Key = P3 ^ 2;//确定键,S3
***it Rst_Key = P3 ^ 3;//系统复位键,S4
//为了编程方便定义的位变量
***it a0 = ACC ^ 0;
***it a1 = ACC ^ 1;
***it a2 = ACC ^ 2;
***it a3 = ACC ^ 3;
***it a4 = ACC ^ 4;
***it a5 = ACC ^ 5;
***it a6 = ACC ^ 6;
***it a7 = ACC ^ 7;
bit flag, Bell_Swh,Hourb,Minb,Secb,Kgb;//闹钟调时闪烁标志位
bit sec=0,min=0,hour=0,year=0,mon=0,day=0,weekk=0; //闪烁标志位
bit flag_min = 0,flag_sec = 0;//整点报警标志位
unsigned char id,id2,d,e,S_1302,H_1302,H_Bell,S_Bell; //
//Function Definition 函数声明
void Delay(int num);
void Init_DS18B20(void);
unsigned char ReadOneChar(void);
void WriteOneChar(unsigned char dat);
unsigned int ReadTemperature(void);
void clock_out(unsigned char dd);
unsigned char clock_in(void);
unsigned char read_clock(unsigned char ord);
void write_clock(unsigned char ord, unsigned char dd);
void Disp(void);
void id_case1_key(void);
void id_case2_key(void);
void Set_time(unsigned char sel,bit sel_1);
void Timer0_Init(void);
void Init_1302(void);
void Set_Bell(unsigned char sel, bit sel_1);
void Beep(void);
//12864
void Delay12864(unsigned int t);
void write_com(unsigned char cmdcode);
void write_data(unsigned char Dispdata);
void frame(void);
void Clr_Scr(void);
void Disp_Img(unsigned char code *img);
void Disp_Digit(unsigned char pag,unsigned char col, unsigned char code *hzk);
void Disp_Chinese(unsigned char pag,unsigned char col, unsigned char code *hzk);
void Init_lcd(void);
//汉字库及数字符号库
unsigned char code nao[32]={0x00,0x00,0xF9,0x12,0x90,0x92,0x96,0xFA,0x92,0x92,0x92,0x12,0x02,0xFE,0x00,0x00,
0x00,0x00,0xFF,0x00,0x1F,0x00,0x00,0x7F,0x00,0x08,0x1F,0x40,0x80,0x7F,0x00,0x00};/*-- 文字: 闹 --*/
unsigned char code zhong[32]={0x40,0x30,0x2C,0xEB,0x28,0x28,0x00,0xF8,0x08,0x08,0xFF,0x08,0x08,0xF8,0x00,0x00,
0x01,0x01,0x01,0xFF,0x41,0x21,0x00,0x01,0x01,0x01,0xFF,0x01,0x01,0x01,0x00,0x00};/*-- 文字: 钟 --*/
unsigned char code she[32]={0x40,0x41,0xCE,0x04,0x00,0x80,0x40,0xBE,0x82,0x82,0x82,0xBE,0xC0,0x40,0x40,0x00,
0x00,0x00,0x7F,0x20,0x90,0x80,0x40,0x43,0x2C,0x10,0x10,0x2C,0x43,0xC0,0x40,0x00};/*-- 文字: 设 --*/
unsigned char code ding[32]={0x00,0x10,0x0C,0xA4,0x24,0x24,0x25,0xE6,0x24,0x24,0x24,0x24,0x14,0x0C,0x04,0x00,
0x40,0x20,0x18,0x07,0x08,0x10,0x20,0x7F,0x42,0x42,0x42,0x42,0x40,0x40,0x00,0x00};/*-- 文字: 定 --*/
unsigned char code kai[32]={0x40,0x42,0x42,0x42,0x42,0xFE,0x42,0x42,0x42,0x42,0xFE,0x42,0x42,0x42,0x42,0x00,
0x00,0x40,0x20,0x10,0x0C,0x03,0x00,0x00,0x00,0x00,0x7F,0x00,0x00,0x00,0x00,0x00};/*-- 文字: 开 --*/
unsigned char code guan[32]={0x00,0x10,0x10,0x10,0x11,0x1E,0x14,0xF0,0x10,0x18,0x17,0x12,0x18,0x10,0x00,0x00,
0x01,0x81,0x41,0x21,0x11,0x09,0x05,0x03,0x05,0x09,0x31,0x61,0xC1,0x41,0x01,0x00};/*-- 文字: 关 --*/
unsigned char code shit[32]={0x00,0xFC,0x44,0x44,0x44,0xFC,0x10,0x90,0x10,0x10,0x10,0xFF,0x10,0x10,0x10,0x00,
0x00,0x07,0x04,0x04,0x04,0x07,0x00,0x00,0x03,0x40,0x80,0x7F,0x00,0x00,0x00,0x00};/*-- 文字: 时 --*/
unsigned char code jian[32]={0x00,0xF8,0x01,0x06,0x00,0xF0,0x92,0x92,0x92,0x92,0xF2,0x02,0x02,0xFE,0x00,0x00,
0x00,0xFF,0x00,0x00,0x00,0x07,0x04,0x04,0x04,0x04,0x07,0x40,0x80,0x7F,0x00,0x00};/*-- 文字: 间 --*/
unsigned char code dao[32]={0x00,0x22,0x72,0x2A,0x26,0xE2,0x2A,0x72,0x22,0x00,0xF8,0x00,0x00,0xFF,0x00,0x00,
0x00,0x42,0xC2,0x42,0x22,0x3F,0x22,0x12,0x12,0x00,0x0F,0x40,0x80,0x7F,0x00,0x00};/*-- 文字: 到 --*/
unsigned char code shi[32]={0x00,0x10,0x2C,0x24,0xA4,0x64,0x25,0x26,0x24,0x24,0xA4,0x24,0x34,0x2C,0x04,0x00,
0x40,0x40,0x48,0x49,0x49,0x49,0x49,0x7F,0x49,0x49,0x49,0x4B,0x48,0x40,0x40,0x00};//室
unsigned char code wen[32]={0x10,0x21,0x86,0x70,0x00,0x7E,0x4A,0x4A,0x4A,0x4A,0x4A,0x7E,0x00,0x00,0x00,0x00,
0x02,0xFE,0x01,0x40,0x7F,0x41,0x41,0x7F,0x41,0x41,0x7F,0x41,0x41,0x7F,0x40,0x00};//温
unsigned char code zero[16]={0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00};//0
unsigned char code one[16]={0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00};//1
unsigned char code two[16]={0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00};//2
unsigned char code three[16]={0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00};//3
unsigned char code four[16]={0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00};//4
unsigned char code five[16]={0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00};//5
unsigned char code six[16]={0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00};//6
unsigned char code seven[16]={0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00};//7
unsigned char code eight[16]={0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00};//8
unsigned char code nine[16]={0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x00};//9
unsigned char code point[16]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,0x00,0x00};//小数点
unsigned char code maohao[16]={0x00,0x00,0x00,0xC0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00};//冒号
unsigned char code space[16]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};//空白
unsigned char code fh[16]={0x00,0x00,0x00,0xFC,0xFC,0x00,0x00,0x00,0x00,0x00,0x00,0x6F,0x6F,0x00,0x00,0x00};//!感叹号
unsigned char code nian[32]={0x40,0x20,0x10,0x0C,0xE3,0x22,0x22,0x22,0xFE,0x22,0x22,0x22,0x22,0x02,0x00,0x00,
0x04,0x04,0x04,0x04,0x07,0x04,0x04,0x04,0xFF,0x04,0x04,0x04,0x04,0x04,0x04,0x00};//年
unsigned char code yue[32]={0x00,0x00,0x00,0x00,0x00,0xFF,0x11,0x11,0x11,0x11,0x11,0xFF,0x00,0x00,0x00,0x00,
0x00,0x40,0x20,0x10,0x0C,0x03,0x01,0x01,0x01,0x21,0x41,0x3F,0x00,0x00,0x00,0x00};//月
unsigned char code xing[32]={0x00,0x00,0x00,0xBE,0x2A,0x2A,0x2A,0xEA,0x2A,0x2A,0x2A,0x2A,0x3E,0x00,0x00,0x00,
0x00,0x48,0x46,0x41,0x49,0x49,0x49,0x7F,0x49,0x49,0x49,0x49,0x49,0x41,0x40,0x00};//星
unsigned char code qi[32]={0x00,0x04,0xFF,0x54,0x54,0x54,0xFF,0x04,0x00,0xFE,0x22,0x22,0x22,0xFE,0x00,0x00,
0x42,0x22,0x1B,0x02,0x02,0x0A,0x33,0x62,0x18,0x07,0x02,0x22,0x42,0x3F,0x00,0x00};//期
unsigned char code cone[32]={0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0xC0,0x80,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};//一
unsigned char code ctwo[32]={0x00,0x00,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x06,0x04,0x00,0x00,0x00,
0x00,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x18,0x10,0x00};//二
unsigned char code cthree[32]={0x00,0x04,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x04,0x00,0x00,
0x00,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x00};//三
unsigned char code cfour[32]={0x00,0xFE,0x02,0x02,0x02,0xFE,0x02,0x02,0xFE,0x02,0x02,0x02,0x02,0xFE,0x00,0x00,
0x00,0x7F,0x28,0x24,0x23,0x20,0x20,0x20,0x21,0x22,0x22,0x22,0x22,0x7F,0x00,0x00};//四
unsigned char code cfive[32]={0x00,0x02,0x82,0x82,0x82,0x82,0xFE,0x82,0x82,0x82,0xC2,0x82,0x02,0x00,0x00,0x00,
0x20,0x20,0x20,0x20,0x20,0x3F,0x20,0x20,0x20,0x20,0x3F,0x20,0x20,0x30,0x20,0x00};//五
unsigned char code csix[32]={0x10,0x10,0x10,0x10,0x10,0x91,0x12,0x1E,0x94,0x10,0x10,0x10,0x10,0x10,0x10,0x00,
0x00,0x40,0x20,0x10,0x0C,0x03,0x01,0x00,0x00,0x01,0x02,0x0C,0x78,0x30,0x00,0x00};//六
unsigned char code ri[32]={0x00,0x00,0x00,0xFE,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0xFE,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x3F,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x3F,0x00,0x00,0x00,0x00};//日
unsigned char code sheshidu[32]={0x00,0x02,0x05,0xE2,0x18,0x04,0x02,0x02,0x02,0x02,0x02,0x02,0x04,0x1E,0x00,0x00,
0x00,0x00,0x00,0x07,0x18,0x20,0x40,0x40,0x40,0x40,0x40,0x40,0x20,0x18,0x00,0x00};//摄氏度的符号
unsigned char code spaces[32]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,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 biaozhi[32]={0x00,0x00,0x00,0x00,0xE0,0xF8,0xFC,0xFC,0xFC,0xFC,0xF8,0xE0,0x00,0x00,0x00,0x00,
0x00,0x10,0x18,0x3E,0x3F,0x7F,0x5F,0x9F,0x9F,0x5F,0x7F,0x3F,0x3E,0x18,0x10,0x00};//闹钟的图标
unsigned char code logo[]={ //开机画面-----湘灵电子工作室
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0xF0,0xF8,
0x38,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x80,0xC0,0xC0,
0xC0,0x80,0x80,0x80,0x80,0x80,0x80,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,0x00,0x00,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0x03,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0E,0x07,0x03,0x01,0x01,0x01,
0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x83,0xFF,0x3F,0x07,0x02,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x7E,0xFF,0x78,0xF0,0xC0,0xC0,0x80,0x00,0x80,0xC0,0xE0,0xFF,0xFF,0xE0,
0x80,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0xE0,0xF0,0x08,0x00,0x38,0x0C,0x02,
0x00,0x0C,0x87,0x81,0xC0,0xC0,0xC0,0xE0,0xE0,0xE0,0xF0,0xF0,0xF0,0xF0,0xF0,0xF0,
0xF0,0xE0,0xE0,0xE0,0xC0,0xC0,0x80,0x00,0x00,0x80,0x87,0x83,0x82,0x83,0x83,0x83,
0x81,0x81,0x81,0x81,0x81,0x80,0x80,0x80,0xC1,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0xE0,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x03,0x03,0xFF,0xFF,0xFF,0x01,
0x01,0x00,0x00,0x00,0xC0,0xF0,0x7C,0x0E,0x03,0x04,0xC0,0xE0,0xF0,0x78,0x3C,0x3E,
0x9F,0xCF,0xF7,0xF3,0xFF,0xFD,0xFD,0xFD,0xFC,0x9C,0xBC,0xFC,0xFC,0xFC,0xF8,0x00,
0x00,0x00,0x01,0x81,0xFF,0xFF,0xFF,0x7F,0x1C,0x01,0x01,0xC1,0x01,0x01,0x01,0x03,
0xFF,0xFF,0x03,0x01,0x01,0x01,0x01,0x81,0xC1,0x01,0x00,0x00,0x00,0x00,0x80,0xC0,
0x60,0x20,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x60,0xC0,0x00,0x00,0x00,0x00,0x80,
0x80,0x80,0x80,0x00,0x00,0x00,0x00,0x80,0x80,0x00,0x00,0x00,0x80,0xF8,0x1C,0x07,
0x03,0x06,0x06,0x0C,0x0C,0x06,0x06,0x0C,0x78,0xF0,0x80,0x00,0x00,0x00,0x00,0x00,
0x00,0x02,0x3F,0x0F,0x07,0x06,0x06,0xC2,0xE6,0x78,0x1C,0x0F,0x07,0xFF,0x3F,0x04,
0x00,0x00,0x00,0x3F,0x4F,0x00,0x00,0xF0,0xFC,0x1F,0x07,0x03,0x00,0x00,0x00,0x0E,
0x3F,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0xBF,0xDF,0xDF,0xEF,0xE7,0x77,0x31,0x38,
0x1C,0x0E,0x0F,0x07,0x83,0x81,0x00,0x00,0x18,0x0E,0x0F,0x07,0x0C,0x0C,0x10,0x00,
0xEF,0xFF,0x70,0xE0,0xC0,0x00,0x07,0x03,0x00,0x00,0x08,0x3E,0x63,0x41,0x41,0x60,
0x20,0x60,0xC0,0x00,0x00,0x00,0xF8,0xCC,0x04,0x07,0x03,0x00,0x00,0xF0,0xFF,0x01,
0x00,0x31,0xFF,0x80,0xC0,0x7E,0x03,0x01,0x0F,0x0C,0x0C,0xFC,0x7F,0x63,0xE0,0x3E,
0x03,0x03,0x43,0x66,0x46,0x04,0x0C,0x88,0xF8,0x60,0x01,0x83,0xEE,0x38,0x00,0x00,
0x00,0x00,0x00,0x80,0xC0,0xE0,0x70,0x31,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0x3F,0x7C,0xF0,0xE2,0xC2,0xC4,0x84,0x84,
0x84,0x86,0x06,0x06,0x86,0x87,0x83,0x83,0x81,0xC1,0xC1,0xE0,0x60,0x70,0x30,0x18,
0x0C,0x04,0x06,0x03,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xC0,0x60,0x38,
0x0F,0x01,0x00,0x00,0x01,0x07,0x0E,0x1C,0x38,0x70,0xE0,0x80,0x00,0x00,0x00,0x00,
0x70,0xF0,0x11,0x1F,0x1C,0x00,0x00,0x07,0x1C,0x18,0x08,0x18,0xF0,0x80,0x01,0x07,
0xFC,0x00,0x00,0xFF,0xFF,0x00,0x00,0xE1,0x31,0x21,0x33,0xCF,0x3C,0x27,0x63,0x26,
0x06,0x00,0x60,0x64,0x24,0x64,0xFC,0x1F,0x03,0x01,0x01,0x01,0x00,0x00,0x00,0x00,
0x00,0x00,0x3F,0xFF,0xFF,0x3F,0x00,0x00,0x00,0x00,0x00,0x00,0x78,0xFF,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x03,0x03,
0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x30,0x30,0x18,0x18,0x08,0x0C,0x04,0x06,0x03,0x01,0x01,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x00,0x00,0x00,
0x00,0x01,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x01,0x00,0x00,0x00,
0x01,0x03,0x03,0x01,0x01,0x03,0x03,0x01,0x00,0x00,0x00,0x03,0x03,0x02,0x02,0x02,
0x02,0x02,0x02,0x02,0x02,0x03,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,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 Delay(int num)//延时函数
{
while(num--) ;
}
/*12864driver.c*/
/******************************************************************************/
void Delay12864(unsigned int t)//
{
unsigned int i,j;
for(i=0;i
{
for(j=0;j<10;j++);
}
}
/******************************************************************************/
void write_com(unsigned char cmdcode)//写命令到LCD
{
Di = 0;
RW = 0;
Lcd_Bus = cmdcode;
Delay12864(0);
Enable = 1;
Delay12864(0);
Enable = 0;
}
/******************************************************************************/
void write_data(unsigned char Dispdata)//写数据到LCD
{
Di = 1;
RW = 0;
Lcd_Bus = Dispdata;
Delay12864(0);
Enable = 1;
Delay12864(0);
Enable = 0;
}
/*******************************************************************************/
void frame(void)//显示边框
{
unsigned char i;
Mcs = 1;
Scs = 1;
write_com(Page_Add+0);
write_com(Col_Add+0);
for(i=0;i<64;i++)
{
write_data(0x01);
}
write_com(Page_Add+7);
write_com(Col_Add+0);
for(i=0;i<64;i++)
{
write_data(0x80);
}
for(i=0;i<8;i++)
{
Mcs=0;
Scs=1;
write_com(Page_Add+i);
write_com(Col_Add+63);
write_data(0xff);
Mcs=1;
Scs=0;
write_com(Page_Add+i);
write_com(Col_Add+0);
write_data(0xff);
}
}
/******************************************************************************/
void Clr_Scr(void)//清除内存
{
unsigned char j,k;
Mcs=1;Scs=1;
write_com(Page_Add+0);
write_com(Col_Add+0);
for(k=0;k<8;k++)
{
write_com(Page_Add+k);
for(j=0;j<64;j++)
{
write_data(0x00);
}
}
}
/*******************************************************************************/
void Disp_Img(unsigned char code *img)//显示12864图片
{
unsigned char j,k;
for(k=0;k<8;k++)
{
Mcs=1;
Scs=0;
Delay(10);
write_com(Page_Add+k);
write_com(Col_Add+0);
for(j=0;j<64;j++)
{
write_data(img[k*128+j]);
}
Mcs=0;
Scs=1;
Delay(10);
write_com(Page_Add+k);
write_com(Col_Add+0);
for(j=64;j<128;j++)
{
write_data(img[k*128+j]);
}
}
}
/*******************************************************************************/
void Disp_Chinese(unsigned char pag,unsigned char col, char code *hzk)
{ //指定位置显示汉字16*16
unsigned char j=0,i=0;
for(j=0;j<2;j++)
{
write_com(Page_Add+pag+j);
write_com(Col_Add+col);
for(i=0;i<16;i++)
{
write_data(hzk[16*j+i]);
}
}
}
/*******************************************************************************/
void Disp_Digit(unsigned char pag,unsigned char col, unsigned char code *hzk)
{ //指定位置显示字母或数字8*16
unsigned char j=0, i=0;
for(j=0;j<2;j++)
{
write_com(Page_Add+pag+j);
write_com(Col_Add+col);
for(i=0;i<8;i++)
{
write_data(hzk[8*j+i]);
}
}
}
/********************************************************************************/
void Init_lcd(void)//初始化LCD屏
{
Lcd_Rst=0;
Delay12864(100);
Lcd_Rst=1;
Delay12864(100);
Mcs=1; Scs=1;
Delay12864(100);
write_com(Disp_Off);
write_com(Page_Add+0);
write_com(Start_Line+0);
write_com(Col_Add+0);
write_com(Disp_On);
}
/*******************************************************************************/
void Init_DS18B20(void)//初始化ds1820
{
unsigned char x=0;
DQ = 1; //DQ复位
Delay(8); //稍做延时
DQ = 0; //单片机将DQ拉低
Delay(80); //精确延时 大于 480us
DQ = 1; //拉高总线
Delay(14);
x=DQ; //稍做延时后 如果x=0则初始化成功 x=1则初始化失败
Delay(20);
}
/******************************************************************************/
unsigned char ReadOneChar(void)//读一个字节
{
unsigned char i=0;
unsigned char dat = 0;
for (i=8;i>0;i--)
{
DQ = 0; // 给脉冲信号
dat>>=1;
DQ = 1; // 给脉冲信号
if(DQ)
dat|=0x80;
Delay(4);
}
return(dat);
}
/******************************************************************************/
void WriteOneChar(unsigned char dat)//写一个字节
{
unsigned char i=0;
for (i=8; i>0; i--)
{
DQ = 0;
DQ = dat&0x01;
Delay(5);
DQ = 1;
dat>>=1;
}
}
/******************************************************************************/
unsigned int ReadTemperature(void)//读取温度
{
unsigned char a=0;
unsigned char b=0;
unsigned int t=0;
float tt=0;
Init_DS18B20();
WriteOneChar(0xCC); // 跳过读序号列号的操作
WriteOneChar(0x44); // 启动温度转换
Init_DS18B20();
WriteOneChar(0xCC); //跳过读序号列号的操作
WriteOneChar(0xBE); //读取温度寄存器
a=ReadOneChar(); //读低8位
b=ReadOneChar(); //读高8位
t=b;
t<<=8;
t=t|a;
tt=t*0.0625;
t= tt*10+0.5; //放大10倍输出并四舍五入
return(t);
}
/******************************************************************************/
//1302驱动程序
void clock_out(unsigned char dd)
{
ACC=dd;
clock_dat=a0; clock_clk=1; clock_clk=0;
clock_dat=a1; clock_clk=1; clock_clk=0;
clock_dat=a2; clock_clk=1; clock_clk=0;
clock_dat=a3; clock_clk=1; clock_clk=0;
clock_dat=a4; clock_clk=1; clock_clk=0;
clock_dat=a5; clock_clk=1; clock_clk=0;
clock_dat=a6; clock_clk=1; clock_clk=0;
clock_dat=a7; clock_clk=1; clock_clk=0;
}
/******************************************************************************/
unsigned char clock_in(void)
{
clock_dat=1;
a0=clock_dat;
clock_clk=1; clock_clk=0; a1=clock_dat;
clock_clk=1; clock_clk=0; a2=clock_dat;
clock_clk=1; clock_clk=0; a3=clock_dat;
clock_clk=1; clock_clk=0; a4=clock_dat;
clock_clk=1; clock_clk=0; a5=clock_dat;
clock_clk=1; clock_clk=0; a6=clock_dat;
clock_clk=1; clock_clk=0; a7=clock_dat;
return(ACC);
}
/******************************************************************************/
unsigned char read_clock(unsigned char ord)
{
unsigned char dd=0;
clock_clk=0;
clock_Rst=0;
clock_Rst=1;
clock_out(ord);
dd=clock_in();
clock_Rst=0;
clock_clk=1;
return(dd);
}
/******************************************************************************/
void write_clock(unsigned char ord, unsigned char dd)
{
clock_clk=0;
clock_Rst=0;
clock_Rst=1;
clock_out(ord);
clock_out(dd);
clock_Rst=0;
clock_clk=1;
}
/******************************************************************************/
void Disp(void)//显示和闪烁函数!
{
unsigned int i=0;
unsigned char a=0,b=0,c=0,f=0;
i=ReadTemperature();//读温度并送显
a=i/100;
Mcs=1;Scs=0;
Disp_Digit(5,40,zero+a*16);
b=i/10-a*10;
Mcs=1;Scs=0;
Disp_Digit(5,48,zero+b*16);
c=i-a*100-b*10;
Mcs=0;Scs=1;
Disp_Digit(5,0,zero+c*16);
if(sec==1) //秒闪烁标志位
{
if(flag==1)
{
d=read_clock(0x81);//读秒
e=d;
d=d>>4;
e=e&0x0f;
Mcs=0;Scs=1;
Disp_Digit(3,40,zero+d*16);//送显示
Disp_Digit(3,48,zero+e*16);
}
else
{
Mcs=0;Scs=1;
Disp_Digit(3,40,space); //显示空格
Disp_Digit(3,48,space);
}
}
else
{
d=read_clock(0x81);//读秒
e=d;
d=d>>4;
e=e&0x0f;
Mcs=0;Scs=1;
/********************************************************************************/
if(d == 0 && e == 0)
{
flag_sec = 1;//秒标志位设定
}
/********************************************************************************/
Disp_Digit(3,40,zero+d*16);
Disp_Digit(3,48,zero+e*16);
}
if(min==1) //分钟闪烁标志位
{
if(flag==1)
{
d=read_clock(0x83);//读分钟
e=d;
d=d>>4;
e=e&0x0f;
Mcs=0;Scs=1;
Disp_Digit(3,16,zero+d*16);
Disp_Digit(3,24,zero+e*16);
}
else
{
Mcs=0;Scs=1;
Disp_Digit(3,16,space); //显示空格
Disp_Digit(3,24,space);
}
}
else
{
d=read_clock(0x83);//读分钟
e=d;
d=d>>4;
e=e&0x0f;
Mcs=0;Scs=1;
/******************************************************************************/
if(d == 0 && e == 0)
{
flag_min = 1;//分标志位设定
}
/******************************************************************************/
Disp_Digit(3,16,zero+d*16);
Disp_Digit(3,24,zero+e*16);
}
if(flag_sec == 1 && flag_min == 1)
{
Beep();//整点报警
flag_sec = 0;//清除标志位
flag_min = 0;
}
if(hour==1) //小时闪烁标志位
{
if(flag==1)
{
d=read_clock(0x85);//读小时
e=d;
d=d>>4;
e=e&0x0f;
Mcs=1;Scs=0;
Disp_Digit(3,56,zero+d*16);
Mcs=0;Scs=1;
Disp_Digit(3,0,zero+e*16);
}
else
{
Mcs=1;Scs=0;
Disp_Digit(3,56,space); //显示空格
Mcs=0;Scs=1;
Disp_Digit(3,0,space);
}
}
else
{
d=read_clock(0x85);//读小时
e=d;
d=d>>4;
e=e&0x0f;
Mcs=1;Scs=0;
Disp_Digit(3,56,zero+d*16);
Mcs=0;Scs=1;
Disp_Digit(3,0,zero+e*16);
}
if(year==1) //年闪烁标志位
{
if(flag==1)
{
d=read_clock(0x8d);//读年
e=d;
d=d>>4;
e=e&0x0f;
Mcs=1;Scs=0;
Disp_Digit(1,8,two);
Disp_Digit(1,16,zero);
Disp_Digit(1,24,zero+d*16);
Disp_Digit(1,32,zero+e*16);
}
else
{
Mcs=1;Scs=0;
Disp_Digit(1,24,space); //显示空格
Disp_Digit(1,32,space);
}
}
else
{
d=read_clock(0x8d);//读年
e=d;
d=d>>4;
e=e&0x0f;
Mcs=1;Scs=0;
Disp_Digit(1,8,two);
Disp_Digit(1,16,zero);
Disp_Digit(1,24,zero+d*16);
Disp_Digit(1,32,zero+e*16);
}
if(mon==1) //月闪烁标志位
{
if(flag==1)
{
d=read_clock(0x89);//读月
e=d;
d=d>>4;
e=e&0x0f;
Mcs=1;Scs=0;
Disp_Digit(1,56,zero+d*16);
Mcs=0;Scs=1;
Disp_Digit(1,0,zero+e*16);
Disp_Chinese(1,8,yue);
}
else
{
Mcs=1;Scs=0;
Disp_Digit(1,56,space); //显示空格
Mcs=0;Scs=1;
Disp_Digit(1,0,space);
}
}
else
{
d=read_clock(0x89);//读月
e=d;
d=d>>4;
e=e&0x0f;
Mcs=1;Scs=0;
Disp_Digit(1,56,zero+d*16);
Mcs=0;Scs=1;
Disp_Digit(1,0,zero+e*16);
Disp_Chinese(1,8,yue);
}
if(day==1) //日闪烁标志位
{
if(flag==1)
{
d=read_clock(0x87);//读日
e=d;
d=d>>4;
e=e&0x0f;
Mcs=0;Scs=1;
Disp_Digit(1,24,zero+d*16);
Disp_Digit(1,32,zero+e*16);
Disp_Chinese(1,40,ri);
}
else
{
Mcs=0;Scs=1;
Disp_Digit(1,24,space); //显示空格
Disp_Digit(1,32,space);
}
}
else
{
d=read_clock(0x87);//读日
e=d;
d=d>>4;
e=e&0x0f;
Mcs=0;Scs=1;
Disp_Digit(1,24,zero+d*16);
Disp_Digit(1,32,zero+e*16);
Disp_Chinese(1,40,ri);
}
if(weekk==1) //星期闪烁标志位
{
if(flag==1)
{
d=read_clock(0x8b);//读星期
Mcs=1;Scs=0;
Disp_Chinese(3,40,cone+(d-1)*32);//写入星期的汉字
}
else
{
Mcs=1;Scs=0;
Disp_Chinese(3,40,spaces); //显示空格
}
}
else
{
d=read_clock(0x8b);//读星期
Mcs=1;Scs=0;
Disp_Chinese(3,40,cone+(d-1)*32);//写入星期的汉字
}
}
/******************************************************************************/
void Disp2(void)//显示和闪烁函数
{
if(Kgb==1) //开关闪烁标志位
{
if(flag==1)
{
if(Bell_Swh == 0)//0为关
{
Mcs=0;Scs=1;
Disp_Chinese(2,32,guan);//显示关
}
else
{
Mcs=0;Scs=1;
Disp_Chinese(2,32,kai);//显示开
}
}
else
{
Mcs=0;Scs=1;
Disp_Chinese(2,32,spaces); //显示空格
}
}
else
{
if(Bell_Swh == 0)//关
{
Mcs=0;Scs=1;
Disp_Chinese(2,32,guan);
}
else
{
Mcs=0;Scs=1;
Disp_Chinese(2,32,kai);
}
}
if(Hourb==1) //时闪烁标志位
{
if(flag==1)
{
d=read_clock(0xc3);//读闹钟小时的数值
e=d;
d=d>>4;
e=e&0x0f;
Mcs=1;Scs=0;
Disp_Digit(4,48,zero+d*16);
Disp_Digit(4,56,zero+e*16);
}
else
{
Mcs=1;Scs=0;
Disp_Digit(4,48,space); //显示空格
Disp_Digit(4,56,space);
}
}
else
{
d=read_clock(0xc3);//读闹钟小时的数值
e=d;
d=d>>4;
e=e&0x0f;
Mcs=1;Scs=0;
Disp_Digit(4,48,zero+d*16);
Disp_Digit(4,56,zero+e*16);
}
if(Minb==1) //分钟闪烁标志位
{
if(flag==1)
{
d=read_clock(0xc5);//读闹钟分钟的数值
e=d;
d=d>>4;
e=e&0x0f;
Mcs=0;Scs=1;
Disp_Digit(4,8,zero+d*16);
Disp_Digit(4,16,zero+e*16);
}
else
{
Mcs=0;Scs=1;
Disp_Digit(4,8,space); //显示空格
Disp_Digit(4,16,space);
}
}
else
{
d=read_clock(0xc5);//读闹钟分钟的数值
e=d;
d=d>>4;
e=e&0x0f;
Mcs=0;Scs=1;
Disp_Digit(4,8,zero+d*16);
Disp_Digit(4,16,zero+e*16);
}
if(Secb==1) //秒闪烁标志位
{
if(flag==1)
{
d=read_clock(0xc7);//读闹钟秒的数值
e=d;
d=d>>4;
e=e&0x0f;
Mcs=0;Scs=1;
Disp_Digit(4,32,zero+d*16);
Disp_Digit(4,40,zero+e*16);
}
else
{
Mcs=0;Scs=1;
Disp_Digit(4,32,space); //显示空格
Disp_Digit(4,40,space);
}
}
else
{
d=read_clock(0xc7);//读闹钟秒的数值
e=d;
d=d>>4;
e=e&0x0f;
Mcs=0;Scs=1;
Disp_Digit(4,32,zero+d*16);
Disp_Digit(4,40,zero+e*16);
}
}
/******************************************************************************/
void id_case1_key(void)//id为1时的下一级选择
{
if(Add_Key == 0) //增加
{
Delay(100);
if(Add_Key == 0)
Set_time(id,0); //调用Set_time函数
while(Add_Key ==0);
}
if (Dec_Key==0) //减少
{
Delay(100);
if(Dec_Key == 0)
Set_time(id,1);
while(Dec_Key ==0);
}
}
/******************************************************************************/
void Set_time(unsigned char sel, bit sel_1) //根据选择调整相应项目并写入DS1302
{
signed char address,item;
signed char max,mini;
if(sel==7) {address=0x80; max=0;mini=0;} //秒
if(sel==6) {address=0x82; max=59;mini=0;} //分钟
if(sel==5) {address=0x84; max=23;mini=0;} //小时
if(sel==3) {address=0x86; max=31;mini=1;} //日
if(sel==2) {address=0x88; max=12;mini=1;} //月
if(sel==1) {address=0x8c; max=99; mini=0;} //年
if(sel==4) {address=0x8a; max=7;mini=1;} //星期
//读取1302某地址上的数值转换成10进制赋给item
item=((read_clock(address+1))/16)*10 + (read_clock(address+1))%16;
if(sel_1==0)
item++;
else
item--;
if(item>max) item=mini;
if(item
write_clock(0x8e,0x00);//允许写操作
write_clock(address,(item/10)*16+item%10);//转换成16进制写入1302
write_clock(0x8e,0x80);//写保护,禁止写操作
}
/******************************************************************************/
void id_case2_key(void)//id为1时的下一级选择
{
if(Add_Key == 0) //增加1
{
Delay(100);
if(Add_Key == 0)
Set_Bell(id2,0); //调用Set_Bell函数
while(Add_Key ==0);//等待键松开
}
if(Dec_Key == 0) //减少1
{
Delay(100);
if(Dec_Key == 0)
Set_Bell(id2,1); //调用Set_Bell函数
while(Dec_Key ==0);//等待键松开
}
}
/******************************************************************************/
void Set_Bell(unsigned char sel, bit sel_1)//根据选择调整相应项目并写入
{
signed char address,item;
signed char max,mini;
if(sel==4) {address=0xc6; max=59;mini=0;} //秒
if(sel==3) {address=0xc4; max=59;mini=0;} //分
if(sel==2) {address=0xc2; max=23; mini=0;} //时
if(sel==1) //标志位
{
address=0xc8;//for read
if(Add_Key ==0 || Dec_Key ==0)
Bell_Swh=~Bell_Swh;
write_clock(address,Bell_Swh);
} //开关
item=((read_clock(address+1))/16)*10 + (read_clock(address+1))%16;
if(sel_1==0)
item++;
else
item--;
if(item>max) item=mini;
if(item
write_clock(0x8e,0x00);//允许写操作
write_clock(address,(item/10)*16+item%10);//转换成16进制写入1302
write_clock(0x8e,0x80);//写保护,禁止写操作
}
/******************************************************************************/
void Timer0_Init(void)//定时器0初始化
{
TMOD=0x01;
TH0=(65535-50000)/256;
TL0=(65535-50000)%256;
EA=1;
ET0=1;
TR0=1;
}
/******************************************************************************/
void Timer0(void) interrupt 1 using 1//中断入口,冒号闪烁
{
static unsigned char timecount = 0;
TH0=(65535-50000)/256; //50ms定时
TL0=(65535-50000)%256;
timecount++;
if(timecount > 9)//500MS
{
timecount = 0;
flag = ~flag;
}
}
/******************************************************************************/
void Init_1302(void)//设置1302的初始时间
{
write_clock(0x8e,0x00);//允许写操作
write_clock(0x8c,0x05);//年
write_clock(0x8a,0x06);//星期
write_clock(0x88,0x01);//月
write_clock(0x86,0x01);//日
write_clock(0x84,0x12);//小时
write_clock(0x82,0x00);//分钟
write_clock(0x80,0x00);//秒
write_clock(0x90,0xa5);//充电
write_clock(0x8e,0x80);//禁止写操作
}
/******************************************************************************/
void Lcd_Mark1(void)//在预定的位置上写入汉字
{
Clr_Scr();//清屏
frame();//显示边框
Mcs=1;Scs=0;
Disp_Chinese(5,8,shi);//显示室温,星期,年, . ,℃
Disp_Chinese(5,24,wen);
Disp_Chinese(3,8,xing);
Disp_Chinese(3,24,qi);
Disp_Chinese(1,40,nian);
Disp_Digit(5,56,point);
Mcs=0;Scs=1;
Disp_Chinese(5,8,sheshidu);
if(Bell_Swh == 1)//闹钟为开
{
Mcs=0;Scs=1;
Disp_Chinese(5,40,biaozhi);//显示闹钟图标
}
}
/******************************************************************************/
void Lcd_Mark2(void)
{
Clr_Scr();//清屏
frame();//显示边框
Mcs=1;Scs=0;//显示闹钟设定等几个汉字
Disp_Chinese(2,16,nao);
Disp_Chinese(2,32,zhong);
Disp_Chinese(2,48,she);
Mcs=0;Scs=1;
Disp_Chinese(2,0,ding);
Disp_Digit(4,0,maohao);//显示:
Disp_Digit(4,24,maohao);
}
/******************************************************************************/
void Beep(void)//BELL 蜂明器发声,整点报警
{
Bell_Out = 0;
Delay(6000);//50ms
Bell_Out = 1;
Delay(6000);//50ms
}
/*****************************************************************************/
void Bell_now(void)
{
Bell_Out = 0;
Delay(31250); //for 250ms
Bell_Out = 1;
Delay(6350); //50ms
Bell_Out = 0;
Delay(18750);//150ms
Bell_Out = 1;
Delay(50000);//400ms
}
/******************************************************************************/
void main(void) //主函数
{
//初始化状态
Bell_Out = 1;//蜂明器关闭
Bak_Light = 0;//开机背光开
Timer0_Init();
Init_lcd();//设置液晶显示器
Clr_Scr();//清屏
Disp_Img(logo); //显示湘灵电子LOGO开机画面
Delay12864(60000);//Delay 4s
Bak_Light = 1;//关闭背光
Bell_Swh = read_clock(0xc9);//读取开,关的状态
Lcd_Mark1();
while(1)//主循环
{
//设置时钟的初始值,显示05年1月1号星期六12:00:00
if(Rst_Key == 0)//按下系统复位键,S4
{
Delay(1000);//延时消抖
if(Rst_Key == 0)
{
Init_1302();//初始化时钟
}
}
if(OK_Key == 0 && Dec_Key ==0 )//进入闹钟设置界面
{
Delay12864(100);
if(OK_Key == 0 && Dec_Key ==0 )
{
Lcd_Mark2();
if(Bell_Swh == 0){Mcs=0;Scs=1;Disp_Chinese(2,32,guan);}//关
else {Mcs=0;Scs=1;Disp_Chinese(2,32,kai);}
while(1)
{
if (OK_Key == 0) // 设置和选择项目键
{
Delay(1000);
if(OK_Key == 0)
{
id2++;if(id2>5) id2=0;
}
while(OK_Key == 0);//等待键松开
}
switch( id2 )
{
case 0:Disp2();break;//正常显示
case 1:Kgb = 1;id_case2_key();Disp2();break;//开关
case 2:Kgb= 0;Hourb=1;id_case2_key();Disp2();break;//
case 3:Hourb=0;Minb=1;id_case2_key();Disp2();break;
case 4:Minb=0;Secb=1;id_case2_key();Disp2();break;
case 5:Secb=0;id2 = 0;Lcd_Mark1();goto FF;break;//返回主界面
default:break;
}
}//while(1)
}//if
}//if
/*****************************************/
FF: //返回主界面
/*****************************************/
if(flag == 0)
{
Mcs=0;Scs=1;
Disp_Digit(3,8,maohao);// :闪烁
Disp_Digit(3,32,maohao);
}
else
{
Mcs=0;Scs=1;
Disp_Digit(3,8,space);//显示空格
Disp_Digit(3,32,space);
}
if (OK_Key == 0) // 设置和选择项目键
{
Delay(1000);
if(OK_Key == 0)
{
id++;if(id>7)id=0;
}
while(OK_Key == 0);//等待键松开
}
switch( id )
{
case 0:sec = 0; Disp( );break;//正常显示
case 1:year = 1;id_case1_key();Disp();break;//年
case 2:year=0;mon=1;id_case1_key();Disp();break;//月
case 3:mon=0;day=1;id_case1_key();Disp();break; //日
case 4:day=0;weekk=1;id_case1_key();Disp();break;//星期
case 5:weekk=0;hour=1;id_case1_key();Disp();break; //小时
case 6:hour=0;min=1;id_case1_key();Disp();break; //分钟
case 7:min=0;sec=1;id_case1_key();Disp();break; //秒
default:break;
}
if(Bell_Swh == 1)//闹钟为开
{
H_Bell=read_clock(0xc3);//读取闹钟的时
S_Bell=read_clock(0xc5);//读取闹钟的分
H_1302=read_clock(0x85);//读小时
S_1302=read_clock(0x83);//读分钟
if(H_Bell == H_1302)
{
if(S_Bell == S_1302)
{
Clr_Scr();//清屏
frame();//显示边框
Mcs=1;Scs=0;
Disp_Chinese(3,16,nao);//闹钟显示时间到!
Disp_Chinese(3,32,zhong);
Disp_Chinese(3,48,shit);
Mcs=0;Scs=1;
Disp_Chinese(3,0,jian);
Disp_Chinese(3,16,dao);
Disp_Digit(3,40,fh);
while(S_Bell == S_1302)//判断是否到闹钟设定时间
{
Bak_Light = 0;//闹钟时间到,打开LCD背光
Bell_now();//闹钟响
S_1302=read_clock(0x83);//读分钟
if(OK_Key == 0 || Dec_Key ==0 || Add_Key == 0)
{
Bak_Light = 1;//关闭背光
Bell_Swh = 0;//关闭闹钟
break; //终止闹钟按任意键退出!
}
}
Lcd_Mark1();//返回万年历时钟界面
}//if(S_Bell == S_1302)
}//if(H_Bell == H_1302)
}//if闹钟开
}//while
}//main
|