c51实现万年历、温度与闹钟功能程序

发布者:SereneDreams最新更新时间:2016-09-07 来源: eefocus关键字:c51  万年历  温度与闹钟 手机看文章 扫描二维码
随时随地手机看文章
#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(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) //增加
    {
     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

关键字:c51  万年历  温度与闹钟 引用地址:c51实现万年历、温度与闹钟功能程序

上一篇:单片机控制的步进电机PWM控制程序
下一篇:keil c51如何实现2进制操作

推荐阅读最新更新时间:2024-03-16 15:08

C51单片机中断定义
C51函数声明对ANSI C作了扩展,具体包括: 1. 中断函数声明: 中断声明方法如下: void serial_ISR () interrupt 4 { /* ISR */ } 为提高代码的容错能力,在没用到的中断入口处生成iret语句,定义没用到的中断。 /* define not used interrupt, so generate IRET in their entrance */ void extern0_ISR() interrupt 0{} /* not used */ void timer0_ISR () interrupt 1{} /* not used */ void extern1_ISR()
[单片机]
基于51单片机+DS1302万年历+LCD1602显示+按键播报时间+温控风扇+按键控灯
前段时间做了一个 基于51单片机的万年历加温度控制风扇以及按键播报时间。在这里做一下笔记。 准备硬件 1:51单片机(我这里用的是STC89C52) 2:语音播报模块(我这里用的是SYN6288) 3:DS1302时钟模块 4:DS18B20温度模块 5:LCD1602显示屏 6:L298N电机驱动 7:蜂鸣器 8:电机 9:按键 5个 10:灯 功能介绍 功能: 1:修改时间 2:修改日期(软件自动校正日期) 3:闹钟模式 4:温度控制风扇速度 5:调节灯亮度 6:播报时间 主界面设置 下面是大概的流程图 位置不够没画全。。。 由于代码较多,这里就不全部贴出来了。 修改时间 当我们进入到修改时间的界面,我们屏幕得
[单片机]
基于51单片机+DS1302<font color='red'>万年历</font>+LCD1602显示+按键播报时间+温控风扇+按键控灯
Keil C51使用教程---C51 vs 标准C(三)
深入理解并应用C51对标准ANSIC的扩展是学习C51的关键之一。因为大多数扩展功能都是直接针对8051系列CPU硬件的。大致有以下8类: ●8051存储类型及存储区域 ●存储模式 ●存储器类型声明 ●变量类型声明 ●位变量与位寻址 ●特殊功能寄存器(SFR) ●C51指针 ●函数属性 具体说明如下(8031为缺省CPU)。 第一节 Keil C51扩展关键字 C51 V4.0版本有以下扩展关键字(共19个): _at_ idata sfr16 alien interrupt small bdata large _task_
[单片机]
课程设计:矩阵键盘(c51,使用扫描法实现)
//可以比较一下和以前发表的一篇用反转法实现的不同(感觉一下那个更简单) //这种方法是用只用P3口的前高四位来比较,看改变了么(由于比较仓促,没有proteus仿真,不过这是个比较经典的方法,网上有很多这个代码,源自郭天祥的视频和书籍) #include reg52.h #define uchar unsigned char #define uint unsigned int sbit wela=P2^7; sbit dula=P2^6; uchar num,num1; unsigned char code table ={0x3f,0x06,0x5b,0x4f,0x66,0x6d, 0x7d,0x07,0
[单片机]
关于在 KEIL C51 中嵌入汇编以及C51A51间的相互调用
如何在 KEIL C51(v6.21) 中调用汇编函数的一个示例 有关c51调用汇编的方法已经有很多帖子讲到,但是一般只讲要点,很少有对整个过程作详细描述,对于初学者是不够的,这里笔者 通过一个简单例子对这个过程进行描述,希望能对初学者有所帮助。几年来,在这个论坛里笔者得到很多热心人指导,因此也希望 藉此尽一点绵薄之力。 在这个例子里,阐述了编写c51程序调用汇编函数的一种方法,这个外部函数的入口参数是一个字符型变量和一个位变量,返回值是 一个整型变量。例中,先用c51写出这个函数的主体,然后用SRC控制指令编译产生asm文件,进一步修改这个asm文件就得到我们所 要的汇编函数。该方法让编译器自动完成各种段的安排,提高了汇编程序
[单片机]
51单片机的4x4矩阵键盘扫描例程(C51)
//4x4矩阵键盘扫描例程(C51) //使用P0口上的LED灯显示4x4键盘扫描得到的键值 // //广西民大物电学院 李映超 2010.4.19 #include reg52.h //52系列单片机头文件 #define uchar unsigned char #define uint unsigned int #define key_4x4_port P3 //定义4x4键盘使用的单片机端口 uchar key; //4x4键盘扫描所得的键值保存到这里 void delayms(uint xms); //声明延时子函数 void key_4x4_s
[单片机]
Keil C51使用教程---开发系统基本知识(一)
Keil C51使用教程---开发系统基本知识(一) 第一节 系统概述 Keil C51是美国Keil Software公司出品的51系列兼容单片机C语言软件开发系统,与汇编相比,C语言在功能上、结构性、可读性、可维护性上有明显的优势,因而易学易用。用过汇编语言后再使用C来开发,体会更加深刻。 Keil C51软件提供丰富的库函数和功能强大的集成开发调试工具,全Windows界面。另外重要的一点,只要看一下编译后生成的汇编代码,就能体会到Keil C51生成的目标代码效率非常之高,多数语句生成的汇编代码很紧凑,容易理解。在开发大型软件时更能体现高级语言的优势。 下面详细介绍Keil C51开发系统各部分功能
[单片机]
Keil <font color='red'>C51</font>使用教程---开发系统基本知识(一)
c51中定时器工作时如何使用T0脚输入脉冲信号?
嵌入式系统中,定时器是一种常用的设备,可以实现各种时间控制功能,如计时、计数、产生中断等。8051单片机中有两个定时器:T0和T1,其中T0定时器主要用于计时和计数操作,可以通过T0脚输入脉冲信号来控制定时器的工作。 T0脚是单片机的P3.4口,既可以作为普通的输入输出口,也可以作为T0定时器的外部输入引脚。当T0脚作为定时器的外部输入引脚时,可以通过输入的脉冲信号来控制定时器的计数。在使用T0脚输入脉冲信号时,需要采取一些措施来确保信号的稳定性和正确性。 首先,需要确定输入脉冲信号的频率。在使用T0脚输入脉冲信号时,需要将信号的频率与定时器的工作频率相匹配。具体来说,当定时器使用外部时钟源时,其工作频率为外部时钟源频率的一半,因
[单片机]
小广播
添点儿料...
无论热点新闻、行业分析、技术干货……
设计资源 培训 开发板 精华推荐

最新单片机文章
何立民专栏 单片机及嵌入式宝典

北京航空航天大学教授,20余年来致力于单片机与嵌入式系统推广工作。

换一换 更多 相关热搜器件
电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号 Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved