Home > other >  Keyboard input data available in the serial communication between the two machine, and by the double
Keyboard input data available in the serial communication between the two machine, and by the double

Time:09-27

Don't understand how to write is true, please give directions
#include
# define uchar unsigned char
# define uint unsigned int
Uchar code KEY_TABLE []={xde 0 xee, 0, 0 xbe, 0 x7e, 0 xed, 0 XDD, 0 XBD, 0 x7d, 0 xeb, 0 XDB, 0 XBB, 0 x7b, 0 xe7, 0 xd7, 0 xb7, 0 x77};//button key value table
Uchar code TABLE []={x5b x3f 0, 0 x06, 0, 0, x4f x66 0, 0 x6d, 0 x7d, 0 x07, 0 x7f, 0 x6f, 0 x77, 0 x7c, 0 x39, 0 x5e, 0 x79, 0 x71};//total Yin
//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Void delayl () {
Uint k, I, j;
For (k=1; K> 0; K -)
For (I=350; i> 0; I -)
For (j=2; J> 0; J -);
}//light digital tube delay
Void delay2 ()
{
Uint n=10000; While (n -);
}//removing jitter
//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Void UART interrupt ()
4{
Uchar temp.
while(! RI);
RI=0;//remove interrupt flag
Temp=SBUF;
P0=0 x01; P1=TABLE [10] temp %;//display received data
Delay1 ();
P0=0 x02; P1=TABLE/temp/10];//display the data received delay1 ();
//light digital tube, display the key value
while(! TI);
TI=0;//remove interrupt flag
}
//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Void main ()
{
Uchar temp, key, I, num;
TMOD=0 x20;//timer 1 as baud rate generator
SCON=0 x50;
TH1=0 XFD;//9600 baud rate
TL1=0 XFD;
TR1=1; EA=1;
ES=1;
While (1)
{
The P2=0 xf0;//behavior zero, as 1, read the column value if (P2!=0 xf0)//judge whether the keyboard is pressed {delay2 ();//damping the if (P2!=0 xf0)//if the if statement is still true, then can be determined with the keyboard is pressed {temp=P2;//store the column read in P2=0 x0f;//as zero, act 1, read the row value key=temp | P2. Comprehensive,//the row, column value is assigned to the key for (I=0; i<16. I++) if (key==KEY_TABLE [I])//read the key value table, determine the read button value {num=I; break; } SBUF=num; while(! TI); }}

}}
  • Related