新聞中心

EEPW首頁(yè) > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > c51實(shí)現(xiàn)萬年歷、溫度與鬧鐘功能程序

c51實(shí)現(xiàn)萬年歷、溫度與鬧鐘功能程序

作者: 時(shí)間:2016-11-18 來源:網(wǎng)絡(luò) 收藏
#include

sbit Bell_Out = P1 ^ 7;//鬧鐘管腳輸出

本文引用地址:http://butianyuan.cn/article/201611/315989.htm

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 //定義數(shù)據(jù)口

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存儲(chǔ)器
sbit SCL = P3 ^ 3;
sbit SDA = P3 ^ 4;
sbit WP = P3 ^ 2;

#define TRUE 1
#define FALSE 0
#define Delay2408_TIME 60 //經(jīng)實(shí)驗(yàn),不要小于50!否則可能造成時(shí)序混亂

//為了編程方便定義的位變量
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;//閃爍標(biāo)志位
bit sec=0,min=0,hour=0,year=0,mon=0,day=0,weekk=0; //閃爍標(biāo)志位
unsigned char id,id2,d,e,S_1302,H_1302,H_2402,S_2402; //

//Function Definition 函數(shù)聲明
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);


//漢字庫(kù)及數(shù)字符號(hào)庫(kù)
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};/*-- 文字: 設(shè) --*/

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};/*-- 文字: 關(guān) --*/

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};/*-- 文字: 時(shí) --*/
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};//小數(shù)點(diǎn)
unsigned char code maohao[16]={0x00,0x00,0x00,0xC0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00};//冒號(hào)
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};//!感嘆號(hào)

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};//攝氏度的符號(hào)
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};//鬧鐘的圖標(biāo)
unsigned char code logo[]={ //開機(jī)畫面-----湘靈電子工作室
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*/
//調(diào)用方式如下:
//Write_One_Byte(0x10,0x04);
//k=Read_One_Byte(0x10);
/********** 函數(shù)定義 ************/
void Delay2408(unsigned int t) /*延時(shí)函數(shù)*/
{
while(t!=0)
t--;
}

void I2C_Start(void)
{
/*啟動(dòng)I2C總線的函數(shù),當(dāng)SCL為高電平時(shí)使SDA產(chǎn)生一個(gè)負(fù)跳變*/
SDA=1;
SCL=1;
Delay2408(Delay2408_TIME);
SDA=0;
Delay2408(Delay2408_TIME);
SCL=0;
Delay2408(Delay2408_TIME);
}

void I2C_Stop(void)
{
/*終止I2C總線,當(dāng)SCL為高電平時(shí)使SDA產(chǎn)生一個(gè)正跳變*/
SDA=0;
SCL=1;
Delay2408(Delay2408_TIME);
SDA=1;
Delay2408(Delay2408_TIME);
SCL=0;
Delay2408(Delay2408_TIME);
}

void SEND_0(void) /* SEND ACK */
{
/*發(fā)送0,在SCL為高電平時(shí)使SDA信號(hào)為低*/
SDA=0;
SCL=1;
Delay2408(Delay2408_TIME);
SCL=0;
Delay2408(Delay2408_TIME);
}

void SEND_1(void)
{
/*發(fā)送1,在SCL為高電平時(shí)使SDA信號(hào)為高*/
SDA=1;
SCL=1;
Delay2408(Delay2408_TIME);
SCL=0;
Delay2408(Delay2408_TIME);
}

bit Check_Acknowledge(void)
{
/*發(fā)送完一個(gè)字節(jié)后檢驗(yàn)設(shè)備的應(yīng)答信號(hào)*/
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總線寫一個(gè)字節(jié)*/
unsigned char i;
for(i=0;i<8;i++)
if((b< SEND_1();
else
SEND_0();
}

unsigned char ReadI2CByte(void)reentrant
{
/*從I2C總線讀一個(gè)字節(jié)*/
unsigned char b=0,i;
for(i=0;i<8;i++)
{
SDA=1; /*釋放總線*/
SCL=1; /*接受數(shù)據(jù)*/
Delay2408(10);
F0=SDA;
Delay2408(10);
SCL=0;
if(F0==1)
{
b=b<<1;
b=b|0x01;
}
else
b=b<<1;
}
return b;
}

/**********以下為讀寫24c02的函數(shù)***********************************************/
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)//延時(shí)函數(shù)
{
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)//寫數(shù)據(jù)到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)//清除內(nèi)存
{
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)
{ //指定位置顯示字母或數(shù)字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復(fù)位
Delay(8); //稍做延時(shí)
DQ = 0; //單片機(jī)將DQ拉低
Delay(80); //精確延時(shí) 大于 480us
DQ = 1; //拉高總線
Delay(14);
x=DQ; //稍做延時(shí)后 如果x=0則初始化成功 x=1則初始化失敗
Delay(20);
}

/******************************************************************************/
unsigned char ReadOneChar(void)//讀一個(gè)字節(jié)
{
unsigned char i=0;
unsigned char dat = 0;
for (i=8;i>0;i--)
{
DQ = 0; // 給脈沖信號(hào)
dat>>=1;
DQ = 1; // 給脈沖信號(hào)
if(DQ)
dat|=0x80;
Delay(4);
}
return(dat);
}

/******************************************************************************/
void WriteOneChar(unsigned char dat)//寫一個(gè)字節(jié)
{
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); // 跳過讀序號(hào)列號(hào)的操作
WriteOneChar(0x44); // 啟動(dòng)溫度轉(zhuǎn)換
Init_DS18B20();
WriteOneChar(0xCC); //跳過讀序號(hào)列號(hào)的操作
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驅(qū)動(dòng)程序
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)//顯示和閃爍函數(shù)
{
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) //秒閃爍標(biāo)志位
{
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) //分鐘閃爍標(biāo)志位
{
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) //小時(shí)閃爍標(biāo)志位
{
if(flag==1)
{
d=read_clock(0x85);//讀小時(shí)
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);//讀小時(shí)
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) //年閃爍標(biāo)志位
{
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) //月閃爍標(biāo)志位
{
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) //日閃爍標(biāo)志位
{
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) //星期閃爍標(biāo)志位
{
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)//顯示和閃爍函數(shù)
{
if(Kgb==1) //開關(guān)閃爍標(biāo)志位
{
if(flag==1)
{
if(Bell_Swh == 0)//0為關(guān)
{
Mcs=0;Scs=1;
Disp_Chinese(2,32,guan);//顯示關(guān)
}
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)//關(guān)
{
Mcs=0;Scs=1;
Disp_Chinese(2,32,guan);
}
else
{
Mcs=0;Scs=1;
Disp_Chinese(2,32,kai);
}
}

if(Hourb==1) //時(shí)閃爍標(biāo)志位
{
if(flag==1)
{
d = Read_One_Byte(0x01);//讀取2408的小時(shí)的數(shù)值
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的小時(shí)的數(shù)值
Mcs=1;Scs=0;
Disp_Digit(4,48,zero+(d/10)*16);
Disp_Digit(4,56,zero+(d%10)*16);
}

if(Minb==1) //分鐘閃爍標(biāo)志位
{
if(flag==1)
{
d = Read_One_Byte(0x02);//讀取24的分的數(shù)值
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的分的數(shù)值
Mcs=0;Scs=1;
Disp_Digit(4,8,zero+(d/10)*16);
Disp_Digit(4,16,zero+(d%10)*16);
}

if(Secb==1) //秒閃爍標(biāo)志位
{
if(flag==1)
{
d = Read_One_Byte(0x03);//讀取24的秒的數(shù)值
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的秒的數(shù)值
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時(shí)的下一級(jí)選擇
{
if(Add_Key == 0) //增加
{
Delay(100);
if(Add_Key == 0)
Set_time(id,0); //調(diào)用Set_time函數(shù)
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) //根據(jù)選擇調(diào)整相應(yīng)項(xiàng)目并寫入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;} //小時(shí)
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某地址上的數(shù)值轉(zhuǎn)換成10進(jìn)制賦給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);//轉(zhuǎn)換成16進(jìn)制寫入1302
write_clock(0x8e,0x80);//寫保護(hù),禁止寫操作
}

/******************************************************************************/
void id_case2_key(void)//id為1時(shí)的下一級(jí)選擇
{
if(Add_Key == 0) //增加
{
Delay(100);
if(Add_Key == 0)
Set_Bell(id2,0); //調(diào)用Set_time函數(shù)
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)//根據(jù)選擇調(diào)整相應(yīng)項(xiàng)目并寫入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;} //時(shí)
if(sel==1)
{
address=0x04;
if(Add_Key ==0 || Dec_Key ==0)
Bell_Swh=~Bell_Swh;
Write_One_Byte(address,Bell_Swh);
} //開關(guān)

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)//定時(shí)器0初始化
{
TMOD=0x01;
TH0=(65535-50000)/256;
TL0=(65535-50000)%256;
EA=1;
ET0=1;
TR0=1;
}

/******************************************************************************/
void Timer0(void) interrupt 1 using 1//中斷入口,冒號(hào)閃爍
{
static unsigned char timecount = 0;//

TH0=(65535-50000)/256; //50ms定時(shí)
TL0=(65535-50000)%256;
timecount++;
if(timecount > 9)//500MS
{
timecount = 0;
flag = ~flag;
}
}

/******************************************************************************/
void Init_1302(void)//設(shè)置1302的初始時(shí)間
{
write_clock(0x8e,0x00);//允許寫操作
write_clock(0x8c,0x05);//年
write_clock(0x8a,0x06);//星期
write_clock(0x88,0x01);//月
write_clock(0x86,0x01);//日
write_clock(0x84,0x12);//小時(shí)
write_clock(0x82,0x00);//分鐘
write_clock(0x80,0x00);//秒
write_clock(0x90,0xa5);//充電
write_clock(0x8e,0x80);//禁止寫操作
}

/******************************************************************************/
void Lcd_Mark1(void)//在預(yù)定的位置上寫入漢字)
{
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);//顯示鬧鐘圖標(biāo)
}

}

/******************************************************************************/
void Lcd_Mark2(void)
{
Clr_Scr();//清屏
frame();//顯示邊框

Mcs=1;Scs=0;//顯示鬧鐘設(shè)定等幾個(gè)漢字
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();//設(shè)置液晶顯示器
WP = 0;//允許2408的寫操作!

Clr_Scr();//清屏
Disp_Img(logo); //顯示湘靈電子LOGO
Delay12864(10000);//Delay

Bell_Swh = Read_One_Byte(0x04);//讀取開關(guān)的狀態(tài)
Lcd_Mark1();

while(1)//主循環(huán)
{
//設(shè)置時(shí)鐘的初始值,顯示05年1月1號(hào)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 )//進(jìn)入鬧鐘設(shè)置界面
{
Delay12864(100);
if(OK_Key == 0 && Dec_Key ==0 )
{
Lcd_Mark2();
if(Bell_Swh == 0){Mcs=0;Scs=1;Disp_Chinese(2,32,guan);}//關(guān)
else {Mcs=0;Scs=1;Disp_Chinese(2,32,kai);}
while(1)
{
if (OK_Key == 0) // 設(shè)置和選擇項(xiàng)目鍵
{
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;//開關(guān)
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) // 設(shè)置和選擇項(xiàng)目鍵
{
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; //小時(shí)
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);//讀小時(shí)
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);//鬧鐘顯示時(shí)間到!
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)//判斷是否到鬧鐘設(shè)定時(shí)間
{
for(a=0; a<100; a++)//BELL脈沖輸出,驅(qū)動(dòng)蜂鳴器
{
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



關(guān)鍵詞: c51萬年歷溫度與鬧

評(píng)論


技術(shù)專區(qū)

關(guān)閉