/*************************************** *********************************
Function: button interrupt control digital tube plus/minus display (Independent display)
Device used: stc12c5a32s2
**************************************** ********************************/
# Include "config. H"
# Define uint unsigned int
# Define uchar unsigned char
# Define ulong unsigned long
# Define signal p3_5 // initial keyboard Signal
# Define key6 p3_2 // The key6 port is the int0 Port
# Define key2 p3_3
Int num;
// Latency is about (0.001 * n) seconds.
Void delay (unsigned char N)
{
Ulong I;
Do {
I = cpuclk/1000;
While (I --);
} While (-- n! = 0 );
}
/*************************************** **********
External Interrupt 0 Function
Function: Press key6 and add a digital number.
**************************************** *********/
Void int0 () interrupt 0 // do not judge whether it is key6 press, because the key6 key causes this interruption
{
If (key6 = 0)
{
Delay (10); // delay to eliminate key Jitter
If (key6 = 0) // confirm that a key is pressed
{
Num ++;
If (Num> 9)
Num = 0;
P0 = num;
}
While (! Key6); // wait for key1 to release
Delay (10); // delay to eliminate loose Jitter
}
}
/*************************************** **********
External Interrupt 1 Function
Function: Press key2 and subtract one digit from the digital control.
**************************************** *********/
Void int1 () interrupt 2
{
If (key2 = 0)
{
Delay (10); // delay to eliminate key Jitter
If (key2 = 0) // confirm that a key is pressed
{
Num --;
If (Num <0)
Num = 9;
P0 = num;
}
While (! Key2); // wait for key1 to release
Delay (10); // delay to eliminate loose Jitter
}
}
// Initialization function of the External Interrupt
Void int_init ()
{
Ea = 1; // total disconnection
Ex0 = 1; // 0
It0 = 0; // low level trigger mode for External Interrupt 0
Ex1 = 1;
It1 = 0;
}
// Main program entry
Void main (void)
{
Int_init ();
Signal = 0; // important !! Although signal and it1 are the same address, signal must be initialized
Num = 0;
P0 = num;
For (;;){
}
}
External Interrupt procedure design steps:
1. Total disconnection
2. Out-of-Service Interruption
3. Set the External Interrupt trigger mode
4. interrupt handling program