本文包含原理图、PCB、源代码、封装库、中英文PDF等资源
您需要 登录 才可以下载或查看,没有账号?注册会员
×
[color=ound-color:#ffffff]小弟瞎搞了一个万年历时钟兼有篮球计分功能的程序,但是时钟每小时慢了十几分钟,求各位高手指点迷津。是不是因为中断没设优先级还是for延时导致时钟慢了呢?
[color=ound-color:#ffffff]#include<REG52.H>
[color=ound-color:#ffffff]// unsigned char code seg[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f}; //共阴数码管
[color=ound-color:#ffffff]unsigned char code seg[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90}; //共阳数码管0~9字段
[color=ound-color:#ffffff]sbit DY_KEY1=P1^0; //定义摁键
[color=ound-color:#ffffff]sbit DY_KEY2=P1^1;
[color=ound-color:#ffffff]sbit DY_KEY3=P1^2;
[color=ound-color:#ffffff]sbit DY_KEY4=P1^3;
[color=ound-color:#ffffff]sbit DY_KEY5=P1^4;
[color=ound-color:#ffffff]sbit DY_KEY6=P1^7;
[color=ound-color:#ffffff]sbit DY_KEY8=P1^5;
[color=ound-color:#ffffff]sbit fengmingqi=P1^6;
[color=ound-color:#ffffff]sbit LED=P1^7;
[color=ound-color:#ffffff]int rnian,i=0,i1=0,c=0,x=00,y=00,shi=12,fen=00,miao=00,ID=0,ID1=0,ID2=0,nian=2011,yue=01,ri=01; //x,y分别表示甲队和乙队的分数
[color=ound-color:#ffffff]int h=00,m=00; //闹钟初始值
[color=ound-color:#ffffff]void delay(int t) // 延时子程序
[color=ound-color:#ffffff]{
[color=ound-color:#ffffff]while(t--)
[color=ound-color:#ffffff]{
[color=ound-color:#ffffff]unsigned int i;
[color=ound-color:#ffffff]for(i=0;i<=200;i++)
[color=ound-color:#ffffff]{;}
[color=ound-color:#ffffff]}
[color=ound-color:#ffffff]}
[color=ound-color:#ffffff]void display(int x,int y) //数码管动态刷新显示
[color=ound-color:#ffffff]{
[color=ound-color:#ffffff]//动态刷新甲对分数十位并延时点亮
[color=ound-color:#ffffff]P2=0x10;//位选
[color=ound-color:#ffffff]P0=seg[x/10]; //送数
[color=ound-color:#ffffff]delay(1);
[color=ound-color:#ffffff]P2=0x00;
[color=ound-color:#ffffff]P0=0xff;
[color=ound-color:#ffffff]P2=0x20; //动态刷新甲对分数个位并延时点亮
[color=ound-color:#ffffff]P0=seg[x%10];
[color=ound-color:#ffffff]delay(1);
[color=ound-color:#ffffff]P2=0x00;
[color=ound-color:#ffffff]P0=0xff;
[color=ound-color:#ffffff]P2=0x40; //动态刷新乙队分数十位并延时点亮
[color=ound-color:#ffffff]P0=seg[y/10];
[color=ound-color:#ffffff]delay(1);
[color=ound-color:#ffffff]P2=0x00;
[color=ound-color:#ffffff]P0=0xff;
[color=ound-color:#ffffff]P2=0x80; //动态刷新乙队分数个位并延时点亮
[color=ound-color:#ffffff]P0=seg[y%10];
[color=ound-color:#ffffff]delay(1);
[color=ound-color:#ffffff]P2=0x00;
[color=ound-color:#ffffff]P0=0xff;
[color=ound-color:#ffffff]}
[color=ound-color:#ffffff]void display1(int shi,int fen)
[color=ound-color:#ffffff]{
[color=ound-color:#ffffff]P2=0x10; //刷新显示时间显示时钟十位,调用延时程序
[color=ound-color:#ffffff]if(i1<=50) //数码管闪烁
[color=ound-color:#ffffff]{
[color=ound-color:#ffffff]if(ID1==1)
[color=ound-color:#ffffff]{
[color=ound-color:#ffffff]P2=0x00;
[color=ound-color:#ffffff]}
[color=ound-color:#ffffff]}
[color=ound-color:#ffffff]P0=seg[shi%100/10];
[color=ound-color:#ffffff]delay(1);
[color=ound-color:#ffffff]P2=0x00;
[color=ound-color:#ffffff]P0=0xff;
[color=ound-color:#ffffff]P2=0x20; //动态刷新时钟时钟个位
[color=ound-color:#ffffff]if(i1<=50)
[color=ound-color:#ffffff]{
[color=ound-color:#ffffff]if(ID1==1)
[color=ound-color:#ffffff]{
[color=ound-color:#ffffff]P2=0x00;
[color=ound-color:#ffffff]}
[color=ound-color:#ffffff]}
[color=ound-color:#ffffff]P0=seg[shi%10];
[color=ound-color:#ffffff]delay(1);
[color=ound-color:#ffffff]P2=0x00;
[color=ound-color:#ffffff]P0=0xff;
[color=ound-color:#ffffff]P2=0x40; //动态刷新时钟分钟十位
[color=ound-color:#ffffff]if(i1<=50)
[color=ound-color:#ffffff]{
[color=ound-color:#ffffff]if(ID1==2)
[color=ound-color:#ffffff]{
[color=ound-color:#ffffff]P2=0x00;
[color=ound-color:#ffffff]}
[color=ound-color:#ffffff]}
[color=ound-color:#ffffff]P0=seg[fen%100/10];
[color=ound-color:#ffffff]delay(1);
[color=ound-color:#ffffff]P2=0x00;
[color=ound-color:#ffffff]P0=0xff;
[color=ound-color:#ffffff]P2=0x80; //动态刷新显示时钟分钟个位
[color=ound-color:#ffffff]if(i1<=50)
[color=ound-color:#ffffff]{
[color=ound-color:#ffffff]if(ID1==2)
[color=ound-color:#ffffff]{
[color=ound-color:#ffffff]P2=0x00;
[color=ound-color:#ffffff]}
[color=ound-color:#ffffff]}
[color=ound-color:#ffffff]P0=seg[fen%10];
[color=ound-color:#ffffff]delay(1);
[color=ound-color:#ffffff]P2=0x00;
[color=ound-color:#ffffff]P0=0xff;
[color=ound-color:#ffffff]}
[color=ound-color:#ffffff]void display2(int yue,int ri)
[color=ound-color:#ffffff]{
[color=ound-color:#ffffff]P2=0x10; //刷新显示月份十位
[color=ound-color:#ffffff]if(i1<=50)
[color=ound-color:#ffffff]{
[color=ound-color:#ffffff]if(ID1==3)
[color=ound-color:#ffffff]{
[color=ound-color:#ffffff]P2=0x00;
[color=ound-color:#ffffff]}
[color=ound-color:#ffffff]}
[color=ound-color:#ffffff]P0=seg[yue%100/10];
[color=ound-color:#ffffff]delay(1);
[color=ound-color:#ffffff]P2=0x00;
[color=ound-color:#ffffff]P0=0xff;
[color=ound-color:#ffffff]P2=0x20; //动态刷新月份个位
[color=ound-color:#ffffff]if(i1<=50)
[color=ound-color:#ffffff]{
[color=ound-color:#ffffff]if(ID1==3)
[color=ound-color:#ffffff]{
[color=ound-color:#ffffff]P2=0x00;
[color=ound-color:#ffffff]}
[color=ound-color:#ffffff]}
[color=ound-color:#ffffff]P0=seg[yue%10];
[color=ound-color:#ffffff]delay(1);
[color=ound-color:#ffffff]P2=0x00;
[color=ound-color:#ffffff]P0=0xff;
[color=ound-color:#ffffff]P2=0x40; //动态刷新日十位
[color=ound-color:#ffffff]if(i1<=50)
[color=ound-color:#ffffff]{
[color=ound-color:#ffffff]if(ID1==4)
[color=ound-color:#ffffff]{
[color=ound-color:#ffffff]P2=0x00;
[color=ound-color:#ffffff]}
[color=ound-color:#ffffff]}
[color=ound-color:#ffffff]P0=seg[ri%100/10];
[color=ound-color:#ffffff]delay(1);
[color=ound-color:#ffffff]P2=0x00;
[color=ound-color:#ffffff]P0=0xff;
[color=ound-color:#ffffff]P2=0x80; //动态刷新显示日个位
[color=ound-color:#ffffff]if(i1<=50)
[color=ound-color:#ffffff]{
[color=ound-color:#ffffff]if(ID1==4)
[color=ound-color:#ffffff]{
[color=ound-color:#ffffff]P2=0x00;
[color=ound-color:#ffffff]}
[color=ound-color:#ffffff]}
[color=ound-color:#ffffff]P0=seg[ri%10];
[color=ound-color:#ffffff]delay(1);
[color=ound-color:#ffffff]P2=0x00;
[color=ound-color:#ffffff]P0=0xff;
[color=ound-color:#ffffff]}
[color=ound-color:#ffffff]void display3(nian)
[color=ound-color:#ffffff]{
[color=ound-color:#ffffff]P2=0x10; //刷新显示年千位
[color=ound-color:#ffffff]if(i1<=50)
[color=ound-color:#ffffff]{
[color=ound-color:#ffffff]if(ID1==5)
[color=ound-color:#ffffff]{
[color=ound-color:#ffffff]P2=0x00;
[color=ound-color:#ffffff]}
[color=ound-color:#ffffff]}
[color=ound-color:#ffffff]P0=seg[nian%10000/1000];
[color=ound-color:#ffffff]delay(1);
[color=ound-color:#ffffff]P2=0x00;
[color=ound-color:#ffffff]P0=0xff;
[color=ound-color:#ffffff]P2=0x20; |