/*****Function description: PS/2 keyboard application header file (interrupt processing) *****/
/*****Debugging platform: 51 single-chip microcomputer 11.0592M crystal *****/
/*****Author: Zheng Wen (ClimberWin) *****/
/*****Written date: October 5, 2009 *****/
/*****Version information: V1.0 *****/
/*****Modified date: *****/
/*****************************************************************/
#ifndef __C51_PS_2_H__
#define __C51_PS_2_H__
#include
#define uchar unsigned char
#define uint unsigned int
////////////////Data definition///////////////////////////////////////
sbit PS2_key_Da
sbit PS2_key_CLK =P3^3; //define PS2 Clk pin
bit PS2_flag=0; //Whether there is PS/2 key data receiving flag
bit PS2_key_UP=0, Shift=0;//Whether the PS2_key_UP is released, whether the Shift key is pressed
uchar clk_num = 0; //Interrupt count, used to determine the number of bits of received data
uchar PS2_da
uchar LCD1602_cursor = 0; //Display cursor position
///////////////Use function definition///////////////////////////////////
void PS2_decode(unsigned char PS2_Co
/////////////////Data receiving subroutine (interrupt processing)///////////////////////////////
//Keyboard protocol One frame contains 11 bits of serial protocol
//bit1 :START=0
//bit2-9: data bit DA
//bit10 : parity bit
//bit11 :STOP=1
void PS2_data_receive
{
clk_num++; //Increase the number of interrupts by 1
if ((clk_num>1) && (clk_num<10))
{
if(PS2_key_Da
{PS2_da
else //Bit 1 receives and saves
{PS2_da
}
while (!PS2_key_CLK); //Wait for PS/2CLK to be pulled high
if (clk_num > 10) //When the interrupt occurs 11 times, it means that one frame of data has been received
{
clk_num = 0; //Clear count value
PS2_flag = 1; //Turn on key value flag
EA = 0; //Turn off interrupt
}
}
///////////////////////Key value processing subroutine ////////////////////////////////////
void PS2_decode(unsigned char PS2_Co
{
uchar tab_num;
if (PS2_key_UP==0) //In the initial state
{
switch (PS2_Co
{
case 0xF0 : //When 0xF0 is received, PS2_key_UP is set to 1 to indicate the start of the break code
PS2_key_UP = 1;
break;
case 0x12: // Left SHIFT
Shift = 1;
break;
case 0x59: //Right SHIFT
Shift = 1;
break;
default:
if(!Shift) //If SHIFT is not pressed
{
for (tab_num = 0;(UnShifted[tab_num][0]!=PS2_Co
(UnShifted[tab_num][0] == PS2_Co
}
else //Press SHIFT
{
for(tab_num = 0; (Shifted[tab_num][0]!=PS2_Co
(Shifted[tab_num][0] == PS2_Co
}
break;
}
}
else //When PS2_key_UP==1, that is, the key is popped up.
{
PS2_key_UP = 0; //Clear flag
if (PS2_Code
}
PS2_flag = 0; //The identification character is processed
}
#endif
Previous article:TFT LCD screen C51 control
Next article:2.4G wireless transmitter module nRF2402 application
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Wi-Fi 8 specification is on the way: 2.4/5/6GHz triple-band operation
- Wi-Fi 8 specification is on the way: 2.4/5/6GHz triple-band operation
- Vietnam's chip packaging and testing business is growing, and supply-side fragmentation is splitting the market
- Vietnam's chip packaging and testing business is growing, and supply-side fragmentation is splitting the market
- Three steps to govern hybrid multicloud environments
- Three steps to govern hybrid multicloud environments
- Microchip Accelerates Real-Time Edge AI Deployment with NVIDIA Holoscan Platform
- Microchip Accelerates Real-Time Edge AI Deployment with NVIDIA Holoscan Platform
- Melexis launches ultra-low power automotive contactless micro-power switch chip
- Melexis launches ultra-low power automotive contactless micro-power switch chip
- Outsourcing of small brushless sensor driver
- Single-ended forward converter
- Bootloader issue of CH579
- SPI to USB CDC
- Battery Pack SOC
- Strange phenomenon of screen display and USB!
- 【Portable programmable instrument】Begin preparation for debugging
- TIOBE Programming Language Rankings April 2022
- Selection of Serial Port to WiFi Module and Serial Port to Network Port Module for Industrial Control Gateway of Internet of Things
- [Raspberry Pi Pico Review] WS2812B Snowflake Light Practice -- and IoT Communication RGB Control