新闻中心

EEPW首页 > 嵌入式系统 > 设计应用 > 51单片机时钟秒表课程设计

51单片机时钟秒表课程设计

作者: 时间:2016-11-29 来源:网络 收藏

void Delayms(int ms)

{

while(ms)

{

unsigned char i;

ms--;

for (i=0; i<240; i++);

}

}

void display()

{

char v,c;

P3=0x11;

v=Leds[Ledc];

c=LEDTAB[v & 0x0f];

if (v&0x10) c|=0x80;

P2=c;

P3=Ledc;

Ledc++;

if (Ledc>=8) Ledc=0;

}

void readkey() //读按键

{

if(start==0) isStart = 1; //真为开始

if(stop==0) isStart = 0; //假为停止

if(key0 == 0) num_count = stu_num0; //选择曾路荣

if(key1 == 0) num_count = stu_num1;//选择张洪荣

if(key2 == 0) num_count = stu_num2;

if(key3 == 0) num_count = stu_num3;

if(key4 == 0) num_count = stu_num4;

if(key5 == 0) num_count = stu_num5;

}

void t0int() interrupt 1 //1ms定时器中断服务函数

{

TH0=(-1000)>>8;

TL0=-1000;

display();

readkey();

T1msc++;

if (isStart) //开始倒计时

{

if ((T1msc%100)==0) //满 0.1秒

{

temp--;

if(temp==-1)

{

num_count--;

temp = 10; //0.1秒恢复9

}

}

if(num_count == -1) //

{

num_count = 99;

num--;

if(num == -1) num = 99;

}

}

if (T1msc>=1000)

{

T1msc=0;

}

}

void NumToLeds()

{

Leds[1]=num/10%10;

Leds[2]=num%10;

Leds[3]=num_count/10%10;

Leds[4]=num_count%10+0x10;

Leds[5]=temp; //0.1秒显示

}

void main()

{

Delayms(10);

TMOD=0x01;

TR0=1;

ET0=1;

EA=1;

while(1)

{

NumToLeds(); //送数据

}

}


上一页 1 2 下一页

评论


技术专区

关闭