Home > other >  For help! External interrupt normal response after the timer does not perform timing, consult the pr
For help! External interrupt normal response after the timer does not perform timing, consult the pr

Time:10-02

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
51 microcontroller hardware carrier: P0 mouth eight common cathode connection LED;
Written language: c language;
Objectives: 1. The timer T0T1 precise timing, 2. Destroy high four four circulation in low light, timer 0 provide timing,
3. The external interrupt 0 or 1 external interrupt response after eight leds light up one by one, after the interruption ends, timing
1 provide timing,

Notes: the interrupt program and the main program count variables may conflict, conflict if try to interrupt the
Define the timer 1 to delay procedures,

===================================================

Consult problem: under the current program, can be normal external interrupt response, but a response to the precise timing timer 1
Cannot provide timing (timing directly is not running), the use of precise timing can run normally,

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#include
# define uchar unsigned char
# define uint unsigned int
Sbit _key0=P3 ^ 2;
Sbit _key1=P3 ^ 3;

Uint count=0, count_1=0, num=0 xf0, valueINT_0, valueINT_1, n.
int i;

Int main (void)
{
Void Time0_Time1_Init ();//timer 0, 1 initialization function declaration
Void INT0_INT1_Init ();//external interrupt 0, 1 initialization function declaration
EA=1;
Time0_Time1_Init ();//timer 0, 1 initialization function call
INT0_INT1_Init ();//external interrupt 0, 1 initialization function call
_key0=1;
_key1=1;
While (1)
{
P0=num;
If (count==2)
{
Count=0;
Num=~ num;
}
}
}
//external interrupt 0, 1 initialization function
Void INT0_INT1_Init ()
{
EX0=1;
EX1=1;//IE=0 x8f;
IT0=0;
IT1=0;
}

//timer 0, 1 initialization function
Void Time0_Time1_Init ()
{
TMOD=0 x11;
ET0=1;//IE=0 x8f;
TR0=1;
TH0=(65535-46079)/256;
TL0=(65535-46079) % 256;
ET1=1;
TR1=1;
TH1=(65535-46079)/256;
TL1=(65535-46079) % 256;
}
Void _INT0_ (void) using interrupt 0 1
{
ValueINT_0=0 XFF;
I=8;
While (I!=0)
{
P0=valueINT_0;
If (count_1==5)
{
I -;
Count_1=0;
ValueINT_0=valueINT_0 & gt;> 1;
}
}
}

Void _INT1_ (void) interrupt 2 using 1
{
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
i=0;
While (1)
{
P0=valueINT_1;
If (count_1==5)
{
i++;
Count_1=0;
ValueINT_1=valueINT_1 & gt;> 1;
}
If (I==7)
break;
}
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
ValueINT_1=0 XFF;
for(i=0; I<8; I++)
{
ValueINT_1=valueINT_1 & lt; <1;
P0=valueINT_1;
For (n=0; N<30000; N++);//the precise timing
}
}
Void time0 () interrupt using 1
{
TH0=(65535-46079)/256;
TL0=(65535-46079) % 256;
Count++;
}
Void time1 () interrupt 3 using 1
{
TH1=(65535-46079)/256;
TL1=(65535-46079) % 256;
Count_1 + +;
}

CodePudding user response:

Interrupt a preemption, led to the delay time terminal execution, more serious is interrupted

CodePudding user response:

1. The void _INT1_ (void) interrupt using 1 in 2 don't use the for delay (n=0; N<30000; N++);
2. The interrupt use using the individual feels meaningless
3. The interrupt service routine to write too repetitive, it is better to let the other operations are moving into the main executive
Your logic to manage way
  • Related