|
/******************************************************** **這個(gè)程序是時(shí)鐘程序用LCM12832作為顯示. **P1口作為鍵盤輸入P1.0=增加鍵;P11為選擇鍵 **時(shí)鐘顯示格式為:“時(shí):分:秒”字體為16*16點(diǎn)陣 **修改方式為兩鍵式選擇鍵合修改鍵 **還可顯示萬年歷:“年:月:日” **需要子函數(shù): ** 1、HEX->BCD子函數(shù)hex_bcd() ** 2、顯示子函數(shù)display() ** 3、鍵盤子函數(shù)key() ** 4、時(shí)鐘子函數(shù)time() ** 5、日歷子函數(shù)day() ** 6、顯示控制子函數(shù)discommond() ** 7、定時(shí)器中斷0 time0() ** 8、初始化子函數(shù) begin(). ** 9、初始屏顯display_begin(). ** 10、時(shí)間屏顯display_time(). ** 11、潤年判斷l(xiāng)eapf(). **現(xiàn)有問題:鍵盤修改程序還未完成 ** http://www.fast88.co ** 程序不夠精簡 *********************************************************/ #include<reg51.h> #define time_TH 0x3c; // time0 :50ms 12M #define time_TL 0xba; unsigned char data msecond=0; bit data second_flag=0,day_flag=0,leap=0,display_flag=0,ku_flag; unsigned char day_temp; struct time_str{ unsigned char hour; unsigned char minute; unsigned char second; }time_now; struct day_str{ unsigned int year; unsigned char month; unsigned char day; }day_now; //顯示緩沖區(qū) unsigned char data display_bcd[13];
//每月天數(shù)表 unsigned char code day_num[]= {31,28,31,30,31,30,31,31,30,31,30,31};
//時(shí)間顯示位置表 unsigned char code time_loc[][1]= {0,2,0,3,0,4,0,5,0,8,0,9,0,12,0,13 ,16,4,16,5,16,8,16,9,16,12,16,13};
//漢字顯示位置表 //指定位置顯示“年,月,日,時(shí),分,秒” unsigned char code zhi_loc[]= {0x06,0x01,0x0a,0x01,0x0e,0x01,0x06,0x10,0x0a,0x10,0x0e,0x10}; /******************************************************************** **字庫開始 **********************************************************************/ unsigned char code shi[]={ /*-- 文字: 年 --*/ /*-- 宋體12; 此字體下對應(yīng)的點(diǎn)陣為:寬x高=16x16 --*/ 0x08,0x00,0x0F,0xFC,0x10,0x80,0x10,0x80,0x20,0x80,0x4F,0xF8,0x88,0x80,0x08,0x80, 0x08,0x80,0x08,0x80,0xFF,0xFE,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80,
/*-- 文字: 月 --*/ /*-- 宋體12; 此字體下對應(yīng)的點(diǎn)陣為:寬x高=16x16 --*/ 0x07,0xF0,0x04,0x10,0x04,0x10,0x04,0x10,0x07,0xF0,0x04,0x10,0x04,0x10,0x04,0x10, 0x07,0xF0,0x04,0x10,0x08,0x10,0x08,0x10,0x10,0x10,0x20,0x50,0x40,0x20,0x00,0x00, /*-- 文字: 日 --*/ /*-- 宋體12; 此字體下對應(yīng)的點(diǎn)陣為:寬x高=16x16 --*/ 0x00,0x00,0x1F,0xF0,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x1F,0xF0,0x10,0x10, 0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x1F,0xF0,0x10,0x10,0x00,0x00,0x00,0x00, /*-- 文字: 時(shí) --*/ /*-- 宋體12; 此字體下對應(yīng)的點(diǎn)陣為:寬x高=16x16 --*/ 0x00,0x10,0x00,0x10,0x7C,0x10,0x44,0x10,0x47,0xFE,0x44,0x10,0x7C,0x10,0x45,0x10, 0x44,0x90,0x44,0x90,0x7C,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x50,0x00,0x20, /*-- 文字: 分 --*/ /*-- 宋體12; 此字體下對應(yīng)的點(diǎn)陣為:寬x高=16x16 --*/ 0x08,0x80,0x0C,0x80,0x08,0x40,0x10,0x20,0x10,0x30,0x20,0x18,0x40,0x0E,0x9F,0xE4, 0x04,0x20,0x04,0x20,0x04,0x20,0x04,0x20,0x08,0x20,0x10,0xA0,0x20,0x40,0x40,0x00, /*-- 文字: 秒 --*/ /*-- 宋體12; 此字體下對應(yīng)的點(diǎn)陣為:寬x高=16x16 --*/ 0x0C,0x20,0xF0,0x20,0x10,0x20,0x11,0x28,0xFD,0xA4,0x11,0x22,0x32,0x22,0x3A,0x20, 0x54,0x22,0x54,0x22,0x90,0x04,0x10,0x08,0x10,0x10,0x10,0x60,0x11,0x80,0x16,0x00}; unsigned char code num[]={ /*-- 文字: 0 --*/ /*-- 宋體12; 此字體下對應(yīng)的點(diǎn)陣為:寬x高=8x16 --*/ 0x00,0x00,0x00,0x18,0x24,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x24,0x18,0x00,0x00, /*-- 文字: 1 --*/ /*-- 宋體12; 此字體下對應(yīng)的點(diǎn)陣為:寬x高=8x16 --*/ 0x00,0x00,0x00,0x10,0x70,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x7C,0x00,0x00, /*-- 文字: 2 --*/ /*-- 宋體12; 此字體下對應(yīng)的點(diǎn)陣為:寬x高=8x16 --*/ 0x00,0x00,0x00,0x3C,0x42,0x42,0x42,0x04,0x04,0x08,0x10,0x20,0x42,0x7E,0x00,0x00, /*-- 文字: 3 --*/ /*-- 宋體12; 此字體下對應(yīng)的點(diǎn)陣為:寬x高=8x16 --*/ 0x00,0x00,0x00,0x3C,0x42,0x42,0x04,0x18,0x04,0x02,0x02,0x42,0x44,0x38,0x00,0x00, /*-- 文字: 4 --*/ /*-- 宋體12; 此字體下對應(yīng)的點(diǎn)陣為:寬x高=8x16 --*/ 0x00,0x00,0x00,0x04,0x0C,0x14,0x24,0x24,0x44,0x44,0x7E,0x04,0x04,0x1E,0x00,0x00, /*-- 文字: 5 --*/ /*-- 宋體12; 此字體下對應(yīng)的點(diǎn)陣為:寬x高=8x16 --*/ 0x00,0x00,0x00,0x7E,0x40,0x40,0x40,0x58,0x64,0x02,0x02,0x42,0x44,0x38,0x00,0x00, /*-- 文字: 6 --*/ /*-- 宋體12; 此字體下對應(yīng)的點(diǎn)陣為:寬x高=8x16 --*/ 0x00,0x00,0x00,0x1C,0x24,0x40,0x40,0x58,0x64,0x42,0x42,0x42,0x24,0x18,0x00,0x00, /*-- 文字: 7 --*/ /*-- 宋體12; 此字體下對應(yīng)的點(diǎn)陣為:寬x高=8x16 --*/ 0x00,0x00,0x00,0x7E,0x44,0x44,0x08,0x08,0x10,0x10,0x10,0x10,0x10,0x10,0x00,0x00, /*-- 文字: 8 --*/ /*-- 宋體12; 此字體下對應(yīng)的點(diǎn)陣為:寬x高=8x16 --*/ 0x00,0x00,0x00,0x3C,0x42,0x42,0x42,0x24,0x18,0x24,0x42,0x42,0x42,0x3C,0x00,0x00, /*-- 文字: 9 --*/ /*-- 宋體12; 此字體下對應(yīng)的點(diǎn)陣為:寬x高=8x16 --*/ 0x00,0x00,0x00,0x18,0x24,0x42,0x42,0x42,0x26,0x1A,0x02,0x02,0x24,0x38,0x00,0x00, /*-- 文字: 0 --*/ /*-- 宋體12; 此字體下對應(yīng)的點(diǎn)陣為:寬x高=8x16 --*/ 0xFF,0xFF,0xFF,0xE7,0xDB,0xBD,0xBD,0xBD,0xBD,0xBD,0xBD,0xBD,0xDB,0xE7,0xFF,0xFF, /*-- 文字: 1 --*/ /*-- 宋體12; 此字體下對應(yīng)的點(diǎn)陣為:寬x高=8x16 --*/ 0xFF,0xFF,0xFF,0xEF,0x8F,0xEF,0xEF,0xEF,0xEF,0xEF,0xEF,0xEF,0xEF,0x83,0xFF,0xFF, /*-- 文字: 2 --*/ /*-- 宋體12; 此字體下對應(yīng)的點(diǎn)陣為:寬x高=8x16 --*/ 0xFF,0xFF,0xFF,0xC3,0xBD,0xBD,0xBD,0xFB,0xFB,0xF7,0xEF,0xDF,0xBD,0x81,0xFF,0xFF, /*-- 文字: 3 --*/ /*-- 宋體12; 此字體下對應(yīng)的點(diǎn)陣為:寬x高=8x16 --*/ 0xFF,0xFF,0xFF,0xC3,0xBD,0xBD,0xFB,0xE7,0xFB,0xFD,0xFD,0xBD,0xBB,0xC7,0xFF,0xFF, /*-- 文字: 4 --*/ /*-- 宋體12; 此字體下對應(yīng)的點(diǎn)陣為:寬x高=8x16 --*/ 0xFF,0xFF,0xFF,0xFB,0xF3,0xEB,0xDB,0xDB,0xBB,0xBB,0x81,0xFB,0xFB,0xE1,0xFF,0xFF, /*-- 文字: 5 --*/ /*-- 宋體12; 此字體下對應(yīng)的點(diǎn)陣為:寬x高=8x16 --*/ 0xFF,0xFF,0xFF,0x81,0xBF,0xBF,0xBF,0xA7,0x9B,0xFD,0xFD,0xBD,0xBB,0xC7,0xFF,0xFF, /*-- 文字: 6 --*/ /*-- 宋體12; 此字體下對應(yīng)的點(diǎn)陣為:寬x高=8x16 --*/ 0xFF,0xFF,0xFF,0xE3,0xDB,0xBF,0xBF,0xA7,0x9B,0xBD,0xBD,0xBD,0xDB,0xE7,0xFF,0xFF, /*-- 文字: 7 --*/ /*-- 宋體12; 此字體下對應(yīng)的點(diǎn)陣為:寬x高=8x16 --*/ 0xFF,0xFF,0xFF,0x81,0xBB,0xBB,0xF7,0xF7,0xEF,0xEF,0xEF,0xEF,0xEF,0xEF,0xFF,0xFF, /*-- 文字: 8 --*/ /*-- 宋體12; 此字體下對應(yīng)的點(diǎn)陣為:寬x高=8x16 --*/ 0xFF,0xFF,0xFF,0xC3,0xBD,0xBD,0xBD,0xDB,0xE7,0xDB,0xBD,0xBD,0xBD,0xC3,0xFF,0xFF, /*-- 文字: 9 --*/ /*-- 宋體12; 此字體下對應(yīng)的點(diǎn)陣為:寬x高=8x16 --*/ 0xFF,0xFF,0xFF,0xE7,0xDB,0xBD,0xBD,0xBD,0xD9,0xE5,0xFD,0xFD,0xDB,0xC7,0xFF,0xFF, }; unsigned char code ku[]={ /*-- 調(diào)入了一幅圖像:這是哭的的圖像 --*/ /*-- 寬度x高度=16x16 --*/ 0x03,0xC0,0x0C,0x30,0x10,0x08,0x20,0x04,0x40,0x02,0x52,0x4A,0x8C,0x31,0x80,0x01, 0x80,0x01,0x81,0x81,0x42,0x42,0x44,0x22,0x20,0x04,0x10,0x08,0x0C,0x30,0x03,0xC0, /*-- 調(diào)入了一幅圖像:這是笑的的圖像 --*/ /*-- 寬度x高度=16x16 --*/ 0x03,0xC0,0x0C,0x30,0x10,0x08,0x20,0x04,0x40,0x02,0x40,0x02,0x8C,0x31,0x92,0x49, 0x80,0x01,0x80,0x01,0x44,0x22,0x42,0x42,0x21,0x84,0x10,0x08,0x0C,0x30,0x03,0xC0 }; /***************************************************************************** **字庫結(jié)束 ******************************************************************************/ void day(); void time(); void begin(); void display(unsigned char *cpoint,unsigned char x_line,unsigned char y_line,unsigned char s_l); unsigned char hex_bcd(unsigned char hex); void display_begin(); void display_time(struct time_str time,struct day_str day); bit leapf(unsigned int year); void main() { begin(); display_begin(); while (1) { while (1) { time(); day(); if (display_flag) { display_flag=0; display_time(time_now,day_now); } if (display_flag) continue; if((day_now.month==2)&leap) { leap=0; day_temp=29; } } } } /****************************************************** **time()子函數(shù) **參數(shù):second_flay ** ******************************************************/ void time(){ if(second_flag){ display_flag=1; second_flag=0; // day_flag=1;
time_now.second++; if(time_now.second==60){ time_now.second=0; time_now.minute++; if(time_now.minute==60){ time_now.minute=0; time_now.hour++; if(time_now.hour==24){ time_now.hour=0; day_flag=1; } } } } } /********************************************************* **day()子函數(shù) **參數(shù):day_flag日標(biāo)志;leap潤年標(biāo)志 ** **********************************************************/ void day(){ if(day_flag){ day_flag=0; day_now.day++; if(day_now.day==day_temp+1){ day_now.month++; if((day_now.month==2)&leap){ leap=0
|