當前位置:編程學習大全網 - 編程軟體 - 如何用C51單片機做出以下程序 “秒表是倒計時,從100秒開始倒計時 用數碼管實時顯示當前計時值”

如何用C51單片機做出以下程序 “秒表是倒計時,從100秒開始倒計時 用數碼管實時顯示當前計時值”

假設P0 P2接數碼管,靜態驅動,程序如下:

include<reg52.h>

#define uchar unsigned char

#define uint unsigned int

uchar num=100;

uchar time=0;

//***陰數碼管七段碼

uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d, 0x07,0x7f,0x6f,0x77};

void Delay1ms(uint i) //1ms延時程序

{

uint j;

for(;i>0;i--)

{

for(j=0;j<164;j++)

{;}

}

}

void main(void )//主程序

{

TMOD=0X01;

ET0=1;

EA=1;

TH0=(65536-50000)/256;//定時50ms

TL0=(65536-50000)%256;

TR0=1;

while(1)

{

P0=table[num/10];

Delay1ms(2);

P2=table[num%10];

Delay1ms(2);

}

}

void TIMER0()interrupt 1//中斷程序

{

TH0=(65536-50000)/256;

TL0=(65536-50000)%256;

time++;

if(time==20)

{

time=0;

num--;

}

if(num==0)

{

num=100;

}

}

  • 上一篇:軟件測試工程師累
  • 下一篇:關於WoW鼠標指向宏
  • copyright 2024編程學習大全網