我想達成的功能如下
當P1^0 低電平時 開始計時
當P1^0高電平時 停止計時,數碼管顯示計時時間至小數第一位
電路如圖片,程式如下 ,想請問 問題出在哪
#include<reg51.h>
char Tab[ ]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
char Tab2[ ]={0x40,0x79,0x24,0x30,0x19,0x12,0x02,0x78,0x00,0x10};
char
time;
char time1;
char time2;
char time3;
char count;
sbit S1=P1^0;
void delay(void)
{ unsigned char j;
for(j=0;j<200;j++);
}
void Display1(char dat)
{ time1=dat/1000;
dat=dat%1000;
time2=dat/100;
dat=dat%100;
time3=dat/10;
P3=0x9f;
P0=Tab[time1];
delay();
P3=0x5f;
P0=Tab2[time2];
delay();
P3=0x3f;
P0=Tab[time3];
delay();
}
void main(void)
{ EA=1;
ET0=1;
TMOD=0x01;
TH0=(65536-9217)/256;
TL0=(65536-9217)%256;
time=1234;
time1=0;
time2=0;
time3=0;
count=0;
P1=0xff;
while(1)
{ Display1(time);
if(S1==0)
{ TR0=1;
if(S1==1)
{ TR0=0;
if(count>9990)
count=9990;
time=count;
count=0;
}
}
}
}
void Time0(void) interrupt 1 using 0
{ TH0=(65536-9217)/256;
TL0=(65536-9217)%256;
count++;
}
-
一周热门 更多>