/**************************
Resources used by the file
1. External interrupt 0
2. Port: P3.3, P3.4
**************************/
sbit PS2_DAT=P3^7; //Data
uchar code unshifted[][2]= //shift key not pressed decoding table
{
0x0e,'`',
0x15,'q',
0x16,'1',
0x1a,'z',
0x1b,'s',
0x1c,'a',
0x1d,'w',
0x1e,'2',
0x21,'c',
0x22,'x',
0x23,'d',
0x24,'e',
0x25,'4',
0x26,'3',
0x29,' ',
0x2a,'v',
0x2b,'f',
0x2c,'t',
0x2d,'r',
0x2e,'5',
0x31,'n',
0x32,'b',
0x33,'h',
0x34,'g',
0x35,'y',
0x36,'6',
0x39,',',
0x3a,'m',
0x3b,'j',
0x3c,'u',
0x3d,'7',
0x3e,'8',
0x41,',',
0x42,'k',
0x 43,'i',
0x44,'o',
0x45,'0',
0x46,'9',
0x49,'.',
0x4a,'/',
0x4b,'l',
0x4c,';',
0x4d,'p',
0x4e,'-',
0x52,'\'',
0x54,'[',
', 0x7a,'3 '
,
0x7b
,'
-',
0x7c,'*', 0x7d,'9', 0,0 }; uchar code shifted[ ]
[ 2
] = //shift key pressed decoding table { 0x0e ,'~', 0x15 , 'Q', 0x16 , ' ! ' , 0x1a,'Z ' , 0x1b,'S', 0x1c,'A', 0x1d,'W', 0x1e,'@', 0x21,'C', 0x22,'X', 0x23,'D', 0x24,'E', 0x25,'$', 0x26,'#', 0x29,' ', 0x2a,'V', 0x2 b,'F', 0x2c,'T', 0x2d,'R', 0x2e,'%', 0x31,'N', 0x32,'B', 0x33,'H', 0x34,'G', 0x35,'Y', 0x36,'^', 0x39,'L', 0x3a,'M', 0x3b,'J', 0x3c,'U', 0x3d,'&', 0x3e,'*', 0x41,'<', 0x42,'K', 0x43,'I', 0x44, 'O', 0x45,')', 0x46,'(', 0x49,'>', 0x4a,'?', 0x4b,'L', 0x4c,':', 0x4d,'P', 0x4e,'_ ', 0x52,'"', 0x54,'{', 0x55,'+', 0x5b,'}', 0x5d,'|', 0x61,'>', 0x69,'1', 0x6b,'4', 0x6c,'7',
0x70,'0',
0x71,'.',
0x72,'2',
0x73,'5',
0x74,'6',
0x75,'8',
0x79,'+',
0x7a,'3',
0x7b, '-',
0x7c,'*',
0x7d,'9',
0,0
};
void Decode(uchar scancode);//declare function prototype
uchar bitcount,bytecount,byte2; //edge is 0 falling edge interrupt, 1 rising edge interrupt
uchar ascii2[35],ascii[99]; //bitcount is the bit count value
//ascii is the translated ASCII code, the initial value is space
//******************************************************
//External interrupt service subfunction
//*******************************************************
void StopInt() interrupt 0
{
static uchar udata; //Declare local static variables to save scan codes
if(bitcount < 11 && bitcount > 2) //3 to 10 bits are data, start bit, check bit and stop bit are ignored
{
udata = (udata >> 1); //right shift to save data
if(PS2_DAT)
{
udata|=0x80; //store a '1'
}
}
if(--bitcount==0) //If all 11 bits are received
{
bitcount = 11; //Reset to 11-bit data
ascii[bytecount]=udata;
if(bytecount<6)bytecount++;
}
}
/*******************************************
Function name: DecodeFunction
:
Parameter: scancode--scan code to be translatedReturn
value: None
/********************************************/
void Decode(uchar scancode)
{
static uchar up=0,shift=0; //up is the pass/break code flag, shift is the shift key pressed flaguchar
i;
if (!up) //The received 11-bit data is a pass code (up is 0)
{
switch (scancode)//Start translating the scan code
{
case 0xF0: //Keyboard release flag (the following byte is a break code)
up=1; //Set up to the break code flagbreak
;
case 0x12: //Left shift key pressedshift
=1; //Set shift to the pressed flagbreak
;
case 0x59: //Right shift key pressedshift
=1; //Set shift to the pressed flagbreak
;
default:
if(!shift) //If the shift key is not pressed
{ //Look up the unshifted table, the left column in the table is the scan code, and the right column is the corresponding ASCII code
for(i=0;unshifted[i][0]!=scancode&&unshifted[i][0];i++);
if(unshifted[i][0]==scancode)
{
ascii2[3]=unshifted[i][1];
}
}
else //If the shift key is pressed
{ //Look up the shifted table
for(i=0;shifted[i][0]!=scancode&&shifted[i][0];i++);
if(shifted[i][0]==scancode)
{
ascii2[3]=shifted[i][1];
}
}
break;
}
}
else //The received 11-bit data is a broken code (up is 1)
{
up = 0; //Reset the broken code flag
switch (scancode) //Detect shift key release
{
case 0x12 : //Left shift key
shift = 0;
break;
case 0x59: //right shift key
shift = 0;
break;
default:
break;
}
}
}
Previous article:128*64 LCD screen (ST7920) C51 driver
Next article:IO port simulation SPI communication C51 program
Recommended ReadingLatest update time:2024-11-16 14:29
- Popular Resources
- Popular amplifiers
- Siemens Motion Control Technology and Engineering Applications (Tongxue, edited by Wu Xiaojun)
- MCU C language programming and Proteus simulation technology (Xu Aijun)
- 100 Examples of Microcontroller C Language Applications (with CD-ROM, 3rd Edition) (Wang Huiliang, Wang Dongfeng, Dong Guanqiang)
- Principles and Applications of Single Chip Microcomputers 3rd Edition (Zhang Yigang)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- ADI Analog Dialogue magazine, if you are interested, come and get it~
- Notes and lessons about IAR installation
- [Open Source] Bluetooth module BT401 full set of information based on Bluetooth headset chip development ultra-low cost
- EEWORLD University Hall----Live Replay: ADI's Vital Signs Monitoring Solutions in Wearable Products
- Arrow Electronics' award-winning live broadcast starts at 10:00 this morning: Intel FPGA Deep Learning Acceleration Technology
- stm32f030R8 Chinese reference material
- Recruitment: Executive Vice President of Automotive Electronics (Executive Vice President of New Energy)
- ATmega4809 Curiosity Nano Review + Unboxing and Powering on
- Sell an unused Jiuxintaike oscilloscope and get a Guwei desktop multimeter for free
- MSP430F1232 external 4M crystal oscillator cannot start