資源描述:
《單片機課程設(shè)計--數(shù)字時鐘》由會員上傳分享,免費在線閱讀,更多相關(guān)內(nèi)容在學術(shù)論文-天天文庫。
1、單片機課程設(shè)計,數(shù)字時鐘學校:中原工學院信息商務(wù)學院專業(yè):機械設(shè)計制造及其自動化班級:機自102名:彪1、設(shè)計要求1、顯示學號及制作日期。2、可以調(diào)整時間,時分秒。3、可以定時2、配件51或52單片機一個,各種電容若干個,各種電阻若干個,六個共陽極led燈,一個12MHZ晶振,一個32.768kHz晶振,一個ds1302時鐘芯片,一個排阻,一個喇叭,五個按鈕,導線若干個。3、數(shù)字電路模擬圖5、單片機程序#include#include#defineucharunsignedchar#defineuintunsignedintbitta
2、,ni,wo,nao,hu,ding,cha;uinta,j,k,dingshi,dingfen;ucharz,x,c,v,b,n,shi,fen,miao,w,r,y,dat,ds1,ds2,df1,df2,huancun,Th0,Tl0;ucharcodetab[]={0x40,0x79,0x24,0x30,0x19,0x12,0x02,0x78,0x00,0x10};sbitshi1=P1^0;sbitshi2=P1^1;sbitfen1=P1^2;sbitfen2=P1^3;sbitmiao1=P1^4;sbitmiao2=P1^5;sbitRST=P2^0;s
3、bitSCLK=P2^1;sbitIO=P2^2;sbitjiashi=P2^3;sbitjiafen=P2^4;sbitjiamiao=P2^5;sbitkai=P2^6;sbitxiang=P2^7;voiddelay1();voidshuru(ucharq);voidxuehao1(ucharz,ucharx,ucharc,ucharv,ucharb,ucharn);voidwrite_byte(uchardat);//寫一個字節(jié)ucharread_byte();//讀一個字節(jié)voidwrite_1302(ucharadd,uchardat);//向1302芯片寫
4、函數(shù),指定寫入地址,數(shù)據(jù)ucharread_1302(ucharadd);//從1302讀數(shù)據(jù)函數(shù),指定讀取數(shù)據(jù)來源地址voidds1302_init();//1302芯片初始化子函數(shù)(2012-06-18,12:00:00,week7)ucharreadset1302(ucharCmd);voidxianshimiao(ucharw);voidxianshifen(ucharr);voidxianshishi(uchary);voidtiaozhengshi();voidtiaozhengfen();voidtiaozhengmiao();voidPlayKey(vo
5、id);voiddelay_1ms(uchari);voiddingshikaiguan(void);voidchanao(void);voidtiaozhengshijian(void);voidkaishi(ucharz,ucharx,ucharc,ucharv,ucharb,ucharn);ucharcodeKeyCode[]={0xFF,0xFF,0xF8,0x8B,0xF9,0x5B,0xFA,0x14,0xFA,0x66,0xFB,0x03,0xFB,0x8F,0xFC,0x0B,//低音0xFC,0x43,0xFC,0xAB,0xFD,0x08,0xFD,
6、0x33,0xFD,0x81,0xFD,0xC7,0xFE,0x05,//中音0xFE,0x21,0xFE,0x55,0xFE,0x84,0xFE,0X99,0XFE,0xC0,0xFE,0xE3,0xFF,0x02,//高音};voidint2_int()interrupt0{hu=1;ding=0;cha=0;}time0()interrupt1//定時器0中斷{TH0=Th0;TL0=Tl0;xiang=~xiang;}voidmain(){P1=0;xiang=1;ding=0;cha=0;kaishi(2,0,1,0,0,6);kaishi(0,2,4,2,1
7、,4);kaishi(1,3,0,6,1,6);ds1302_init();EA=1;EX0=1;IT0=1;TMOD=0X01;TR0=0;ET0=1;while(1){miao=read_1302(0x81);xianshimiao(miao);fen=read_1302(0x83);xianshifen(fen);shi=read_1302(0x85);xianshishi(shi);chanao();dingshikaiguan();if(ding==1){PlayKey();xiang=1;}tiaozhengshijian()