关于89c52用c编的一个程序。中途不回了。望指导!!
我是想再安k1键以后秒表继续计数。但可以读出一个数来。通过按k2键在以后能显示在数码管上。望望高手帮忙!!!!
#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
sbit led1=P1^7;
uchar led_discode[11]={0xc0,0xf9,0xa4,0xb0,0x99,
0x92,0x82,0xf8,0x80,0x90,0xff};
uint num,k1num;
sbit xsd=P0^7;
uchar qian_bit,bai_bit,shi_bit,ge_bit;
sbit k1=P1^0;
sbit k2=P1^1;
void delay_ms(unsigned int ms) //1ms延时
{
uchar a;
while(ms--)
for(a=123;a>0;a--);
}
void nint() //初始化
{
TMOD = 0x01;
TH0 =(65536-10000)/256;
TL0 =(65536-10000)%256;
EA = 1;
ET0 = 1;
}
void led_display( )
{
P0=led_discode[qian_bit]; //显示千位
P3=0Xe0;
delay_ms(1);
P3=0Xff;
P0=led_discode[bai_bit]; //显示百位
P3=0Xd0;
xsd=0;
delay_ms(1);
P3=0Xff;
P0=led_discode[shi_bit]; //显示十位
P3=0X7f;
delay_ms(1);
P3=0Xff;
P0=led_discode[ge_bit]; //显示个位
P3=0Xbf;
delay_ms(1);
P3=0Xff;
}
void keyscan()
{
if(k1==0)
{
delay_ms(1);
if(k1==0)
{
while(!k1);
k1num++;
if(k1num==1)
{
TR0 = 1;
}
if(k1num==2)
{
if(k2==0)
{
delay_ms(1);
if(k2==0)
{
while(!k2);
}
}
// TR0=0;
}
}
}
}
void main()
{
nint();
while(1)
{
uint i;
for(i=0;i<30;i++)
{
keyscan();
led_display();
}
}
}
void Timer0Interrupt(void) interrupt 1
{
TH0 =(65536-10000)/256;
TL0 =(65536-10000)%256;
num++;
if(num==1)
{
num=0;
ge_bit++;
if(ge_bit==10)
{
ge_bit=0;
shi_bit++;
if(shi_bit==10)
{
shi_bit=0;
bai_bit++;
if(bai_bit==10)
{
bai_bit=0;
qian_bit++;
if(qian_bit==6)
{
qian_bit=0;
}
}
}
}
}
}