#include
# define uchar unsigned char
# define uint unsigned int
Float fosc=33000000;
Uchar duanma1 []={xa4 xc0 0, 0 xf9, 0, 0 xb0, 0 x99, 0 x92, 0 x82, 0 xf8, 0 x80, 0 x90};//with no decimal point total anode segment code
Uchar duanma2 []={x79 0 x40, 0, 0 x24, 0 x30, 0 x19, x12, 0, 0 x02 x78 0, 0 x00 to 0 x10};//with a decimal point, a total of anode segment code
Uchar weima []={0 x01, 0 x02, 0 x10, 0 x20};
P1 sbit KEY1=^ 0;
P1 sbit KEY2=^ 1;
Sbit KEY3=p ^ 2;
P1 sbit KEY4=^ 3;
Sbit OUT=P3 ^ 0;
Sbit OUTBAR=P3 ^ 1;
Sbit P3_2=P3 ^ 2;
Uchar ZKB;
Uint freq.
Uint TIMER0_L TIMER0_H, TIMER1_L TIMER1_H;
Void delay (uchar n)
{
Uchar I;
While (n -)
{the for (I=255; I> 0; I -)
{}
}}
Void chushihua (void)
{
P1=0 x0f;
Freq=5000;
ZKB=50;
P3_2=1;
TIMER0_L=0 xda;
XFD TIMER0_H=0;
Xed TIMER1_L=0;
TIMER1_H=0 xfe;
TL0=0 xda;
XFD TH0=0;
TL1=0 xed;
TH1=0 xfe;
TMOD=0 x11;
IT0=1;
EX0=1;
ET0=1;
ET1=1;
EA=1;
TR0=1;
TR1=1;
}
LED (void)
{
Uint m;
For (m=1; m<=4; M++)
{
The P2=weima [m - 1);
The switch (m)
{
Case 1: P0=duanma2 freq/1000; break;
Case 2: P0=duanma1 freq/100% 10; break;
Case 3: P0=duanma2 [0]. break;
Case 4: P0=duanma1 ZKB/10; break;
}
Delay (10);
}
}
Void main (void)
{
Chushihua ();
While (1)
{
Leds ();
}
}
Void Timer0_freq () interrupt 1
{
TL0=TIMER0_L;
TH0=TIMER0_H;
OUT=1;
OUTBAR=0;
TR1=1;
}
Void Timer1_zkb () interrupt 3
{
TL1=TIMER1_L;
TH1=TIMER1_H;
TR1=0;
OUT=0;
OUTBAR=1;
}
Void keyscan () using interrupt 0 1
{
Float TF0 TZ1;
EX0=0;
Delay (10);
If (P1!=0 x0f)
{
If (KEY1==0) freq +=500;
If (KEY2==0) freq=500;
If (freq> 9500) freq=9500;
If (freq<500) freq=500;
If (KEY3==0) ZKB +=10;
If (KEY4==0) ZKB -=10;
If (zkb> 90) ZKB=90;
If (zkb<10) ZKB=10;
TF0=(65536 - fosc/(12.0 * freq));
TZ1=(65536 - (fosc * ZKB)/(12.0 * 100 * freq));
TIMER0_H=(uint) TF0/256;
TIMER0_L=(uint) TF0%256;
TIMER1_H=(uint) TZ1/256;
TIMER1_L=(uint) TZ1%256;
}
P1=0 x0f;
EX0=1;
TR0=1;
TR1=1;
P3_2=1;
}
CodePudding user response:
First of all, don't interrupt and the interrupt can call the same function, also is the delay in your code, why you think;Second, if the LED () put the timer, and LED a delay in the (), when the delay caused by the timer interrupt service routine can't finished in regular time, his will happen to think of it,
Again, the interrupt is best not to delay, so you want to change, button scanning process the example of a large online
In the end, you this kind of c51 should be 8 bits, registers are also eight, and a lot of (uint) in your code
CodePudding user response:
What is abnormal digital tube display phenomenonWhy is an external interrupt button scanning