I just learn c, please use c to modify
1. Using the matrix keyboard, in addition to the eight key additional set a reset button (unlike with reset)
2. Numerical fixed after the buzzer to press a button, only press the reset button on the next round of vies to answer first
3. Using digital tube or LCD1602 display eight-way responder numerical
4. The use of external interrupt
# include & lt; Reg52. H>
Typedef unsigned char uchar;
Typedef unsigned int uint;
# define GPIO_DIG P0
# define GPIO_KEY P1
Uchar KeyValue;
Sbit k1=P3 ^ 1;
Sbit LSA=P2 ^ 2;
Sbit LSB=P2 ^ 3;
Sbit LSC=P2 ^ 4;
Uchar code smgduan [17]={x5b x3f 0, 0 x06, 0, 0 x4f, 0 x66, 0 x6d, 0 x7d, 0 x07,
X6f 0 x7f, 0, 0 x77, 0 x7c, 0 x39, 0 x5e, 0 x79, 0 x71};
Void Int0Init ()
{
IT0=1;
EX0=1;
EA=1;
}
Void delay (uint I)
{
While (I -);
}
Void KeyDown ()
{
Char a=0;
GPIO_KEY=0 x0f;
If (GPIO_KEY!=0 x0f)
{
delay(1000);
If (GPIO_KEY!=0 x0f)
{
GPIO_KEY=0 x0f;
The switch (GPIO_KEY)
{
Case (0 x07) : KeyValue=https://bbs.csdn.net/topics/1; break;
Case (0 x0b) : KeyValue=https://bbs.csdn.net/topics/2; break;
Case (0 x0d) : KeyValue=https://bbs.csdn.net/topics/3; break;
Case (0 x0e) : KeyValue=https://bbs.csdn.net/topics/4; break;
}
GPIO_KEY=0 xf0;
The switch (GPIO_KEY)
{
Case (0 x70) : KeyValue=https://bbs.csdn.net/topics/KeyValue; break;
Case (0 xb0) : KeyValue=https://bbs.csdn.net/topics/KeyValue+4; break;
Case (0 xd0) : KeyValue=https://bbs.csdn.net/topics/KeyValue+8; break;
Case (0 xe0-0xfc) : KeyValue=https://bbs.csdn.net/topics/KeyValue+12; break;
}
While ((a<50) & amp; & (GPIO_KEY!=0 xf0))
{
delay(1000);
a++;
}
}
}
}
Void main ()
{
KeyDown ();
The switch (KeyValue)
{
Case 1: P2=0 XFD; break;
Case 2: P2=0 xfe; break;
Case 3: P2=0 XFB; break;
Case 4: P2=0 xf7; break;
Case 5: P2=0 xef; break;
Case 6: P2=0 XDF; break;
Case 7: P2=0 XBF; break;
Case 8: P2=0 x7f; break;
Default: Int0Init ();
}
LSA=0;
LSB=0;
LSC=0;
GPIO_DIG=smgduan [KeyValue];
KeyDown ();
The switch (KeyValue)
{
Case 1: P2=0 xfe; break;
Case 2: P2=0 XFD; break;
Case 3: P2=0 XFB; break;
Case 4: P2=0 xf7; break;
Case 5: P2=0 xef; break;
Case 6: P2=0 XDF; break;
Case 7: P2=0 XBF; break;
Case 8: P2=0 x7f; break;
Default: Int0Init ();
}
LSA=1;
LSB=1;
LSC=1;
}
Void Int0 () interrupt 0
{
The P2=0 XFF;
If (k1==0)
{
delay(100);
If (k1==0)
{
Uchar code RST []={0 xe4, 0 xc0, 0 xe0-0xfc, 0 xc0, 0 xe0-0xfc, 0 x32};
(* ((void (*) (void)) (RST))) ();
}
}
}
CodePudding user response:
Someone to help to solve it for me?
CodePudding user response:
When detected button can control EX0=1; Or EA=1; Reply is the control EX0=1; Or EA=1;
CodePudding user response:
When detected button can control EX0=0; Or EA=0; Reply is the control EX0=1; Or EA=1;
CodePudding user response:
reference 3 floor wise men know already should good karma response: when detected button can control EX0=0; Or EA=0; Reply is the control EX0=1; Or EA=1; This is written in this interruption or write in the main function? ('? ') CodePudding user response:
reference 4 floor qq_44992011 response: Quote: reference 3/f the wise know already should good karma response: when detected button can control EX0=0; Or EA=0; Reply is the control EX0=1; Or EA=1; This is written in this interruption or write in the main function? ('? ') Said very clearly, where a button CodePudding user response:
The first is based on your original said: 1, this program is you can't complete your function, in the main function of the process have a problem, the following main functions for a reference model for your reference, note here a while loop below, your function is not inside, so you don't know what to run again after application to local, is expected to continue to reset operation, I don't know how a specific logic, Void main (void) { The init ();//this function is executed only once after power up, While (1)//the cycle requires program has been run, { Sub1 ();//this two function as long as the MCU without electricity, will keep loop execution, Sub2 (); } } 2, see the keydown this function again, no circuit diagram, look from the program, for the first time use GPIO_KEY low four input four buttons, reoccupy GPIO_KEY high four input keys, look not to understand what is the intention, if according to your requirements, using matrix buttons, 8 IO GPIO_KEY, should use the four output, four input, can meet the requirements of your eight buttons (within 16 buttons can be), 3, didn't see you is how to connect INT0, if adopt the method of the inside of the Keydown 4 * 4 to do, so how are the four input signals into INT0? These signals are merged into an IO need to consider the influence of each other, Suggest you final solution is: 1, made output GPIO_KEY, use INT0 the IO for input, after power on, directly on the GPIO_KEY 0, INT0 need to go to pull, 2, falling edge set INT0 to interrupt, 3, open INT0 interrupts, and then enter the main loop (the while (1) loop body), 4, need to be closed in INT0 interrupt program interrupt (way interrupts or shut down), then GPIO_KEY from bit0 to bit7, in turn, 0 (0 output only one bit at a time, the other is high), after each output read INT0 IO port state, if found read back the state is 0, then press the buttons produced interrupt, then you can exit the interrupt service program, 5, tackle this button in the main loop, if it is a zero button, once again open INT0 interrupt, MCU program combined with hardware circuit is needed to do, so, write programs to consider the hardware what to do before, after completes the hardware, to consider the software again, CodePudding user response:
A similar code, to modify, there are questions to ask CodePudding user response:
Detect any button code oneself add to interrupt button, such as the if (! K0 | |! K1 | |! K2 | |! K3) CodePudding user response:
Buzzer countdown 16 road show a CodePudding user response:
the wise know already, 9/f, reference shall be good karma response: buzzer countdown 16 road show a nullnullnullnullnullnullnullnull