×點(diǎn)陣數(shù)字鐘及漢字顯示_第1頁
×點(diǎn)陣數(shù)字鐘及漢字顯示_第2頁
×點(diǎn)陣數(shù)字鐘及漢字顯示_第3頁
×點(diǎn)陣數(shù)字鐘及漢字顯示_第4頁
×點(diǎn)陣數(shù)字鐘及漢字顯示_第5頁
已閱讀5頁,還剩13頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡介

16×32點(diǎn)陣數(shù)字鐘及漢字顯示作者:HYPERLINK"http://.cn/user/HEY"HEY|掃瞄數(shù)(6070)|評論數(shù)(0)|2007-08-09一.電路原理框架設(shè)計(jì)制作作品:16×32點(diǎn)陣顯示數(shù)字鐘及漢字顯示實(shí)現(xiàn)功能:點(diǎn)陣顯示的實(shí)時時鐘以及漢字等字符的左移顯示有用特征:接受雙電源供電,斷電后時鐘由電池供電還能連續(xù)運(yùn)行,而且精確性較高實(shí)現(xiàn)原理:1.時鐘顯示是由DS1302精確的時鐘芯片產(chǎn)生時鐘信號并將其送至單片機(jī),經(jīng)過單片機(jī)處理后再輸送到點(diǎn)陣顯示模塊。2。漢字顯示并左移原理是先寫入與本點(diǎn)陣驅(qū)動相應(yīng)的代碼進(jìn)單片機(jī),通過單片機(jī)掌握程序取表進(jìn)行處理后送點(diǎn)陣模塊顯示電路主要模塊及原理圖:1。單片機(jī)最小系統(tǒng)及掌握按鍵電路2.DS1302與單片機(jī)接口電路DS1302除了系統(tǒng)上電時由系統(tǒng)供電外,如果主電源斷電還有一電池給DS1302供電,防止斷電后DS1302數(shù)據(jù)消滅.4.點(diǎn)陣行驅(qū)動模塊電路行驅(qū)動接受74LS154(4—16線譯碼器)及PNP三極管,由于是16×32點(diǎn)陣顯示功率較大故接受8550NP三極管。5.點(diǎn)陣列驅(qū)動電路列驅(qū)動接受74HC595移位寄存器將掌握位級連接入單片機(jī),每個74HC595數(shù)據(jù)輸入端單獨(dú)接單片機(jī)。16×32點(diǎn)陣模塊由8塊小的8×8點(diǎn)陣模塊通過級連而拼成,共16行,32列。二:主要元器件選擇:單片機(jī):AT89S51接受市場上比較常用的AT89S51三極管:點(diǎn)陣的行驅(qū)動電路用,這里接受PNP管,簡略型號用8550點(diǎn)陣塊:為了電路簡潔,接受雙色8×8點(diǎn)陣晶振:接受的是12MHZ的晶振電源部分:接受5V電壓供電,接受的是L7805穩(wěn)壓芯片供電電阻:大部分是限流電阻,阻值為4.7K或10K,1K譯碼器:4-16線接受市場上較為常用的74LS154,用來作行驅(qū)動移位寄存器:接受74HC595移位寄存器作列驅(qū)動,驅(qū)動列端口支配及連接:P1.0-P1。2:DS1302與單片機(jī)接口P1。3-P1.4:K0,K1按鍵,用來調(diào)整時間,按下為0P0:P0口接點(diǎn)陣行驅(qū)動電路接譯碼器P2:P2口點(diǎn)陣列驅(qū)動電路接74HC595最后是做好之后的圖附:點(diǎn)陣時間顯示源程序//===================================================================================//?//*標(biāo)題:16*32點(diǎn)陣數(shù)字鐘顯示程序

//*說明:時鐘信號產(chǎn)生接受DS1302,列接受74HC595驅(qū)動(共4個),行驅(qū)動接受4-16線譯碼器74LS154?//*功能:通過動態(tài)掃描顯示時鐘,可顯示時,分,秒,日期中的月和日?//*作者:HEY?//*日期:2006—05-29?//*郵箱:billy3416@163.com

//*備注:此是我剛接觸單片機(jī)時的一個小制作程序和電路設(shè)計(jì)上難免有不足之處請諒解?//===================================================================================//#include<reg51。h>?#include<stdlib。h>?#defineucharunsignedchar//===================================================================================//?//用到的引腳及端口定義

//===================================================================================//sbitSERIALIN_0=P2^0;//定義P2。0為列向第1個74HC595的DATA輸入

sbitSERIALIN_1=P2^1;//定義P2。1為列向第2個74HC595的DATA輸入?sbitSERIALIN_2=P2^2;//定義P2.2為列向第2個74HC595的DATA輸入

sbitSERIALIN_3=P2^3;//定義P2。3為列向第2個74HC595的DATA輸入sbitCLOCK_DATA=P1^0;//定義P1.0為DS1302的DATA端口

sbitCLOCK_RST=P1^1;//定義P1。1為DS1302的復(fù)位輸出端口?sbitCLOCK_SCLK=P1^2;//定義P1。2為DS1302的時鐘信號狀態(tài)掌握sbitK0=P1^3;//K0為按鍵1,用來選擇要調(diào)整時間的選項(xiàng)(時和分)?sbitK1=P1^4;//K1為按鍵2,執(zhí)行加1sbitCLOCK=P2^4;//74HC595的移位時鐘掌握?sbitLATCH=P2^5;//74HC595的鎖存輸出時鐘掌握voidcontrol();//調(diào)整時間掌握函數(shù)?voidtime();ucharCLOCK_TIME[3]={0,0,0};//定義時鐘時間數(shù)據(jù)存儲區(qū),分別為(時,分,秒)?ucharBUFFER[8]={0,0,0,0,0,0,0,0};//顯示緩沖區(qū)?ucharYEAR[3]={0,0,0};//定義時鐘年月日數(shù)據(jù)存儲區(qū)?uchartemp[4]={0,0,0,0};//定義74HC595的移位緩沖區(qū)ucharFLASH_STO(shè)P;//顯示小時和分鐘之間的兩點(diǎn)掌握位?ucharsec_flash;//用單片機(jī)定時器模擬的一秒(用來掌握小時和分中之間的兩點(diǎn))

//===================================================================================//?//定義0—9的點(diǎn)陣顯示代碼段8*8

//===================================================================================//ucharcodebmp[10][8]={?{0xe3,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xe3},//0?{0xf7,0xc7,0xf7,0xf7,0xf7,0xf7,0xf7,0xc1},//1?{0xe3,0xdd,0xdd,0xfd,0xfb,0xf7,0xef,0xc1},//2

{0xe3,0xdd,0xfd,0xe3,0xfd,0xfd,0xdd,0xe3},//3?{0xfb,0xf3,0xeb,0xdb,0xdb,0xc1,0xfb,0xf1},//4?{0xc1,0xdf,0xdf,0xc3,0xfd,0xfd,0xdd,0xe3},//5

{0xe3,0xdd,0xdf,0xc3,0xdd,0xdd,0xdd,0xe3},//6?{0xc1,0xdd,0xfd,0xfb,0xf7,0xf7,0xf7,0xf7},//7?{0xe3,0xdd,0xdd,0xe3,0xdd,0xdd,0xdd,0xe3},//8?{0xe3,0xdd,0xdd,0xdd,0xe1,0xfd,0xdd,0xe3},//9?};//===================================================================================//?//定義0-9的點(diǎn)陣顯示代碼段8*8與上面不同的是多了小時和分鐘之間的兩點(diǎn)?//===================================================================================//ucharcodebmp_1[10][8]={?{0xe3,0xdd,0x5d,0xdd,0xdd,0x5d,0xdd,0xe3},//:0

{0xf7,0xc7,0x77,0xf7,0xf7,0x77,0xf7,0xc1},//:1?{0xe3,0xdd,0x5d,0xfd,0xfb,0x77,0xef,0xc1},//:2?{0xe3,0xdd,0x7d,0xe3,0xfd,0x7d,0xdd,0xe3},//:3?{0xfb,0xf3,0x6b,0xdb,0xdb,0x41,0xfb,0xf1},//:4

{0xc1,0xdf,0x5f,0xc3,0xfd,0x7d,0xdd,0xe3},//:4

{0xe3,0xdd,0x5f,0xc3,0xdd,0x5d,0xdd,0xe3},//:5

{0xc1,0xdd,0x7d,0xfb,0xf7,0x77,0xf7,0xf7},//:6?{0xe3,0xdd,0x5d,0xe3,0xdd,0x5d,0xdd,0xe3},//:7?{0xe3,0xdd,0x5d,0xdd,0xe1,0x7d,0xdd,0xe3},//:8?};//===================================================================================//?//定義0—9的點(diǎn)陣顯示代碼段數(shù)碼似的字模8*8顯示數(shù)據(jù)前有一橫杠將月和日格開

//===================================================================================//ucharcodebmp_2[10][8]={

{0xff,0xff,0xf8,0xfa,0x8a,0xfa,0xf8,0xff},//-0?{0xff,0xff,0xfe,0xfe,0x8e,0xfe,0xfe,0xff},//-1?{0xff,0xff,0xf8,0xfe,0x88,0xfb,0xf8,0xff},//-2?{0xff,0xff,0xf8,0xfe,0x88,0xfe,0xf8,0xff},//-3?{0xff,0xff,0xfa,0xfa,0x88,0xfe,0xfe,0xff},//-4

{0xff,0xff,0xf8,0xfb,0x88,0xfe,0xf8,0xff},//-5?{0xff,0xff,0xf8,0xfb,0x88,0xfa,0xf8,0xff},//-6?{0xff,0xff,0xf8,0xfe,0x8e,0xfe,0xfe,0xff},//-7?{0xff,0xff,0xf8,0xfa,0x88,0xfa,0xf8,0xff},//-8?{0xff,0xff,0xf8,0xfa,0x88,0xfe,0xf8,0xff},//-9?};//===================================================================================//

//定義0-9的點(diǎn)陣顯示代碼段模擬數(shù)碼似的字模8*8?//===================================================================================//ucharcodebmp_3[10][8]={?{0xff,0xff,0x8f,0xaf,0xaf,0xaf,0x8f,0xff},//0?{0xff,0xff,0xef,0xef,0xef,0xef,0xef,0xff},//1?{0xff,0xff,0x8f,0xef,0x8f,0xbf,0x8f,0xff},//2

{0xff,0xff,0x8f,0xef,0x8f,0xef,0x8f,0xff},//3?{0xff,0xff,0xaf,0xaf,0x8f,0xef,0xef,0xff},//4?{0xff,0xff,0x8f,0xbf,0x8f,0xef,0x8f,0xff},//5

{0xff,0xff,0x8f,0xbf,0x8f,0xaf,0x8f,0xff},//6

{0xff,0xff,0x8f,0xef,0xef,0xef,0xef,0xff},//7?{0xff,0xff,0x8f,0xaf,0x8f,0xaf,0x8f,0xff},//8?{0xff,0xff,0x8f,0xaf,0x8f,0xef,0x8f,0xff},//9?};//===================================================================================//

//定義0-59模擬七段數(shù)碼管顯示8*8?//===================================================================================//ucharcodebmp_4[60][8]={?{0xff,0xff,0x88,0xaa,0xaa,0xaa,0x88,0xff},//00?{0xff,0xff,0x8e,0xae,0xae,0xae,0x8e,0xff},//01?{0xff,0xff,0x88,0xae,0xa8,0xab,0x88,0xff},//02

{0xff,0xff,0x88,0xae,0xa8,0xae,0x88,0xff},//03?{0xff,0xff,0x8a,0xaa,0xa8,0xae,0x8e,0xff},//04?{0xff,0xff,0x88,0xab,0xa8,0xae,0x88,0xff},//05?{0xff,0xff,0x88,0xab,0xa8,0xaa,0x88,0xff},//06

{0xff,0xff,0x88,0xae,0xae,0xae,0x8e,0xff},//07?{0xff,0xff,0x88,0xaa,0xa8,0xaa,0x88,0xff},//08

{0xff,0xff,0x88,0xaa,0xa8,0xae,0x88,0xff},//09?{0xff,0xff,0xe8,0xea,0xea,0xea,0xe8,0xff},//10?{0xff,0xff,0xee,0xee,0xee,0xee,0xee,0xff},//11?{0xff,0xff,0xe8,0xee,0xe8,0xeb,0xe8,0xff},//12?{0xff,0xff,0xe8,0xee,0xe8,0xee,0xe8,0xff},//13?{0xff,0xff,0xea,0xea,0xe8,0xee,0xee,0xff},//14

{0xff,0xff,0xe8,0xeb,0xe8,0xee,0xe8,0xff},//15?{0xff,0xff,0xe8,0xeb,0xe8,0xea,0xe8,0xff},//16?{0xff,0xff,0xe8,0xee,0xee,0xee,0xee,0xff},//17?{0xff,0xff,0xe8,0xea,0xe8,0xea,0xe8,0xff},//18

{0xff,0xff,0xe8,0xea,0xe8,0xee,0xe8,0xff},//19?{0xff,0xff,0x88,0xea,0x8a,0xba,0x88,0xff},//20

{0xff,0xff,0x8e,0xee,0x8e,0xbe,0x8e,0xff},//21?{0xff,0xff,0x88,0xee,0x88,0xbb,0x88,0xff},//22?{0xff,0xff,0x88,0xee,0x88,0xbe,0x88,0xff},//23?{0xff,0xff,0x8a,0xea,0x88,0xbe,0x8e,0xff},//24

{0xff,0xff,0x88,0xeb,0x88,0xbe,0x88,0xff},//25?{0xff,0xff,0x88,0xeb,0x88,0xba,0x88,0xff},//26

{0xff,0xff,0x88,0xee,0x8e,0xbe,0x8e,0xff},//27

{0xff,0xff,0x88,0xea,0x88,0xba,0x88,0xff},//28?{0xff,0xff,0x88,0xea,0x88,0xbe,0x88,0xff},//29?{0xff,0xff,0x88,0xea,0x8a,0xea,0x88,0xff},//30?{0xff,0xff,0x8e,0xee,0x8e,0xee,0x8e,0xff},//31

{0xff,0xff,0x88,0xee,0x88,0xeb,0x88,0xff},//32?{0xff,0xff,0x88,0xee,0x88,0xee,0x88,0xff},//33?{0xff,0xff,0x8a,0xea,0x88,0xee,0x8e,0xff},//34?{0xff,0xff,0x88,0xeb,0x88,0xee,0x88,0xff},//35?{0xff,0xff,0x88,0xeb,0x88,0xea,0x88,0xff},//36?{0xff,0xff,0x88,0xee,0x8e,0xee,0x8e,0xff},//37?{0xff,0xff,0x88,0xea,0x88,0xea,0x88,0xff},//38?{0xff,0xff,0x88,0xea,0x88,0xee,0x88,0xff},//39?{0xff,0xff,0xa8,0xaa,0x8a,0xea,0xe8,0xff},//40?{0xff,0xff,0xae,0xae,0x8e,0xee,0xee,0xff},//41?{0xff,0xff,0xa8,0xae,0x88,0xeb,0xe8,0xff},//42

{0xff,0xff,0xa8,0xae,0x88,0xee,0xe8,0xff},//43

{0xff,0xff,0xaa,0xaa,0x88,0xee,0xee,0xff},//44

{0xff,0xff,0xa8,0xab,0x88,0xee,0xe8,0xff},//45?{0xff,0xff,0xa8,0xab,0x88,0xea,0xe8,0xff},//46?{0xff,0xff,0xa8,0xae,0x8e,0xee,0xee,0xff},//47?{0xff,0xff,0xa8,0xaa,0x88,0xea,0xe8,0xff},//48

{0xff,0xff,0xa8,0xaa,0x88,0xee,0xe8,0xff},//49?{0xff,0xff,0x88,0xba,0x8a,0xea,0x88,0xff},//50?{0xff,0xff,0x8e,0xbe,0x8e,0xee,0x8e,0xff},//51?{0xff,0xff,0x88,0xbe,0x88,0xeb,0x88,0xff},//52?{0xff,0xff,0x88,0xbe,0x88,0xee,0x88,0xff},//53?{0xff,0xff,0x8a,0xba,0x88,0xee,0x8e,0xff},//54?{0xff,0xff,0x88,0xbb,0x88,0xee,0x88,0xff},//55

{0xff,0xff,0x88,0xbb,0x88,0xea,0x88,0xff},//56

{0xff,0xff,0x88,0xbe,0x8e,0xee,0x8e,0xff},//57?{0xff,0xff,0x88,0xba,0x88,0xea,0x88,0xff},//58?{0xff,0xff,0x88,0xba,0x88,0xee,0x88,0xff},//59?};//===================================================================================//

//名稱:delay?//說明:延時函數(shù)?//功能:依據(jù)需要取不同的值,實(shí)現(xiàn)不同的延時效果?//===================================================================================//voiddelay()?{?ucharn;?for(n=0;n<=125;n++);?}voiddelay2(ucharm)?{?ucharn;

while(m-—)?{?for(n=0;n〈=200;n++);?}}//===================================================================================//?//名稱:shift?//說明:74HC595左移程序?//功能:實(shí)現(xiàn)74HC595的移位輸入?//===================================================================================//voidshift()?{?ucharj;?for(j=0;j〈8;j++)?{?temp[0]=temp[0]<<1;//將temp[0]左移1位?SERIALIN_0=CY;//進(jìn)位輸出到移位寄存器?temp[1]=temp[1]<<1;//將temp[1]左移1位后?SERIALIN_1=CY;//進(jìn)位輸出到移位寄存器

temp[2]=temp[2]<<1;//將temp[2]左移1位后?SERIALIN_2=CY;//進(jìn)位輸出到移位寄存器?temp[3]=temp[3]<<1;//將temp[0]左移1位后的進(jìn)位輸出到移位寄存器?SERIALIN_3=CY;//進(jìn)位輸出到移位寄存器?CLOCK=1;//移位時鐘掌握移位?CLOCK=0;?}?}//===================================================================================//?//名稱:display?//說明:顯示函數(shù)?//功能:將要顯示的數(shù)據(jù)通過74HC595和74LS154用LED點(diǎn)陣顯示出來?//實(shí)現(xiàn)方法:該16X32點(diǎn)陣為8塊小點(diǎn)陣,顯示時將上下分開,上面顯示時間。下面顯示日期和秒?//===================================================================================//voiddisplay(void)

{?uchari,sec;

sec=CLOCK_TIME[0];?BUFFER[0]=CLOCK_TIME[1]%10;//顯示時鐘分鐘個位

BUFFER[1]=CLOCK_TIME[1]/10;//顯示時鐘分鐘十位?BUFFER[2]=CLOCK_TIME[2]%10;//顯示時鐘小時個位?BUFFER[3]=CLOCK_TIME[2]/10;//顯示時鐘小時十位?BUFFER[4]=YEAR[1];//顯示月,從00—12

BUFFER[5]=Y(jié)EAR[2]/10;//顯示日十位?BUFFER[6]=YEAR[2]%10;//顯示日個位

BUFFER[7]=CLOCK_TIME[0];//顯示秒從00-59for(i=0;i〈16;i++)//逐行掃描?{

if(i<8)//上面的8行顯示時間?{?temp[0]=bmp[BUFFER[3]][i];//取表顯示時鐘十位?temp[1]=bmp[BUFFER[2]][i];//取表顯示時鐘個位?if(FLASH_STO(shè)P==0)//小時和分鐘之間的兩點(diǎn)閃標(biāo)志位?{

temp[2]=bmp_1[BUFFER[1]][i];//標(biāo)志位為0時,兩點(diǎn)亮?}?else?{?temp[2]=bmp[BUFFER[1]][i];//相反不亮

}

?temp[3]=bmp[BUFFER[0]][i];//取表顯示分鐘個位

}?else?{

temp[0]=bmp_4[BUFFER[4]][i-8];//通過取表顯示月?temp[1]=bmp_2[BUFFER[5]][i—8];//通過取表顯示日?temp[2]=bmp_3[BUFFER[6]][i—8];?temp[3]=bmp_4[BUFFER[7]][i-8];//通過取表顯示秒?}?shift();//調(diào)用移位函數(shù)處理??LATCH=0;LATCH=1;//輸出?P0=i;//逐行顯示,掃描?delay();//延時?P0=0xff;//顯示完一行清顯示?}?}//===================================================================================//?//單字節(jié)寫子程序RC0(SCLK),RC1(I/O),RC2(RST)?//名稱:inputdata?//說明:先寫地址,后寫數(shù)據(jù)?//功能:往DS1302寫入時鐘數(shù)據(jù)?//===================================================================================//?voidinputdata(unsignedchartmaddr,unsignedchartmdat(yī)a)

{?ucharloop;

CLOCK_DATA=0;//設(shè)置為輸出;?CLOCK_RST=0;?CLOCK_SCLK=0;?CLOCK_RST=1;?for(loop=0;loop<8;loop++)//送地址?{?tmaddr=tmaddr>〉1;//右移一位

CLOCK_DATA=CY;//輸出移位標(biāo)志位?CLOCK_SCLK=1;

CLOCK_SCLK=0;?}

for(loop=0;loop〈8;loop++)//送數(shù)據(jù)

tmdata=tmdata>>1;//右移一位?CLOCK_DATA=CY;//輸出移位標(biāo)志?CLOCK_SCLK=1;?CLOCK_SCLK=0;

}?CLOCK_SCLK=1;?CLOCK_RST=0;?CLOCK_DATA=1;//設(shè)置為輸出;

}

//===================================================================================//?//單字節(jié)讀子程序RC0(SCLK),RC1(I/O),RC2(RST)?//名稱:outputdata?//說明:讀數(shù)據(jù)?//功能:從DS1302讀取1Byte數(shù)據(jù)

//===================================================================================//?unsignedcharoutputdat(yī)a(unsignedchartmaddr)?{?ucharloop;?uchartmdata=0;?inputdat(yī)a(0x8F,0x00);

CLOCK_DATA=0;//設(shè)置為輸?CLOCK_RST=0;

CLOCK_SCLK=0;

CLOCK_RST=1;?for(loop=8;loop>0;loop——)//送地址?{?tmaddr=tmaddr>>1;

CLOCK_DATA=CY;?CLOCK_SCLK=1;?CLOCK_SCLK=0;?}?CLOCK_DATA=1;//設(shè)置為輸入;?CLOCK_DATA=1;?CLOCK_SCLK=1;?CLOCK_SCLK=0;

for(loop=8;loop〉0;loop—-)//讀數(shù)據(jù)?{?tmdata=tmdata>〉1;

if(CLOCK_DATA==1)

tmdata=tmdat(yī)a|0x80;?CLOCK_SCLK=1;?CLOCK_SCLK=0;?}?tmdat(yī)a=tmdata〈<1;//由于在開頭讀是已經(jīng)是其次個時鐘下降延所以要進(jìn)行左移處理?if(CY==1)?tmdata=tmdat(yī)a|0x01;?CLOCK_SCLK=1;?CLOCK_RST=0;?return(tmdat(yī)a);?}//===================================================================================//

//函數(shù):調(diào)整時間子程序?//名稱:control?//說明:調(diào)整時間掌握?//功能:通過兩個按鍵調(diào)整時間,其中一個選擇要調(diào)整的分鐘或時鐘,另一個加1功能

//===================================================================================//voidcontrol()?{?ucharmin16,hour16;?inputdata(0x80,0x80);//時鐘停止運(yùn)行?CLOCK_TIME[0]=0;//秒初始化位0?FLASH_STOP=0;//時鐘分鐘之間兩點(diǎn)狀態(tài)位為0?TR0=0;//開啟T0定時器while(1)?{?if(K1==0)//當(dāng)K1按下時?{?delay2(50);//延時?if(K1==0)//K1按下?{?CLOCK_TIME[1]=CLOCK_TIME[1]+1;//分鐘加1?if(CLOCK_TIME[1]==60)//當(dāng)分鐘加到60時初始化為0?CLOCK_TIME[1]=0;

}?}?if(K0==0)//K0鍵再次按下,小時調(diào)整?{

delay2(100);?if(K0==0)

while(1)?{?if(K0==1)//K0鍵按下加1?{while(1)

{?if(K1==0)?{?delay2(50);

if(K1==0)

{?CLOCK_TIME[2]=CLOCK_TIME[2]+1;//小時加1

if(CLOCK_TIME[2]==24)//當(dāng)變成24時初始化為0?CLOCK_TIME[2]=0;?}??}?if(K0==0)//當(dāng)K0再次按下時返回?{?delay2(100);?if(K0==0)?{

while(1)?{?if(K0==1)//按下的鍵彈起時?{

min16=CLOCK_TIME[1]/10*16+CLOCK_TIME[1]%10;//將所得的分鐘數(shù)據(jù)轉(zhuǎn)變成16進(jìn)制數(shù)據(jù)?hour16=CLOCK_TIME[2]/10*16+CLOCK_TIME[2]%10;//將所得的小時數(shù)據(jù)轉(zhuǎn)變成16進(jìn)制數(shù)據(jù)

inputdata(0x84,hour16);//將調(diào)整后的小時數(shù)據(jù)寫入DS1302?inputdata(0x82,min16);//將調(diào)整后的分鐘數(shù)據(jù)寫入DS1302?

inputdata(0x80,0x00);//啟動時鐘?time();//回到time函數(shù)?}

}?}?}?display();//顯示函數(shù)?}??}?}?}?}

display();//顯示函數(shù)

}?}//===================================================================================//?//函數(shù):T0中斷服務(wù)子程序

//名稱:time0

//說明:掌握時鐘和分鐘之間的兩點(diǎn)顯示

//功能:利用單片機(jī)內(nèi)部定時器造成0.5秒時鐘和分鐘之間兩點(diǎn)閃動?//===================================================================================//?voidtime0(void)interrupt1using1//T0中斷函數(shù)?{

TH0=-10100/256;//填入計(jì)數(shù)器初值高位?TL0=—10100%256;//填入計(jì)數(shù)器初值低位

sec_flash=sec_flash+1;?if(sec_flash==50)//0。5S到?{?FLASH_STOP=0;

}?if(sec_flash==100)//1S到

{

FLASH_STOP=1;?sec_flash=0;?}?}//===================================================================================//

//函數(shù):時間掌握函數(shù)?//說明:統(tǒng)一時鐘顯示于調(diào)整?//功能:?//===================================================================================//?voidtime()?{

ucharsec,min,hour,year,month,day;?FLASH_STOP=1;

EA=1;ET0=1;//開總中斷源,開T0中斷?TMOD=0x61;//T1方式2計(jì)數(shù),T0方式1計(jì)時

TH0=—10000/256;TL0=-10000%256;//初始化計(jì)數(shù)器初值?ET0=1,TR0=1;//開中斷??inputdat(yī)a(0x8E,0x00);//掌握命令,WP=0,寫操作?inputdata(0x90,0x06);while(1)?{?K0=1;//K0=1?if(K0==0)

{?delay2(100);//延時?if(K0==0)//K0按下時?{

while(1)

{?if(K0==1)

{?control();//進(jìn)入調(diào)時子程序?}

}?}

}?sec=outputdata(0x81);//讀取秒?min=outputdata(0x83);//讀取分?hour=outputdata(0x85);//讀取時?year=outputdat(yī)a(0x8d);//讀取年?month=outputdat(yī)a(0x89);//讀取月

day=outputdata(0x87);//讀取日

CLOCK_TIME[0]=sec/16*10+sec%16;//將讀取到的16進(jìn)制數(shù)轉(zhuǎn)化為10進(jìn)制?CLOCK_TIME[1]=min/16*10+min%16;//將讀取到的16進(jìn)制數(shù)轉(zhuǎn)化為10進(jìn)制

CLOCK_TIME[2]=hour/16*10+hour%16;//將讀取到的16進(jìn)制數(shù)轉(zhuǎn)化為10進(jìn)制??YEAR[0]=year/16*10+year%16;//將讀取到的16進(jìn)制數(shù)轉(zhuǎn)化為10進(jìn)制

YEAR[1]=month/16*10+month%16;?YEAR[2]=day/16*10+day%16;display();//調(diào)用顯示子函數(shù)?}?}//===================================================================================//?//函數(shù):主程序?//說明:?//功能:

//===================================================================================//?voidmain()?{?time();?}附:點(diǎn)陣漢字顯示程序//===================================================================================//?//*標(biāo)題:16*32點(diǎn)陣漢字顯示程序

//*說明:接受89s51或52單片機(jī),12M晶震,列接受74HC595驅(qū)動(共4個),行驅(qū)動接受4-16線譯碼器74LS154?//*功能:通過動態(tài)掃描顯示漢字,并實(shí)現(xiàn)左移功能?//*作者:HEY?//*日期:2006-06-01?//*郵箱:billy3416@163.com?//*聲明:以下源程序均通過keil調(diào)試與硬件實(shí)現(xiàn)均無問題

//===================================================================================//?#include<reg52.h〉

#include<stdlib.h>?#defineucharunsignedchar//===================================================================================//?//用到的引腳及端口定義及全局變量

//===================================================================================//?sbitSERIALIN_0=P2^0;//定義P2.0為列向第1個74HC595的DATA輸入

sbitSERIALIN_1=P2^1;//定義P2。1為列向第1個74HC595的DATA輸入

sbitSERIALIN_2=P2^2;//定義P2.2為列向第1個74HC595的DATA輸入?sbitSERIALIN_3=P2^3;//定義P2。3為列向第1個74HC595的DATA輸入sbitCLOCK=P2^4;//74HC595的移位時鐘掌握?sbitLATCH=P2^5;//74HC595的鎖存輸出時鐘掌握uchartemp[4]={0,0,0,0};//用到的74HC595顯示緩沖區(qū)變量?uchardisp[4][16];//用到的顯示緩沖區(qū)//===================================================================================//

//定義要顯示的漢字代碼段16*16,分別是左上—左下-右上-右下?//===================================================================================//?ucharcodeword[52][16]={?/*****點(diǎn)*****/

{0xfe,0xfe,0xfe,0xfe,0xfe,0xe0,0xef,0xef,0xef,0xe0,0xef,0xfe,0xd7,0xdb,0xbb,0xff},?{0xff,0xff,0x07,0xff,0xef,0x07,0xef,0xef,0xef,0x0f,0xef,0xef,0x77,0xbb,0xbb,0xff},/*****陣*****/

{0xff,0x07,0x77,0x68,0x5e,0x6e,0x75,0x70,0x77,0x57,0x68,0x7f,0x7f,0x7f,0x7f,0x7f},?{0x7f,0x7f,0x7f,0x03,0xff,0xbf,0xbf,0x03,0xbf,0xbf,0x01,0xbf,0xbf,0xbf,0xbf,0xbf},/*****顯*****/?{0xff,0xe0,0xef,0xe0,0xef,0xe0,0xfb,0xfb,0xbb,0xdb,0xeb,0xeb,0xfb,0x00,0xff,0xff},?{0xff,0x0f,0xef,0x0f,0xef,0x0f,0xbf,0xbf,0xb7,0xb7,0xaf,0x9f,0xbf,0x01,0xff,0xff},/*****示*****/?{0xff,0xe0,0xff,0xff,0xff,0x80,0xfe,0xfe,0xee,0xee,0xde,0xbe,0x7e,0xfe,0xfa,0xfd},

{0xff,0x07,0xff,0xff,0xff,0x01,0xff,0xff,0xdf,0xef,0xf7,0xf3,0xfb,0xff,0xff,0xff},/*****由*****/?{0xfe,0xfe,0xfe,0xfe,0xc0,0xde,0xde,0xde,0xc0,0xde,0xde,0xde,0xde,0xc0,0xdf,0xff},

{0xff,0xff,0xff,0xff,0x07,0xf7,0xf7,0xf7,0x07,0xf7,0xf7,0xf7,0xf7,0x07,0xf7,0xff},/*****信*****/?{0xf7,0xf3,0xe7,0xe8,0xcf,0xcc,0xaf,0x6c,0xef,0xec,0xed,0xed,0xed,0xec,0xed,0xff},

{0x7f,0x9f,0xbf,0x01,0xff,0x07,0xff,0x07,0xff,0x07,0xf7,0xf7,0xf7,0x07,0xf7,0xff},/*****息*****/?{0xfe,0xfd,0xe0,0xef,0xe0,0xef,0xe0,0xef,0xe0,0xff,0xf6,0xd7,0xd7,0x97,0xf8,0xff},?{0xff,0xff,0x0f,0xef,0x0f,0xef,0x0f,0xef,0x0f,0xff,0xff,0x7b,0x6d,0xed,0x0f,0xff},/*****工*****/?{0xff,0xc0,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0x00,0xff,0xff},?{0xff,0x03,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x01,0xff,0xff},/*****程*****/

{0xf2,0x8e,0xee,0xee,0x02,0xee,0xcf,0xc4,0xab,0xaf,0x6c,0xef,0xef,0xef,0xe8,0xef},?{0x07,0xf7,0xf7,0xf7,0xf7,0x07,0xff,0x03,0xbf,0xbf,0x03,0xbf,0xbf,0xbf,0x01,0xff},/*****學(xué)*****/?{0xfe,0xef,0xf3,0xf7,0x80,0xbf,0x70,0xff,0xff,0x80,0xff,0xff,0xff,0xff,0xfd,0xfe},?{0xf7,0x73,0x37,0x6f,0x01,0xfb,0x17,0xbf,0x7f,0x01,0x7f,0x7f,0x7f,0x7f,0x7f,0xff},/*****院*****/

{0xff,0x07,0x70,0x6b,0x5f,0x5c,0x6f,0x77,0x70,0x56,0x6e,0x7e,0x7d,0x7d,0x7b,0x77},

{0x7f,0xbf,0x01,0xfb,0xff,0x07,0xff,0xff,0x01,0xdf,0xdf,0xdf,0xdd,0xdd,0xdd,0xe1},?{0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff},?{0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff},?{0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff},?{0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff}};??//===================================================================================//?//名稱:delay?//說明:延時函數(shù)?//功能:依據(jù)需要取不同的值,實(shí)現(xiàn)不同的延時效果

//===================================================================================//?voiddelay()?{?uchari;?for(i=0;i〈=100;i++);?}

//==============================================================

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

最新文檔

評論

0/150

提交評論