您好,欢迎访问三七文档
当前位置:首页 > 行业资料 > 酒店餐饮 > DS1302时钟程序
本文件包含C语言程序以及仿真原理图!程序:#includereg52.h#includeintrins.h#defineucharunsignedchar#defineuintunsignedintsbitsclk=P3^0;sbitdio=P3^1;sbitce=P3^2;sbits0=P2^0;sbits1=P2^1;uchard[10]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};uchara[8]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};ucharshi,fen,miao;uintx=1;voidshow(ucharshi,ucharfen,ucharmiao);voiddelay(uintz){uintx,y;for(y=z;y0;y--)for(x=110;x0;x--);}voiddisplay(ucharshu,ucharwei){s0=0;s1=0;P1=0XFF;P1=a[wei];s1=1;s1=0;if(x%2==0)//小数点显示判定{P1=d[shu]&0x7f;x++;}else{P1=d[shu];x++;}if(x==6)x=0;delay(2);s0=0;}voidwrite(ucharadd,uchardate){uchartemp,t;ce=0;sclk=0;ce=1;temp=add;for(t=0;t8;t++)//地址控制{if((temp&0x01)==1){dio=1;}elsedio=0;sclk=1;delay(1);sclk=0;temp=temp1;}temp=date;for(t=8;t0;t--)//写数据{if((temp&0x01)==1){dio=1;}elsedio=0;sclk=1;delay(1);sclk=0;temp=temp1;}ce=0;}ucharread(ucharadd){uchartemp,t;ce=0;sclk=0;ce=1;temp=add;for(t=0;t8;t++){if((temp&0x01)==1)dio=1;elsedio=0;sclk=1;sclk=0;temp=1;}temp=0;for(t=0;t7;t++){if(dio==1)temp=temp|0x80;elsetemp=temp&0x7f;sclk=1;sclk=0;temp=1;}returntemp;}voidchu(){write(0x8e,0x00);//写保护write(0x80,0x00);//写秒write(0x82,0x43);//写分write(0x84,0x15);//写时write(0x86,0x17);write(0x88,0x7);write(0x8c,0x11);write(0x8e,0x80);}voidmain(){chu();//设定初始时间while(1){shi=read(0x85);//读出时间fen=read(0x83);miao=read(0x81);show(shi,fen,miao);//显示时间}}voidshow(ucharshi,ucharfen,ucharmiao){display(shi4,0);display(shi&0x0f,1);display(fen4,2);display(fen&0x0f,3);display(miao4,4);display(miao&0x0f,5);}
本文标题:DS1302时钟程序
链接地址:https://www.777doc.com/doc-6091449 .html