📄 4-2.c
字号:
#include<reg52.h>
#include<intrins.h>
#define uchar unsigned char
#define ul unsigned long
ul n;
sbit dula=P2^6;
sbit wela=P2^7;
sbit c_led=P2^5;
sbit beep=P2^3;
uchar led=0xfe;
uchar count_0,count_1,s;
uchar code tabledu[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71};
uchar code tabledu_0[]={
0xbf,0x86,0xdb,0xcf,
0xe6,0xed,0xfd,0x87,
0xff,0xef,0xf7,0xfc,
0xb9,0xde,0xf9,0xf1};
uchar code tablewe[]={
0x01,0x02,0x04,0x08,
0x10,0x20
};
void display(uchar,uchar,uchar,uchar,uchar,uchar);
void led_beep();
void delay(uchar);
void main()
{EA=1;
ET1=1;
ET0=1;
TMOD=0X11;
TH1=(65536-10000)/256;
TL1=(65536-10000)%256;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
n=765432;
TR1=1;
while(1)
{
//------n decline and display the num;
if(count_1==1)
{count_1=0;
n--;
}
display(n/100000,n%100000/10000,n%10000/1000,n%1000/100,n%100/10,n%10);
//------led shine
if(n<=764987&&TR0==0) TR0=1; // (&&TR0==0)can make this order run one time
if(count_0==20)
{
s=1;
count_0=0;
led=_crol_(led,1);
}
if(s==1) {led_beep() ;s=0; } // if count 0 interrupt one time ,then change the led;
} //while
}//main
void tim1() interrupt 3
{
TH1=(65536-10000)/256;
TL1=(65536-10000)%256;
count_1++;
}
void tim0() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
count_0++;
}
void display(uchar w1,uchar w2,uchar w3,uchar w4,uchar w5,uchar w6)
{
P0=0x00;
wela=1;
wela=0;
P0=~tabledu[w1];
dula=1;
dula=0;
P0=tablewe[0];
wela=1;
wela=0;
delay(1);
//-------------------
P0=0x00;
wela=1;
wela=0;
P0=~tabledu[w2];
dula=1;
dula=0;
P0=tablewe[1];
wela=1;
wela=0;
delay(1);
//-------------------
P0=0x00;
wela=1;
wela=0;
P0=~tabledu[w3];
dula=1;
dula=0;
P0=tablewe[2];
wela=1;
wela=0;
delay(1);
//-------------------
P0=0x00;
wela=1;
wela=0;
P0=~tabledu_0[w4]; // the fourth bit has the dot;
dula=1;
dula=0;
P0=tablewe[3];
wela=1;
wela=0;
delay(1);
//-------------------
P0=0x00;
wela=1;
wela=0;
P0=~tabledu[w5];
dula=1;
dula=0;
P0=tablewe[4];
wela=1;
wela=0;
delay(1);
//-------------------
P0=0x00;
wela=1;
wela=0;
P0=~tabledu[w6];
dula=1;
dula=0;
P0=tablewe[5];
wela=1;
wela=0;
delay(1);
}
void led_beep()
{uchar a,b;
for(a=3;a>0;a--)
{beep=~beep;for(b=15;b>0;b--);}
P1=led;
c_led=1;
c_led=0;
}
void delay(uchar x)
{
uchar a,b;
for(a=x;a>0;a--)
for(b=255;b>0;b--);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -