第3个回答 2010-10-23
#include<at89x51.h>
#define uchar unsigned char
uchar num=12;
uchar code tab[10]={
0xC0,/*0*/
0xF9,/*1*/
0xA4,/*2*/
0xB0,/*3*/
0x99,/*4*/
0x92,/*5*/
0x82,/*6*/
0xF8,/*7*/
0x80,/*8*/
0x90,/*9*/
};
void delayms(uchar);
void display(void);
void detectkey() ;
void main()
{
while(1)
{
display();
detectkey();
}
}
void display()
{
P2_1=0;
P0=tab[num%10];
delayms(1);
P2_1=1;
P2_0=0;
P0=tab[num/10];
delayms(1);
P2_0=1;
}
void detectkey()
{
if(P3_7==0)
{
num++; P2_6=0;
// num%=100;//num=num%100
if(num==100) num=0 ;
while(P3_7==0) display();
P2_6=1;
}
if(!P3_6)
{
P2_6=!P2_6; P1_0=!P1_0;
while(P3_6==0) display(); //按键释放过程
;
}
}
/*************************
延时处理程序
**************************/
void delayms(uchar no)
{
uchar i,j;
for(i=0;i<no;i++)
{
for(j=0;j<164;j++); //3微秒
for(j=0;j<164;j++);
}
}