8位秒表设计
支持 1 ;复位 2 ;暂停 3 ;继续
16号引脚 接的晶振button 按下开始计时 再次按下停止计时 在次按下接着上次计时
15号引脚 接的晶振button 按下结束计时 再次按下复位
下边是整体效果图↓↓↓↓↓↓↓↓↓↓↓①
89c51单片机引脚接线图如下↓↓↓↓↓↓↓↓↓②
数码管显示器↓↓↓↓↓↓↓↓↓↓③
keil写的程序 C语言编写的 自己生成 .hex格式文件
[size=13.3333px] [size=13.3333px]感谢大家的支持- #include <reg51.h>
- #define uchar unsigned char
- sbit start=P3^6;
- sbit stop=P3^5;
- uchar code dulatab[]={0x3f,0x06,0x5b,0x4f,0x66,
- 0x6d,0x7d,0x07,0x7f,0x6f,0x40};
- uchar code welatab[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};//位控制字
- uchar msec,sec,min;
- void delay(uchar time)
- {
- uchar i,j;
- for(i=0;i<time;i++)
- {
- for(j=0;j<110;j++)
- ;
- }
- }
- void writeled(uchar num,uchar addr)
- {
- P2=0xff;
- P0=dulatab[num];
- P2=welatab[addr];
- delay(4);
- }
- void display(uchar msec,uchar sec,uchar min)
- {
- uchar msech,msecl,sech,secl,minh,minl;
- msech=msec/10;
- msecl=msec%10;
- sech=sec/10;
- secl=sec%10;
- minh=min/10;
- minl=min%10;
- writeled(minh,0);
- writeled(minl,1);
- writeled(10,2);
- writeled(sech,3);
- writeled(secl,4);
- writeled(10,5);
- writeled(msech,6);
- writeled(msecl,7);
- }
- void init()
- {
- TMOD=0x10;
- TH1=0xd8;
- TL1=0xf0;
- // TR1=1;
- EA=1;
- ET1=1;
- }
- void keyscan()
- {
- if(start==0)
- {
- delay(2);
- if(start==0)
- {
- TR1=~TR1;
- while(start==0)
- {
- display(msec,sec,min);
- }
- }
- }
- if(stop==0&&TR1==0)
- {
- delay(2);
- if(stop==0)
- {
- msec=0;
- sec=0;
- min=0;
- while(stop==0)
- {
- display(msec,sec,min);
- }
- }
- }
- }
- void main()
- {
- init();
- while(1)
- {
- display(msec,sec,min);
- keyscan();
- }
- }
- void timer1() interrupt 3
- {
- TH1=0xd8;
- TL1=0xf0;
- msec++;
- if(msec==100)
- {
- msec=0;
- sec++;
- if(sec==60)
- {
- sec=0;
- min++;
- if(min==60)
- {
- min=0;
- }
- }
- }
- }
复制代码
|