Matrix Keypad + serial transmission

Test 15. Matrix Keypad + serial transmission

Keypads play important role in a small embedded system where human interaction or human input is needed. All we have to do is connect the rows and columns to a port of microcontroller and program the controller to read the input.

We make the rows as i/p and we drive the columns making them o/p, this whole procedure of reading the keyboard is called scanning.

A 3 x 4 matrix keypad is used for data entry. The 12 push switches are connected to seven lines of port A, as shown in figure 36.

Interfacing PIC Microcontrollers to Peripherial Devices-0372

Interfacing PIC Microcontrollers to Peripherial Devices-0373Interfacing PIC Microcontrollers to Peripherial Devices-0374Interfacing PIC Microcontrollers to Peripherial Devices-0375Interfacing PIC Microcontrollers to Peripherial Devices-0376Interfacing PIC Microcontrollers to Peripherial Devices-0377Interfacing PIC Microcontrollers to Peripherial Devices-0378Interfacing PIC Microcontrollers to Peripherial Devices-0379Interfacing PIC Microcontrollers to Peripherial Devices-0380Interfacing PIC Microcontrollers to Peripherial Devices-0381Interfacing PIC Microcontrollers to Peripherial Devices-0382Interfacing PIC Microcontrollers to Peripherial Devices-0383Interfacing PIC Microcontrollers to Peripherial Devices-0384Interfacing PIC Microcontrollers to Peripherial Devices-0385Interfacing PIC Microcontrollers to Peripherial Devices-0386Interfacing PIC Microcontrollers to Peripherial Devices-0387Interfacing PIC Microcontrollers to Peripherial Devices-0388Interfacing PIC Microcontrollers to Peripherial Devices-0389

Program description

Interrupt Service Routine has not been used in the program.

The three columns of the keypad are connected to three of the output signals from the PIC. The four rows of the keypad are connected to four of the input signals to the PIC. If no key is pressed there is no electrical contact between the rows and the columns. The PIC detects which key is pressed by ‘scanning’ the keypad.

First the PIC makes the column 1 current column and sets the signal going to Col- umn 1 low (a digital ‘0’). All the other Columns are made high (a digital ‘1’). Then it tests the input signals coming from each Row in turn. If any of the Row signals is low, this means that the corresponding key in Column 1 has been pressed. Current column number is stored to the variable cur_col.

Interrupt Service Routine has not been used in the program. During the initializa- tion phase the variable cur_col is cleared:

Interfacing PIC Microcontrollers to Peripherial Devices-0390

Interfacing PIC Microcontrollers to Peripherial Devices-0391

Now if we know valid keys, they have to be translated into ASCII codes. This task carries out the routine key_xlate. The lookup tables are built with the respective values for each column and each row. The lowest ASCII code is for the character

# (ASCII code 35)In lookup tables we assign 0 for the # character and starting with 0 we successively assign next numbers for next characters. Therefore after finishing this procedure to each value we have to add 35.

Interfacing PIC Microcontrollers to Peripherial Devices-0392

Finaly the found ASCII codes are sent to LCD for displaying and in parallel for transmission to terminal window on PC.

Leave a comment

Your email address will not be published. Required fields are marked *