Industrial computers usually have standard keyboards, but for ease of operation, it is often necessary to connect a special keyboard. This example introduces the application method of connecting an industrial PC to the PS/2 bus and then connecting a self-made special keyboard.
PS/2 keyboard interface circuit for industrial computers
The design should ensure that the two keyboards work independently and cannot affect each other. Therefore, the dedicated keyboard and the standard keyboard cannot be directly connected to the PS/2 port of the industrial control PC. In view of this situation, this design uses the analog switch CD4052 and time-division multiplexing the PS/2 port of the industrial control PC to make only one keyboard valid at the same time, thereby solving the above problem. Its hardware schematic diagram is shown in the figure. Among them, the P2 port and the P1 port are used for the keyboard scanning circuit (not drawn in the figure), P0.0 is the data end, P0.1 is the clock end, and P0.2 is the analog switch selection end. Since the dedicated keyboard does not need to receive commands from the industrial control PC, the corresponding code does not need to be written in the software.
Through the software, P0.2 can be cleared to 0 after the dedicated keyboard is reset, so that the analog switch CD4052 opens the corresponding channel. At this time, the standard keyboard of the industrial control PC will start working. The standard keyboard can complete the response to the peripheral detection when the industrial control PC is just started. After reset, the dedicated keyboard keeps scanning for keys. If a key is pressed, it identifies the key and encodes it according to the pre-designed design. At the same time, it calls the sending program and sends it to the industrial PC through the PS/2 port. At this time, the analog switch closes the corresponding channel (sets P0.2 to 1), and the dedicated keyboard is connected to the clock line and data line of the PS/2 port of the industrial PC to work, but the standard keyboard is disconnected from the clock line and data line of the PS/2 by the analog switch and does not work. In this way, the dual keyboards can time-division multiplex the PS/2 port of the same industrial PC. The corresponding sending subroutine is as follows:
1 #define DATA P00 Use P0.0 as data line
2 #define CLK P01 Use P0.1 as the clock line
3 #define INHIBIT P02 Use P0.2 as the INH terminal of CD4052
4 #define PORTR P1 Use port P1 as the read port
5 #define PORTW P2 Use port P2 as the write port to implement 64 custom keys
6 void send(uchar x)/***function for send a char da-ta***/
7 {
8 float i,temp,char_temp;
9 bit flag_check=1;
10 INHIBIT=1;//disable standard keyboard
11 delay_ ms(3);
12 temp=x;
13 for(i=0;i<8;i++)//find the number of 1 in this uchar x is odd or not
14 {
15 char_temp=temp&0x01;
16 if(char_temp==0x01)
17 {
18 flag_check=!flag_check;
19 }
20 temp=temp>>1;
21 }
22 CLK=1;//send 1 to P1 then read P1
23 while (!CLK) //if CLK is low wait
24 {
25 ;
26 }
27 CLK=1;DATA=1;//send 1 to P1 then read P1
28 if(CLK==1)
29 {
30 delay_us(30);//
31 }
32 if(CLK==1&&DATA==1)//send data
33 {
34 DATA=0;//start bit 0
35 delay_us(10);
36 CLK=0;
37 delay_us(5);//
38 temp=x;
39 for(i=0;i<8;i++)//send 8 bits LSBfirst
40 {
41 CLK=1;
42 delay_us(5);
43 char_temp=temp&0x01;
44 if(char_temp==0x01)
45 {
46 DATA=1;
47 }
48 else
49 {
50 DATA=0;
51 }
52 //DATA=(bit)(temp&0x01);
53 //LSB
54 delay_us(10);
55 CLK=0;
56 delay_us(5);
57 temp=temp>>1;
58 }
59 CLK=1;//send check bit
60 delay_us(5);
61 DATA=flag_check;
62 delay_us(10);
63 CLK=0;
64 delay_us(5)
65 CLK=1;//send stop bit
66 delay_us(5);
67 DATA=1;
68 delay us10
69 CLK=0
70 delay_us(5);
71 CLK=1;
72 delay_us(30);
73 CLK=1;DATA=1;//send 1 to P1 then read P1
74 if(CLK==1&&DATA==0)
75 {
76 return; //pc is sending data to mcu, go to
77 receiving function
78 }
79 INHIBIT=0; //enable standard keyboard
80 }
Previous article:Using 51 single chip microcomputer to make a cheap box robot
Next article:HT6221 sends infrared HS0038 decoding program
- Popular Resources
- Popular amplifiers
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
- Huawei's Strategic Department Director Gai Gang: The cumulative installed base of open source Euler operating system exceeds 10 million sets
- Download from the Internet--ARM Getting Started Notes
- Learn ARM development(22)
- Learn ARM development(21)
- Learn ARM development(20)
- Learn ARM development(19)
- Learn ARM development(14)
- Learn ARM development(15)
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
- Is this true? Most people who buy Apple phones are "invisible poor people"
- As shown in the figure, which type of capacitor filtering wiring is better?
- Registration is open | TI Award Live: The industry's most accurate 3D Hall effect position sensor
- Power supply tips you must know: A small negligence can ruin EMI performance!
- What is the inverted state of the transistor and what is its function!
- IAP issue when porting from Qinheng CH32F103 to CH32V103
- Playing with Bluetooth chips on a perforated board, where is the antenna? Come and see Qinheng's 10-pin CH9141K
- Common Faults and Solutions for DC-DC Power Modules
- Design of lightning protection circuit for RS-485 in multifunctional electric energy meter
- Generator re-voltage overcurrent protection