Design of PS/2 keyboard interface circuit for industrial computers

Publisher:SparklingSunLatest update time:2016-12-30 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

 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 us10 

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     }


Reference address:Design of PS/2 keyboard interface circuit for industrial computers

Previous article:Using 51 single chip microcomputer to make a cheap box robot
Next article:HT6221 sends infrared HS0038 decoding program

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号