自己用课余时间写的一个小程序,现在贴出来大家看了不要笑话用 PROTEUS仿真已经通过;我用的时两位一体的数码管动态显示的,用的是查询方式来进行1秒钟计时。本想在网上看一下别人的99马表是怎样写的没有想到的时大家贴出来的都是一个程序而且用的是静态显示觉得浪费了IO口就写了一个动态的附带仿真电路图https://static.assets-stash.eet-china.com/album/old-resources/2009/4/11/709f9ca6-4c88-410d-a927-9312be62c2a1.rar看过下过的顶一下啦!!
#include<reg51.h>
#define uchar unsigned char
#define uint unsigned int
#define dateport P0
#define bitport P2
uchar dispcode[]={0x3f,0x06,0x5b,0x4f,0x66,
0x6d,0x7d,0x07,0x7f,0x6f,0x77,
0x7c,0x39,0x5e,0x79,0x71,0x00};
uchar code t[]={0xfd,0xfe};
sbit sw="P3"^5;
uchar second,i,key;
uint count;
void delay(uchar x)
{
while(x--);
}
void main()
{
TMOD="0X02"; //设置定时器工作方式
// ET0=0;
// EA="0";
second="0";
i="0";
key="0";
count="0";
sw="1";
dateport="dispcode"[second/10];
bitport="t";
delay(20);
bitport="0x00";
dateport="dispcode"[second%10];
bitport="t"[i+1];
delay(20);
bitport="0x00";
while(1)
{
if(sw==0)
delay(120);
if(sw==0)
{
key++;
while(sw==0);
if(key==4)
{
key="0";
}
switch(key)
{
case 1:
TH0=0X06;
TL0=0X06;
TR0=1; //启动定时器 0
break;
case 2:
TR0=0;
break;
case 3:
second=0;
break;
}
}
if(TF0) //中断标志位
{
TF0=0;
count++;
if(count==400)
{
count="0";
second++;
}
if(second==100)
{second=0;}
}
dateport=dispcode[second/10];
bitport=t[i++];
bitport=0xff;
dateport="dispcode"[second%10];
bitport="t"[i++];
bitport=0xff;
if(i==2)
i=0;
}
}
用户193823 2009-4-18 00:22
tengjingshu_112148725 2009-4-11 16:04