STC单片机做的电子表C51程序
时间:08-29
来源:互联网
点击:
电路很简单我就不画了,是stc系列的单片机做的,显示部分就是2个74hc573芯片连到P1口,然后用p3.0控制段选,按键的定义程序里有说明。很容易就能搭出来,下图是效果图,自己用万用板焊的,技术不行。到处都是飞线呵呵,请大家多多指教
程序的c51语言完整版本的下载地址:http://www.51hei.com/f/biaoc4.rar
#includestc90.h>#define uchar unsigned char#define uint unsigned intuchar d0,ss,gs,sf,gf,sm,gm;uchar e1,e2,e3,e4,e5,e6;uchar s1,q1;uchar shi,fen,miao;// 8 4 2 1 8 4 2 1 // h g f e d c b a//效正 累加数98 跑1320秒 实际1316//当前已走秒数 乘以 当前累加数 除以除以实际秒数 等于 累加数应得值uchar code num[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x80};//0-9 点uchar code wes[]={0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0x7f};//1-8位sbit dua=P3^0;sbit laba=P3^1;sbit a1=P3^2;//时间设置sbit a2=P3^3;//闹钟设置sbit a3=P3^4;//按键+sbit a4=P3^5;//按键-sbit a5=P3^7;//返回 启动闹钟void weiduan(uchar z,uchar x); //位段 函数void chushi(); //初始化函数void shijian(); //时间显示函数void shjianbata();//测试时间函数void shezhi(); //时间设置函数void naozhong(); //闹钟这是函数void shu(); //时间最大值限制函数void delay(uchar d1);//延时函数//...................................................................void main(){ chushi(); //初始化时间TH0=(65535-40000)/256;//定时器装初值TL0=(65535-40000)%256;ET0=1;//开定时器0中断TR0=1;//启动定时器0EA=1; //打开总中断laba=1;while(1){ shijian(); //调用时间显示函数 显示时间 if(a1==1){if(a2==1){if(a3==1){if(a4==1)
{ weiduan(1,10);delay(5);weiduan(3,10);delay(5);weiduan(5,10);delay(5); }}}}if(a1==0){delay(100);if(a1==0){shezhi();}}if(a2==0){delay(100);if(a2==0){naozhong();}}//调用闹钟设置函数if(a5==0){delay(100);{if(a5==0){while(1)
{if(q1==0){q1=1;break;}else{q1=0;break;}}while(a5==0);delay(100);}}}if(a2==0){delay(100);if(a2==0){naozhong();} }if(q1==1){weiduan(6,0);delay(20);if(fen==e2)
{if(shi==e1){laba=0;}}if(fen!=e2){laba=1;} }else{laba=1;}}}//...................................................................void naozhong(){while(1){ ss=e1/10;gs=e1%10; sf=e2/10;gf=e2%10; sm=e3/10;gm=e3%10;delay(10);weiduan(0,ss);delay(10);weiduan(1,gs);delay(10);weiduan(2,sf);delay(10); weiduan(3,gf);delay(10);weiduan(4,sm);delay(10);weiduan(5,gm);delay(10);if(a1==0){delay(100);if(a1==0){while(a1==0);delay(20);break;}}if(a2==0){delay(100);while(a2==0);delay(20);s1++;}if(s1==3){s1=0;}if(s1==1){weiduan(0,10);delay(5);weiduan(1,10);delay(5);if(a3==0){delay(20);if(a3==0){e1++;}while(a3==0);delay(100);}if(a4==0){delay(20);if(a4==0){e1--;}while(a4==0);delay(100);}}if(s1==2){weiduan(2,10);delay(5);weiduan(3,10);delay(5);if(a3==0){delay(20);if(a3==0){e2++;}while(a3==0);delay(100);}if(a4==0){delay(20);if(a4==0){e2--;}while(a4==0);delay(100);}}if(s1==0){weiduan(4,10);delay(5);weiduan(5,10);delay(5);if(a3==0){delay(20);if(a3==0){e3++;}while(a3==0);delay(100);}if(a4==0){delay(20);if(a4==0){e3--;}while(a4==0);delay(100);}}}}//.........................................................void shezhi()//时间设置函数{while(1){ ss=shi/10;gs=shi%10; sf=fen/10;gf=fen%10; sm=miao/10;gm=miao%10;shijian();if(a2==0){delay(100);if(a2==0){while(a2==0);delay(20);break;}}if(a1==0){delay(100);while(a1==0);delay(20);s1++;}if(s1==3){s1=0;}if(s1==1){weiduan(0,10);delay(5);weiduan(1,10);delay(5);if(a3==0){delay(20);if(a3==0){shi++;}while(a3==0);delay(100);}if(a4==0){delay(20);if(a4==0){shi--;}while(a4==0);delay(100);}}if(s1==2){weiduan(2,10);delay(5);weiduan(3,10);delay(5);if(a3==0){delay(20);if(a3==0){fen++;}while(a3==0);delay(100);}if(a4==0){delay(20);if(a4==0){fen--;}while(a4==0);delay(100);}}if(s1==0){weiduan(4,10);delay(5);weiduan(5,10);delay(5);if(a3==0){delay(20);if(a3==0){miao++;}while(a3==0);delay(100);}if(a4==0){delay(20);if(a4==0){miao--;}while(a4==0);delay(100);}}}}//...................................................................void zhongduan() interrupt 1 //定时器中断函数体{ TH0=(65535-40400)/256;TL0=(65535-40400)%256;if(e3>=60)//判断秒等于或超过60{e2++; //分钟加1e3=0;} //秒数清零if(e2>=60) //判断分钟等于或超过60{e1++; //小时加1e2=0;} //分钟数清零if(e1>=24) //判断小时等于或大于24{e1=0;} //小时数 清零d0++;//累加数shu(); //调用时间最大值限制函数} //...............................................................void delay(uchar d1)//延时函数{uchar t0,t1;for(t0=d1;t0>0;t0--)for(t1=110;t1>0;t1--);}//.................................................................void weiduan(uchar z,uchar x) //位段选择函数{ P1=num[x];dua=1;dua=0;P1=wes[z];}//.....................................................................................void shijian()//动态扫描时间显示函数 带延时{chushi();//调用时间初始化函数 delay(10);weiduan(0,ss);delay(10);weiduan(1,gs);delay(10);weiduan(2,sf);delay(10); weiduan(3,gf);delay(10);weiduan(4,sm);delay(10);weiduan(5,gm);delay(10);}//............................................................void shu() //时间最大限制函数体{ if(d0>=98) //判断定时器进入 多少次{d0=0; //清除累加数miao++;} //秒数自+if(miao>=60)//判断秒等于或超过60{fen++; //分钟加1miao=0;} //秒数清零if(fen>=60) //判断分钟等于或超过60{shi++; //小时加1fen=0;} //分钟数清零if(shi>=24) //判断小时等于或大于24{shi=0;} //小时数 清零}//...................................................................void chushi() //时间初始化{ ss=shi/10;gs=shi%10; sf=fen/10;gf=fen%10; sm=miao/10;gm=miao%10;}//.............................................................
- 交流稳压电源模拟采样stc单片机程序(12-02)
- STC单片机内部EEPROM程序(12-02)
- STC单片机 EEPROM/IAP 功能测试程序演示(12-01)
- stc单片机IO配置与PWM(12-01)
- STC单片机I/O口控制程序(两个不同的跑马灯效果)(12-01)
- STC单片机实现水滴效果程序(12-01)