?? 1263.c
字號:
/*用動態掃描方法和定時器在數碼管的前三位顯示出秒表,
精確到%1秒,即后兩位顯示%1秒,一直顯循環下去。*/
#include<reg52.h>
#define uc unsigned char
sbit duans=P2^6;
sbit weis=P2^7;
uc count,i,j;
unsigned int num;
uc code table[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71};
uc code table1[]={
0xbf,0x86,0xdb,0xcf,
0xe6,0xed,0xfd,0x87,
0xff,0xef};
display(uc,uc,uc);
delay(uc);
void main()
{
EA=1;
ET1=1;
TMOD=0x10;
TH1=(65536-5000)/256;
TL1=(65536-5000)%256;
TR1=1;
while(1)
{
if(count==2)//控制數字變化的速度
{
count=0;
if(num==1000)
num=0;
num++;
}
display(num/100,num%100/10,num%100%10);
}
}
void time1() interrupt 3 using 1
{
TH1=(65536-5000)/256;
TL1=(65536-5000)%256;
count++;
}
display(uc bai,uc shi,uc ge)
{
P0=0xff;//消除余輝
weis=1;
weis=0;
P0=table1[bai];
duans=1;
duans=0;
P0=0xfe;
weis=1;
weis=0;
delay(1);//控制動態掃描的時間
P0=0xff;
weis=1;
weis=0;
P0=table[shi];
duans=1;
duans=0;
P0=0xfd;
weis=1;
weis=0;
delay(1);
P0=0xff;
weis=1;
weis=0;
P0=table[ge];
duans=1;
duans=0;
P0=0xfb;
weis=1;
weis=0;
delay(1);
}
delay(uc x)
{
for(i=20;i>0;i--)
for(j=x;j>0;j--);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -