Decoding what key is pressed Step 1: Row

Download Report

Transcript Decoding what key is pressed Step 1: Row

Decoding and Using a
4x4 Keyboard
1
Mark Neil - Microprocessor Course
Example Product: Signal Generator
2
 A Signal Generator should be programmable.
 A user can use the the LCD display and the keyboard
to change the:




Frequency scale
Amplitude scale
Offset on/off etc.
Waveform shape (Square, Sinusoidal, Triangle..)
 Analog control given by potentiometer
 Analog signal output by using a Digital to Analog
Converter (DAC)
Mark Neil - Microprocessor Course
The Keyboard
3
By Pressing a button you
connect one of the row
lines to one of the column lines.
8 lines corresponding to
4 rows and 4 columns
Mark Neil - Microprocessor Course
The PCB of the Key-Board
4
From this picture you
Can see that the keyboard is
all PASSIVE: No
ICs no Transistors
The buttons simply
connect one row with
one column!
Mark Neil - Microprocessor Course
5
Decoding what
key is pressed
Step 1: Row
We can provide power
to the four rows, and
readout the data
We write 0 to all
columns
In the example on the
right (the 5 is pressed)
we will see a 0 on row 2
and 1 on the rest of the
rows
We then have to
determine which
column has been
pressed
Mark Neil - Microprocessor Course
6
Step 2:Reading
the Column
If instead of providing
power to the rows, we
provide power to the
columns we can
determine which
column has a key
pressed
We write 0 to all the
rows
In this case we will read
0 on column 1 and 1 on
the other rows
Hence we know that the
‘5’ was pressed as row 2
and col 1 have a key
pressed
Mark Neil - Microprocessor Course
Pull-up Resistors on ATmeag128 Ports
There are pull-up resistors present on-board. Which allow us
7
to put power on the PORT pins. These need to be enabled by
writing high levels to input pins.
DDRx :
Direction Reg.
PORTx :
OUTPUT
Register
PINx : INPUT
(no Register)
Mark Neil - Microprocessor Course
each pin in
PORTx is
independent!
Reading the Keypad with the ATMega128
8
PORTE bits 0-3
Inputs
We will use PORTE for both
Reading the pins and providing the
Power. This example is the initial
configuration to read the row
Mark Neil - Microprocessor Course
PORTE bits 4-7
Outputs
Task Plan - Steps
9
 Enable the pull-up resistors on bits 0-3 of PORTE and
connect the 4 pins of the keyboard. Configure these pins as
inputs, the 4 lines will be held high by the pull-up resistors.
 Connect the rest of keyboard to pins 4-7 of PORTE and
configure them as outputs.
 Write a program that drives the output bits (4-7) of PORTE
low all at once
 read the 4 PORTE input pins (0-3).

Determine which row has a key pressed
 Now configure bits 0-3 as outputs and bits 4-7 as inputs
 Determine which column has a key pressed
 Determine which key has been pressed
 Echo the PORTE input to PORTB to use the LEDs to do a
quick check of the keyboard. [also output to LCD.]
Mark Neil - Microprocessor Course
How to configure PORTE for Step 1
10
 To configure PORTE 4-7 as outputs and PORTE 0-3
as inputs

set DDRE:$F0
 Set the PORT REGISTERS in such a way so that the
inputs have pull up resistors and the outputs drive
low

set PORTE:$0F
 Be careful as it may take time for the voltage on your
output pins to settle

Use delays, check what is happening with your oscilloscope
Mark Neil - Microprocessor Course
Task
11
 Write a routine that decodes the key on the 4x4 Keyboard
and tells you what key was pressed on the LCD display
 We need a reliable setup where the ATmega128
interprets relatively quickly any key pressed on the
keyboard .
 Notice that the microprocessor is faster than your finger
and can ‘see’ the bouncing up and down that happens
when you press the a button of the keyboard.


Write a routine which reliably inputs a key press.
Write a routine which reliably inputs a string of key presses
Mark Neil - Microprocessor Course