资源描述:
《基于单片机的电子日历时钟设计.doc》由会员上传分享,免费在线阅读,更多相关内容在学术论文-天天文库。
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};//数码的位选,左到右uchartab_1302[7]={45,50,11,19,1,1,15};uchartab_tim
2、e[8]={0,0,10,0,0,10,0,0};//时间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-"}////////////=============函数声明============////////////////voiddisplay_time();voiddelayms(uint);voiddisplay_day();voidds1302();//获
3、取DS1302的时间voidds1302_init();//DS1302的初始化voidwrite1302(uchar,uchar);//指定地址向DS1302写数据ucharread1302(uchar);//指定地址向DS1302读数据voidds1302();voidint0_init();/////////=======中断初始化=======///////////voidint0_init(){EX0=1;IT0=1;EX1=1;IT1=1;EA=1;}///////////========时间显示======/////////////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);}//////////=========延时函数========////////////////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初始化,设置初始时间{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