0-99S的秒表计时器程序与调试

设计要求:

1.设计一个秒表/计时器系统,显示时间为00.00~99.99秒,个位每秒自动加一。

2.设计一个按键,一上电数码管显示四个0,按一下按键秒表开始计时,按第二下秒表停止计时,保持数码管显示的值,按第三下秒表归零。 一.程序代码

#include #include #define uchar unsigned char #define uint unsigned int sbit SB0=P3^0; sbit SB1=P3^1; sbit SB2=P3^2; uchar code

smgduan[17]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f, 0x00,0x80};

uchar Xian[]={10,10,10,10,10,10,10,10,}; uint Time=0; bit ST=0;

void delayms(uint x) { uchar i;

while(x--)for(i=0;i<125;i++);}

void main() {

TMOD=0x11;

TH0=(65536-2000)>>8; TL0=(65536-2000)&0xff; TH1=(65536-10000)>>8; TL1=(65536-10000)&0xff;

}

TR1=1; ET1=1; TR0=1; ET0=1; EA=1; while(1) { }

if(SB0==0) {ST=1;} if(SB1==0) {ST=0;} if(SB2==0) { ST=0;

Time=0;}

void ET_1() interrupt 1 { }

static uchar j=0; static uchar i=7; TH0=(65536-2000)>>8; TL0=(65536-2000)&0xff; P0=0x00; P2=j<<2|0x03; P0=smgduan[Xian[i]]; j++; i--;

if(j==8){j=0;i=7;}

void ET_3() interrupt 3 { }

TH1=(65536-10000)>>8; TL1=(65536-10000)&0xff; if(ST) { }

Xian[0]=Time/1000; Xian[1]=Time/100; Xian[2]=11; Xian[3]=Time/10; Xian[4]=Time;

Time++; if(Time==9999) {ST=0;}

二.仿真调试图

1.原理图

联系客服:779662525#qq.com(#替换为@) 苏ICP备20003344号-4