求查看两按键之间计时程序哪里出错
#include <iom16v.h>
#include <macros.h>
#define uchar unsigned char
#define uint unsigned int
uchar miao=0;
uchar feng=0;
uchar shi=0;
#pragma interrupt_handler kiao:9
#pragma data:code
const table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d, 0x07,
0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
void delay(uint ms)
{
uint i,j;
for(i=0;i<ms;i++)
{
for(j=0;j<1141;j++);
}
}
void show(uchar j,uchar k)
{
PORTA|=BIT(3);
PORTB=table[j];
PORTA&=~BIT(3);
PORTB=0XFF;
PORTB&=~BIT(k);
PORTA|=BIT(4);
PORTA&=~BIT(4);
delay(1);
}
uchar key_press()
{ uchar b;
DDRD=0X0F; //输出状态
PORTD|=0X0F; //输出高电平
DDRD&=0x0f; //输入状态
b=PIND; //记录电平状态
b=b&0X0F; //查看电平状态改变了旅挥?
if(b==0x0f)
{
return 0;
}
else
{ return 1;}
}
uchar key_scan ()
{ uchar s;
delay (20);
if(key_press)
{ s=PIND; //记录电平状态
s=s&0X0F; //查看电平状态改变了旅挥?
switch(s)
{
case 0x0e:
s=0;
break;
case 0x0d:
s=1;
break;
case 0x0b:
s=2;
break;
case 0x07:
s=3;
break;
default :
s=16 ;
}
while(key_press())
return s;
}
}
void kiao()
{
if(miao==60)
{miao=0;
miao++;
feng++;
if(feng==60)
{
feng=0;
feng++;
shi++;
if(shi==25)
{
shi=0;
shi++;
}
else
{
shi++;
}
}
else
{
feng++;
}
}
else
{
miao++;
}
TCNT1H=0X85;
TCNT1L=0XED;
}
void main()
{
uchar l,j,i=0;
DDRD=0X0F;
DDRA|=0X18;
l=key_press();
if(l==1)
{
j=key_scan();
}
if(j==1)
{
i=i+j;
if(i%2)
{
TCCR1B=0X04;
TCNT1H=0X85;
TCNT1L=0XED;
TIMSK&=~BIT(2);
SREG|=BIT(7);
}
else
{
TCCR1B=0X04;
TCNT1H=0X85;
TCNT1L=0XED;
TIMSK|=BIT(2);
SREG|=BIT(7);
}
}
else
{
miao=0;
feng=0;
shi=0;
}
while(1)
{
show(miao/10,4);
show(miao%10,5);
show(feng/10,2);
show(feng%10,3);
show(shi/10,0);
show(shi%10,1);
}
} |