急求!单片机99秒表课程设计,回答的好追加!

老师要我们课程设计,我们学的不多,单片机控制两个数码管显示的就行,要全点,最好是c语言的程序

#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int

uchar code table[10] = {0x03, 0x9f, 0x25, 0x0d, 0x99, 0x49, 0x41, 0x1f, 0x01, 0x09};
//数码管显示代码
uchar num,aa;

void delay()
{
uint x,y;
for(x=20;x>0;x--)
for(y=30;y>0;y--);
}

void unit() //中断开启条件
{
num=0;
TMOD=0x01;
TL0=(65536-50000)/256;
TH0=(65536-50000)%256;
TR0=1;
ET0=1;
EA=1;
}

void display()
{

P0=table[num%10]; //动态显示个位
P2=0x01;
delay();

P0=table[num/10]; //动态显示十位
P2=0x02;
delay();

}

void main()
{
unit();
while(1)
{
display();
}
}

void time0() interrupt 1//开启中断
{
TL0=(65536-50000)/256;
TH0=(65536-50000)%256;
aa++;
if(aa==20)//动态显示精确到1秒
num++;
if(num==100)
num=0;
}

P0口控制段选 P2口控制位选 希望能帮助到你
温馨提示:答案为网友推荐,仅供参考
第1个回答  2009-11-21
//===============================
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
uchar int_cishu, shi, ge;
uchar code duan_table[] = {0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f, 0x77, 0x7c, 0x39, 0x5e, 0x79, 0x71}; //共阴段码
//-------------------------------
void delayms(uint i) //延时
{
uint j;
for(; i > 0; i--)
for(j = 100; j > 0; j--);
}
//-------------------------------
void T0_time() interrupt 1 //T0中断函数
{
TH0 = (65536-50000)/256; //初值, 定时50ms @ 12MHz
TL0 = (65536-50000)%256;
int_cishu++; //中断次数加一
if(int_cishu == 20) { //到了20次,1秒
int_cishu = 0;
ge++;
if(ge == 10) { //到了10
ge = 0;
shi++;
if(shi == 10) shi = 0; //到了10
}
}
}
//-------------------------------
void xian_shi(uchar x, uchar y) //显示
{
//P0、P2口,各自外接一个共阴LED数码显示器
P0 = duan_table[x]; //输出十位段码
delayms(2);
P2 = duan_table[y]; //输出个位段码
delayms(2);
}
//-------------------------------
void init(void) //初始化
{
TMOD = 0x01; //定时器0 工作方式1
TH0 = (65536-50000)/256; //初值, 定时50ms @ 12MHz
TL0 = (65536-50000)%256;
TR0 = 1; //T0启动
ET0 = 1; //开T0中断
EA = 1; //开总中断
}
//-------------------------------
void main() //主函数
{
init();
while(1) { //无尽循环
xian_shi(shi, ge); //显示, 等待中断
}
}
//===============================