您的位置 首页 应用

c51完成万年历、温度与闹钟功用程序

#includereg51.h>sbitBell_Out=P1^7;//闹钟管脚输出sbitDQ=P2^1;//ds1820datasbitclock_clk=P1^0;//ds13…

#include

sbit Bell_Out = P1 ^ 7;//闹钟管脚输出

sbit DQ = P2 ^ 1;//ds1820data
sbit clock_clk = P1 ^ 0;//ds1302_clk
sbit clock_dat = P1 ^ 1;//ds1302_dat
sbit clock_Rst = P1 ^ 2;//ds1302_Rst

#define Disp_On 0x3f //界说管脚的指令值
#define Disp_Off 0x3e
#define Col_Add 0x40
#define Page_Add 0xb8
#define Start_Line 0xc0
#define Lcd_Bus P0 //界说数据口

sbit Mcs = P3 ^ 5; //
sbit Scs = P3 ^ 6; //
sbit Enable = P1 ^ 5; //
sbit Di = P1 ^ 4; //
sbit RW = P1 ^ 3; //
sbit Lcd_Rst= P3 ^ 7; //

//键盘扫描
sbit Add_Key = P2 ^ 1;//加1键
sbit Dec_Key = P2 ^ 2;//减1键
sbit OK_Key = P2^ 3;//确认键

//24存储器
sbit SCL = P3 ^ 3;
sbit SDA = P3 ^ 4;
sbit WP = P3 ^ 2;

#define TRUE 1
#define FALSE 0
#define Delay2408_TIME 60 //经试验,不要小于50!不然或许形成时序紊乱

//为了编程便利界说的位变量
sbit a0 = ACC ^ 0;
sbit a1 = ACC ^ 1;
sbit a2 = ACC ^ 2;
sbit a3 = ACC ^ 3;
sbit a4 = ACC ^ 4;
sbit a5 = ACC ^ 5;
sbit a6 = ACC ^ 6;
sbit 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; //闪耀标志位
unsigned char id,id2,d,e,S_1302,H_1302,H_2402,S_2402; //

//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);

//24系列
void Delay2408(unsigned int t);
void I2C_Start(void);
void I2C_Stop(void);
void SEND_0(void);
void SEND_1(void);
bit Check_Acknowledge(void);
void WriteI2CByte(unsigned char b)reentrant;
unsigned char ReadI2CByte(void)reentrant;
void Write_One_Byte(unsigned char addr,unsigned char thedata);
char Read_One_Byte(unsigned char addr);

//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
};

/******************************************************************************/
/* 24C08.c*/
//调用方法如下:
//Write_One_Byte(0x10,0x04);
//k=Read_One_Byte(0x10);
/********** 函数界说 ************/
void Delay2408(unsigned int t) /*延时函数*/
{
while(t!=0)
t–;
}

void I2C_Start(void)
{
/*发动I2C总线的函数,当SCL为高电平时使SDA发生一个负跳变*/
SDA=1;
SCL=1;
Delay2408(Delay2408_TIME);
SDA=0;
Delay2408(Delay2408_TIME);
SCL=0;
Delay2408(Delay2408_TIME);
}

void I2C_Stop(void)
{
/*停止I2C总线,当SCL为高电平时使SDA发生一个正跳变*/
SDA=0;
SCL=1;
Delay2408(Delay2408_TIME);
SDA=1;
Delay2408(Delay2408_TIME);
SCL=0;
Delay2408(Delay2408_TIME);
}

void SEND_0(void) /* SEND ACK */
{
/*发送0,在SCL为高电平时使SDA信号为低*/
SDA=0;
SCL=1;
Delay2408(Delay2408_TIME);
SCL=0;
Delay2408(Delay2408_TIME);
}

void SEND_1(void)
{
/*发送1,在SCL为高电平时使SDA信号为高*/
SDA=1;
SCL=1;
Delay2408(Delay2408_TIME);
SCL=0;
Delay2408(Delay2408_TIME);
}

bit Check_Acknowledge(void)
{
/*发送完一个字节后查验设备的应对信号*/
SDA=1;
SCL=1;
Delay2408(Delay2408_TIME/2);
F0=SDA;
Delay2408(Delay2408_TIME/2);
SCL=0;
Delay2408(Delay2408_TIME);
if(F0==1)
return FALSE;
return TRUE;
}

void WriteI2CByte(unsigned char b)reentrant
{
/*向I2C总线写一个字节*/
unsigned char i;
for(i=0;i<8;i++)
if((b< SEND_1();
else
SEND_0();
}

unsigned char ReadI2CByte(void)reentrant
{
/*从I2C总线读一个字节*/
unsigned char b=0,i;
for(i=0;i<8;i++)
{
SDA=1; /*开释总线*/
SCL=1; /*承受数据*/
Delay2408(10);
F0=SDA;
Delay2408(10);
SCL=0;
if(F0==1)
{
b=b<<1;
b=b|0x01;
}
else
b=b<<1;
}
return b;
}

/**********以下为读写24c02的函数***********************************************/
void Write_One_Byte(unsigned char addr,unsigned char thedata)
{
bit acktemp=1;
/*write a byte to mem*/
I2C_Start();
WriteI2CByte(0xa0);
acktemp=Check_Acknowledge();
WriteI2CByte(addr); /*address*/
acktemp=Check_Acknowledge();
WriteI2CByte(thedata); /*thedata*/
acktemp=Check_Acknowledge();
I2C_Stop();
}

/******************************************************************************/
char Read_One_Byte(unsigned char addr)
{
bit acktemp=1;
unsigned char mydata;
/*read a byte from mem*/
I2C_Start();
WriteI2CByte(0xa0);
acktemp=Check_Acknowledge();
WriteI2CByte(addr);/*address*/
acktemp=Check_Acknowledge();
I2C_Start();
WriteI2CByte(0xa1);
acktemp=Check_Acknowledge();
mydata=ReadI2CByte();
acktemp=Check_Acknowledge();
return mydata;
I2C_Stop();
}

/******************************************************************************/
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;
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;
Disp_Digit(3,16,zero+d*16);
Disp_Digit(3,24,zero+e*16);
}

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_One_Byte(0x01);//读取2408的小时的数值
Mcs=1;Scs=0;
Disp_Digit(4,48,zero+(d/10)*16);
Disp_Digit(4,56,zero+(d%10)*16);
}
else
{
Mcs=1;Scs=0;
Disp_Digit(4,48,space); //显现空格
Disp_Digit(4,56,space);
}
}
else
{
d = Read_One_Byte(0x01);//读取24的小时的数值
Mcs=1;Scs=0;
Disp_Digit(4,48,zero+(d/10)*16);
Disp_Digit(4,56,zero+(d%10)*16);
}

if(Minb==1) //分钟闪耀标志位
{
if(flag==1)
{
d = Read_One_Byte(0x02);//读取24的分的数值
Mcs=0;Scs=1;
Disp_Digit(4,8,zero+(d/10)*16);
Disp_Digit(4,16,zero+(d%10)*16);
}
else
{
Mcs=0;Scs=1;
Disp_Digit(4,8,space); //显现空格
Disp_Digit(4,16,space);
}
}
else
{
d = Read_One_Byte(0x02);//读取24的分的数值
Mcs=0;Scs=1;
Disp_Digit(4,8,zero+(d/10)*16);
Disp_Digit(4,16,zero+(d%10)*16);
}

if(Secb==1) //秒闪耀标志位
{
if(flag==1)
{
d = Read_One_Byte(0x03);//读取24的秒的数值
Mcs=0;Scs=1;
Disp_Digit(4,32,zero+(d/10)*16);
Disp_Digit(4,40,zero+(d%10)*16);
}
else
{
Mcs=0;Scs=1;
Disp_Digit(4,32,space); //显现空格
Disp_Digit(4,40,space);
}
}
else
{
d = Read_One_Byte(0x03);//读取24的秒的数值
Mcs=0;Scs=1;
Disp_Digit(4,32,zero+(d/10)*16);
Disp_Digit(4,40,zero+(d%10)*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(address,(item/10)*16+item%10);//转化成16进制写入1302
write_clock(0x8e,0x80);//写保护,制止写操作
}

/******************************************************************************/
void id_case2_key(void)//id为1时的下一级挑选
{
if(Add_Key == 0) //添加
{
Delay(100);
if(Add_Key == 0)
Set_Bell(id2,0); //调用Set_time函数
while(Add_Key ==0);
}
if (Dec_Key==0) //削减
{
Delay(100);
if(Dec_Key == 0)
Set_Bell(id2,1);
while(Dec_Key ==0);
}
}

/******************************************************************************/
void Set_Bell(unsigned char sel, bit sel_1)//依据挑选调整相应项目并写入24
{
signed char address,item;
signed char max,mini;
if(sel==4) {address=0x03; max=59;mini=0;} //秒
if(sel==3) {address=0x02; max=59;mini=0;} //分
if(sel==2) {address=0x01; max=23; mini=0;} //时
if(sel==1)
{
address=0x04;
if(Add_Key ==0 || Dec_Key ==0)
Bell_Swh=~Bell_Swh;
Write_One_Byte(address,Bell_Swh);
} //开关

item = Read_One_Byte(address);
if(sel_1==0)
item++;
else
item–;
if(item>max) item=mini;
if(item

Write_One_Byte(address,item);//写入24
}

/******************************************************************************/
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 main(void)
{
unsigned char a;

Timer0_Init();
Init_lcd();//设置液晶显现器
WP = 0;//答应2408的写操作!

Clr_Scr();//清屏
Disp_Img(logo); //显现湘灵电子LOGO
Delay12864(10000);//Delay

Bell_Swh = Read_One_Byte(0x04);//读取开关的状况
Lcd_Mark1();

while(1)//主循环
{
//设置时钟的初始值,显现05年1月1号12:00:00
if(Add_Key == 0 && Dec_Key == 0)
{
Delay(1000);
if(Add_Key == 0 && Dec_Key == 0)
{
Init_1302();
}
}

/* if(Add_Key == 0)
{ Delay(1000);
if(Add_Key ==0)
{
//写入闹钟初始值08:00:00
Write_One_Byte(0x01,18);
Write_One_Byte(0x02,0);
Write_One_Byte(0x03,0);
}
}*/

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_2402=Read_One_Byte(0x01);//读取2408的
S_2402=Read_One_Byte(0x02);

d=read_clock(0x85);//读小时
e=d;
d=d>>4;
e=e&0x0f;
H_1302=10*d+e;

d=read_clock(0x83);//读分钟
e=d;
d=d>>4;
e=e&0x0f;
S_1302=10*d+e;

if(H_2402 == H_1302)
{
if(S_2402 == 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_2402 == S_1302)//判别是否到闹钟设守时刻
{
for(a=0; a<100; a++)//BELL脉冲输出,驱动蜂鸣器
{
if(a<50){Bell_Out = 0;Delay(100);}
else {Bell_Out = 1;Delay(100);}
}

d=read_clock(0x83);//读分钟
e=d;
d=d>>4;
e=e&0x0f;
S_1302=10*d+e;
}
Lcd_Mark1();
}//if
}
}//if
}//while
}//main

声明:本文内容来自网络转载或用户投稿,文章版权归原作者和原出处所有。文中观点,不代表本站立场。若有侵权请联系本站删除(kf@86ic.com)https://www.86ic.net/yingyong/267108.html

为您推荐

联系我们

联系我们

在线咨询: QQ交谈

邮箱: kf@86ic.com

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

返回顶部