資源描述:
《基于單片機(jī)的電子日歷時(shí)鐘設(shè)計(jì).doc》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在學(xué)術(shù)論文-天天文庫。
1、#include#defineucharunsignedchar#defineuintunsignedint//----端口定義---sbitACC_7=ACC^7;sbitRST1=P2^5;sbitIO=P2^6;sbitSCLK=P2^7;sbitk1=P3^2;sbitk2=P3^3;sbitk3=P2^2;sbitk4=P2^3;//ucharwei[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};//數(shù)碼的位選,左到右uchartab_1302[7]={45,50,11,19,1,1,15};uchartab_tim
2、e[8]={0,0,10,0,0,10,0,0};//時(shí)間uchartab_day[8]={0,0,10,0,0,10,0,0,};//年月日uchartab_num[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xbf};//0123456789-{"0123456789-"}////////////=============函數(shù)聲明============////////////////voiddisplay_time();voiddelayms(uint);voiddisplay_day();voidds1302();//獲
3、取DS1302的時(shí)間voidds1302_init();//DS1302的初始化voidwrite1302(uchar,uchar);//指定地址向DS1302寫數(shù)據(jù)ucharread1302(uchar);//指定地址向DS1302讀數(shù)據(jù)voidds1302();voidint0_init();/////////=======中斷初始化=======///////////voidint0_init(){EX0=1;IT0=1;EX1=1;IT1=1;EA=1;}///////////========時(shí)間顯示======/////////////voiddisplay_time(){P1=0
4、x7f;P0=tab_num[tab_time[7]];delayms(10);P1=0xbf;P0=tab_num[tab_time[6]];delayms(10);P1=0xdf;P0=tab_num[tab_time[5]];delayms(10);P1=0xef;P0=tab_num[tab_time[4]];delayms(10);P1=0xf7;P0=tab_num[tab_time[3]];delayms(10);P1=0xfb;P0=tab_num[tab_time[2]];delayms(10);P1=0xfd;P0=tab_num[tab_time[1]];delayms
5、(10);P1=0xfe;P0=tab_num[tab_time[0]];delayms(10);}//////////=========延時(shí)函數(shù)========////////////////voiddelayms(uintx){inti,j;for(i=x;i>=0;i--)for(j=0;j<=110;j++);}//////////=======日期顯示======///////////voiddisplay_day(){P1=0x7f;P0=tab_num[tab_day[7]];delayms(10);P1=0xbf;P0=tab_num[tab_day[6]];delayms(
6、10);P1=0xdf;P0=tab_num[tab_day[5]];delayms(10);P1=0xef;P0=tab_num[tab_day[4]];delayms(10);P1=0xf7;P0=tab_num[tab_day[3]];delayms(10);P1=0xfb;P0=tab_num[tab_day[2]];delayms(10);P1=0xfd;P0=tab_num[tab_day[1]];delayms(10);P1=0xfe;P0=tab_num[tab_day[0]];delayms(10);}////////////=========DS1302初始化======
7、////////////voidds1302_init()//DS1302初始化,設(shè)置初始時(shí)間{uchari,add;add=0x80;write1302(0x8e,0x00);for(i=0;i<7;i++){write1302(add,tab_1302[i]);add+=2;}/*write1302(0x80,0x50);//秒...write1302(0x82,0x59);//分write1302(0x