Docsity

MC9S12C128 Microcontroller Lab: Matrix Keypad Interface using Program-Controlled I/O - Pro, Lab Reports of Electrical and Electronics Engineering

Partial preview of the text

Download MC9S12C128 Microcontroller Lab: Matrix Keypad Interface using Program-Controlled I/O - Pro and more Lab Reports Electrical and Electronics Engineering in PDF only on Docsity!

ELEC 3040/

Lab 4

Matrix Keypad Interface

Using Program-Controlled I/O

Goals of this lab exercise

 Control a peripheral “device” with the

MC9S12C128 microcontroller

 Use parallel I/O ports to access a device

 Practice with program-controlled

input/output (I/O)

 Software controls timing of data transfers

 Next week – interrupt-driven I/O

DragonFly12 40-pin DIP pin

connections

DragonFly12 Module Schematic

Ports available on the

MC9S12C128/Dragonfly

 PORT E bits PE0,PE1,PE4,PE

 Special functions:  PE0 = XIRQ (nonmaskable interrupt request input)  PE1 = IRQ (interrupt request input)  PE4 = ECLK output  PE7 = XCLK output  General purpose I/O (default operation)  Access via PORTE  DDRE determines pin directions, EXCEPT:  PE0 & PE1 can only be inputs (DDRE bits ignored)  PE2-PE7 can be general purpose inputs or outputs

All 8 bits of PORTE available on larger packages

Ports available on the

MC9S12C128/Dragonfly

 PORT T bits 0-

 General-purpose I/O pins PT7-PT

 Access via PTT  Directions set via DDRT

 Programmable timer inputs/outputs IOC7-IOC

 Enable via timer setup registers  Default is general-purpose I/O

 Bits 0-4 can be connected to the PWM module

 Select via MODRR (0=timer*, 1 = PWM) *default connection is to timer

Ports available on the

MC9S12C128/Dragonfly

 PORT M bits 0-

 Pins for synchronous peripheral interface (SPI) #  PM5 = SCK0 (SPI clock)  PM4 = MOSI0 (master out/slave in)  PM3 = SS0 (slave select)  PM2 = MISO0 (master in/slave out)  PINS for controller area network interface (CAN) #  PM1 = TXCAN0 (CAN transmit signal)  PM0 = RXCAN0 (CAN receive signal)  General-purpose digital I/O pins PM0-PM  Access via PTM  Directions set via DDRM  Default is general I/O – other functions selected if SPI/CAN enabled

Ports available on the

MC9S12C128/Dragonfly

 PORT P bit 5 (PP5 or PWM5)

 Outputs of pulse-width modulation (PWM) module  PWM0-PWM5 outputs on pins PP0-PP  PWM0-PWM4 can also connect to pins PT0-PT  enable via MODRR register  General-purpose digital I/O pin PP5 (default)  Access via PTP  Direction set via DDRP  Default is general I/O  PWM outputs selected if PWM module channels enabled  All 8 pins PP0-PP7 on larger chip packages - only PP5/PWM5 available on 48-pin MC9S12C

MC9S12C128 pin electronics

Reduced drive levels

 Default is “standard” drive level

 Can reduce drive to reduce power

consumption and RFI emissions

 Ports K,E,B,A configured via RDRIV

 RDRIV has one bit per port:  0 = full drive (default), 1 = reduced drive  All pins in port have same drive levels

 Ports AD,J,M,P,S,T each have their own RDRx

register (RDRAD, RDRJ, etc.)

 pins individually configurable

MC9S12C128 pin electronics

Pull-up/pull-down control

 Normally connect unused input pins to high or

low logic level (avoids CMOS latch-up)

 HCS12 provides internal pull-up/down devices

for port input pins

 PUCR – enable pull-ups for ports K, E, B, A  1 bit per port - all pins in port configured the same  0=disable (default on A & B)  1=enable (default on K & E)  PERx – Port X pull device enable (x=AD,J,M,P,S,T)  0=disable, 1=enable (see table for defaults)  PPSx = Port polarity select (x=AD,J,M,P,S,T)  0=pull-up device, 1=pull-down device

Matrix keypad circuit diagram

  • 10 keys & contact pairs: in 3 rows & 4 columns
  • Each key is at a row-column intersection
  • Spring normally holds key away from contacts
  • Pressing a key connects the contacts (creates “short circuit” between row & column)

“Scanning” the keypad

 Drive column wires with output port

 Read states of row wires via input port

 Connect each row to +5v with a pull-up resistor

 If no row-column shorts – all row lines are

pulled high

 Row line K can only be low if it is shorted to

column line N while line N is being driven low

Example

Drive (output port pins): 1 0 1 1 Read (input port pins): 1

0

1

Pull-up Resistors

Pressed 10K Key

+5v

Hardware design

 Use MC9S12C128 I/O ports T and AD

 Mount DragonFly module and connect to +5v/GND

 Insert keypad in breadboard, with pull-up resistors

 Connect I/O port pins to “devices” as follows:

Parallel Port Pins Connected Devices

Port T, bits 0-3 7-segment display decoder

Port T, bits 4-7 Keypad column lines (Columns 0-3)

Port AD, bits 0-2 Keypad row lines (Rows 0-2)

Use logic analyzer/oscilloscope to help debug connections