Administrivia. ECE/CS 5780/6780: Embedded System Design. Port Pull Configuration. Interfacing a Switch to a Computer

Similar documents
ECE/CS 5780/6780: Embedded System Design

General Features of Interrupts. ECE/CS 5780/6780: Embedded System Design. Stack Before and After an Interrupt. Sequence of Events During Interrupt

General Features of Interrupts. ECE/CS 5780/6780: Embedded System Design. Sequence of Events During Interrupt. Stack Before and After an Interrupt

CS/ECE 5780/6780: Embedded System Design

MICROCONTROLLER SYSTEM CONTROL DESIGN JON PRITCHARD SCOTT VON THUN

Administrivia. ECE/CS 5780/6780: Embedded System Design. Debugging: Another perspective. Testing & Stabilization

The modules in this lab room are 4 line by 16 character display modules. The data sheet/users manual for the module is posted on My.Seneca.

Capturing the Time of an External Event Input Capture Subsystem

The MC9S12 Timer Output Compare Function Making an event happen at specific time on the HC12 The MC9S12 Output Compare Function

Lab #3: Keypad Scanning in C Week of 11 February 2019

The MC9S12 Input Capture Function

Using Input Capture on the 9S12

ECE/CE 3720: Embedded System Design

ECE 4510/5530 Microcontroller Applications Week 7

ECE/CS 5780/6780: Embedded System Design. Introduction to Serial Communication

The MC9S12 Timer Input Capture Function

EE 308 Spring Exam 1 Feb. 27

ECE 4510/5530 Microcontroller Applications Week 9

Introduction to Semaphores. ECE/CS 5780/6780: Embedded System Design. Spin-Lock Counting Semaphore. Spin-Lock Semaphore

EE345L Spring 2006 May 10, 2006, 2-5pm Page 1 of 8

What happens when an HC12 gets in unmasked interrupt:

Introduction to Serial Communication. ECE/CS 5780/6780: Embedded System Design. A Serial Channel. Definitions. SCI versus SPI.

Embedded Controller Programming II. I/O Device Programming in C Part 1: Input and Interrupts

Introduction to Semaphores. ECE/CS 5780/6780: Embedded System Design. Spin-Lock Counting Semaphore. Spin-Lock Semaphore

EE 308 Spring A software delay. To enter a software delay, put in a nested loop, just like in assembly.

EE 308 Spring A software delay

EE 308/MENG 483 Spring 2017

Keyboards. The PS/2 Protocol

ME 4447/6405. Microprocessor Control of Manufacturing Systems and Introduction to Mechatronics. Instructor: Professor Charles Ume.

Keypad Interfacing. Microcomputer Architecture and Interfacing Colorado School of Mines Professor William Hoff

ELEC 3040/3050 Lab 5. Matrix Keypad Interface Using Parallel I/O

ECE/CS 5780/6780: Embedded System Design

EE319 K Lecture 3. Introduction to the 9S12 Lab 1 Discussion Using the TExaS simulator. University of Texas ECE

Microprocessors & Interfacing

CHAPTER 12 LCD AND KEYBOARD INTERFACING

Bachelor of Engineering in Computer and Electronic Engineering

EE445L Fall 2010 Final Version A Page 1 of 10

EE345L Spring 2004 Final Version 3 Page 1 of 8

ELEC 3040/3050 Lab 5. Matrix Keypad Interface Using Parallel I/O

Introduction to the MC9S12 Hardware Subsystems

MCO556 Practice Test 2

Input/Output Devices. Lecturer: Sri Parameswaran Notes by: Annie Guo

AN10184 Connecting a keyboard to the Philips LPC9xx microcontroller

EE345L Fall 2007 December 14, 2007, 9am-12 Version 1 Page 1 of 8

CS/ECE 5780/6780: Embedded System Design

EE4390 Microprocessors

NTE1731 Integrated Circuit CMOS 10 Number Pulse Dialer

CS/ECE 5780/6780: Embedded System Design

Chapter 1. Solutions Solution 1.1. Most RAMs are volatile, meaning the information is lost if power is removed then restored.

LCD AND KEYBOARD INTERFACING

HC12 Built-In Hardware

Register Access. Common - Last updated 7/25/18

ECE 3120: Computer Systems Chapter 8: ECE-3120-A Musical

Computer Organization & Systems Exam I Example Questions

ECE3120: Computer Systems Chapter 8: Timer Module

Interrupts. How can we synchronize with a peripheral? Polling

Copyright (C) 2003 Freescale Semiconductor, Inc. and Viola Systems Ltd. All Rights Reserved

8.7. Finite state machines with statically-allocated linked structures Stepper motor controller L 293

538 Lecture Notes Week 7

EE Embedded Systems Design. Lessons Exceptions - Resets and Interrupts

ECE 367 -Experiment #1 Fall 2012

Debounced 8 8 Key-Scan Controller

CprE 288 Introduction to Embedded Systems Exam 1 Review. 1

History of the Microprocessor. ECE/CS 5780/6780: Embedded System Design. Microcontrollers. First Microprocessors. MC9S12C32 Block Diagram

ECE2049: Embedded Computing in Engineering Design A Term Fall Lecture #8: Making it work: LEDs, Buttons & Keypad

C Language Programming, Interrupts and Timer Hardware

Introduction. ECE/CS 5780/6780: Embedded System Design. Golden Rule of Software Development. Software Maintenance. Assembly Language Style Issues

Lecture 15 February 20, 2012 Introduction to the MC9S12 Timer Subsystem What Happens when you Reset the MC9S12. Introduction to Interrupts

CPEG300 Embedded System Design. Lecture Interface with Peripheral Devices

Do not start the test until instructed to do so!

Lab 8 RS232 October 22, 2015

Introduction to Embedded Microcomputer Systems Lecture 6.1

Turning Ideas Into Reality ABCircuits POB 123 New Hill NC (919) C922-SO IC

TIMSK=0b ; /* enables the T/C0 overflow interrupt in the T/C interrupt mask register for */

Texas Instruments Microcontroller HOW-TO GUIDE Interfacing Keypad with MSP430F5529

538 Lecture Notes Week 5

538 Lecture Notes Week 5

F²MC-16FX FAMILY MB96340 KEY MATRIX INTERFACE USING I/O PORT 16-BIT MICROCONTROLLER APPLICATION NOTE. Fujitsu Microelectronics Europe Application Note

Pulse Accumulator on the HCS12

Chapter 9. Input/Output (I/O) Ports and Interfacing. Updated: 3/13/12

EL2310 Scientific Programming

Administrivia. ECE/CS 5780/6780: Embedded System Design. FIFO with Infinite Memory. Introduction to FIFOs

Finite State Machine Lab

Phi_interfaces. Liu Version /14/2012 2:32:00 AM

Interrupts and Timers

C Language Advanced Concepts. Microcomputer Architecture and Interfacing Colorado School of Mines Professor William Hoff

6.1. EE 109 Unit 6. LCD Interfacing

COMP2121: Microprocessors and Interfacing. I/O Devices (II)

Introduction to Embedded Microcomputer Systems Lecture Synchronizing with an input device. Busy-Wait. Empty Fifo. Busy Status.

ELE 758 * DIGITAL SYSTEMS ENGINEERING * MIDTERM TEST * Circle the memory type based on electrically re-chargeable elements

Magic 8 Ball. Student's name & ID (1): Partner's name & ID (2): Your Section number & TA's name

e-pg Pathshala Subject: Computer Science Paper: Embedded System Module: Interfacing External Devices using Embedded C Module No: CS/ES/22

Embedded Controller Programming 2

AN10210 Using the Philips 87LPC76x microcontroller as a remote control transmitter

C Language Programming, Interrupts and Timer Hardware

CSE 351: The Hardware/Software Interface. Section 2 Integer representations, two s complement, and bitwise operators

AGENDA Binary Operations CS 3330 Samira Khan

ME 4447/ME Microprocessor Control of Manufacturing Systems/ Introduction to Mechatronics. Instructor: Professor Charles Ume

EE472 Mid Term SOLUTION KEY. Rules. Prof. Blake Hannaford Department of Electrical Engineering The University of Washington 31-Oct-2005 NAME

Marten van Dijk Department of Electrical & Computer Engineering University of Connecticut

Transcription:

Administrivia ECE/CS 5780/6780: Embedded System Design Scott R. Little Give yourself enough time on Lab 3 prelab. Lecture 6: Debouncing and Matrix Keypads Scott R. Little (Lecture 6: Keypads) ECE/CS 5780/6780 1 / 20 Scott R. Little (Lecture 6: Keypads) ECE/CS 5780/6780 2 / 20 Interfacing a Switch to a Computer Port Pull Configuration Port Pull Select Register (PPSAD, PPSJ, PPSP, PPSM, PPSS, PPST) select pull-up (0) or pull-down (1) for the port. Pull Enable Register (PERAD, PERJ, PERP, PERM, PERS, PERT) enables the pull-up or pull-down function. You should first set the PPSx register and then the PERx register to avoid glitches. Scott R. Little (Lecture 6: Keypads) ECE/CS 5780/6780 3 / 20 Scott R. Little (Lecture 6: Keypads) ECE/CS 5780/6780 4 / 20

Port AD Initialization Software Switch Bounce void PortAD_Init(void){ ATDDIEN = 0x03; // PAD1-0 digital I/O DDRAD &= ~0x03; // PAD1-0 inputs PPSAD = 0x02; // pull-down on PAD1 PPSAD &= ~0x01; // pull-up on PAD0 PERAD = 0x03; // enable pull-up and pull-down Scott R. Little (Lecture 6: Keypads) ECE/CS 5780/6780 5 / 20 Scott R. Little (Lecture 6: Keypads) ECE/CS 5780/6780 6 / 20 Hardware Debouncing Using a Capacitor Hardware Debouncing Using a Capacitor (cont) Scott R. Little (Lecture 6: Keypads) ECE/CS 5780/6780 7 / 20 Scott R. Little (Lecture 6: Keypads) ECE/CS 5780/6780 8 / 20

Software Debouncing Software Debouncing with Gadfly Synchronization void Key_WaitPress(void){ while(ptt&0x08); // PT3=0 when pressed Timer_Wait10ms(1); // debouncing void Key_WaitRelease(void){ while((ptt&0x08)==0); // PT3=1 -> released Timer_Wait10ms(1); // debouncing void Key_Init(void){ Timer_Init(); DDRT &=~0x08; // PT3 is input Scott R. Little (Lecture 6: Keypads) ECE/CS 5780/6780 9 / 20 Scott R. Little (Lecture 6: Keypads) ECE/CS 5780/6780 10 / 20 Software Debouncing Output Compare Basics Used to create squarewaves, generate pulses, implement time delays, and execute periodic interrupts. 6812 has 8 output compare modules. Each module has: An external output pin (OCn). A flag bit. Force compare control bit (FOCn). Two control bits (OMn, OLn). An interrupt mask bit. 16-bit output compare register. Scott R. Little (Lecture 6: Keypads) ECE/CS 5780/6780 11 / 20 Scott R. Little (Lecture 6: Keypads) ECE/CS 5780/6780 12 / 20

Output Compare Process Example Read the current 16-bit TCNT. Calculate TCNT+delay. Set the 16-bit output compare register to TCNT+delay. Clear the output compare flag. Wait for the output compare flag to be set. Scott R. Little (Lecture 6: Keypads) ECE/CS 5780/6780 13 / 20 Another Approach to Software Debouncing void Key_Init(void) { TIOS = 0x20; // enable OC5 (see Chapter 6) TSCR1 = 0x80; // enable TSCR2 = 0x01; // 500 ns clock DDRT &=~0x08; // PT3 is input unsigned char Key_Read(void){ unsigned char old; old = PTT&0x08; // Current value TC5 = TCNT+20000; // 10ms delay TFLG1 = 0x20; // Clear C5F while((tflg1&0x20)==0){ // 10ms if(old!=(ptt&0x08)){ // changed? old = PTT&0x08; // New value TC5 = TCNT+20000; // restart delay return(old); Scott R. Little (Lecture 6: Keypads) ECE/CS 5780/6780 14 / 20 Debouncing Multiple Switches Basic Approaches to Interfacing Multiple Keys #define MAX_CHECKS 10 uint8_t Debounced_State; uint8_t State[MAX_CHECKS]; uint8_t Index; void DebounceSwitches(void) { uint8_t i,j; State[Index] = ReadKeys(); Index++; j = 0xff; for(i=0;i<max_checks-1;i++) { j &= State[i]; Debounced_State ^= j; if(index >= MAX_CHECKS) { Index = 0; Based on My favorite software debouncers by Jack Gannsle. Scott R. Little (Lecture 6: Keypads) ECE/CS 5780/6780 15 / 20 Row Out3 Out2 Out1 Out0 3 0 HiZ HiZ HiZ 2 HiZ 0 HiZ HiZ 1 HiZ HiZ 0 HiZ 0 HiZ HiZ HiZ 0 Row Out3 Out2 Out1 Out0 15 14... 0 15 1 1 1 1 0 HiZ... HiZ 14 1 1 1 0 HiZ 0... HiZ........................... 0 0 0 0 0 HiZ HiZ... 0 Scott R. Little (Lecture 6: Keypads) ECE/CS 5780/6780 16 / 20

4 by 4 Scanned Keypad 4 by 4 Scanned Keypad Row 3 Row 2 Row 1 Row 0 Col 3 Col 2 Col 1 Col 0 0 1 1 1 a b c d 1 0 1 1 e f g h 1 1 0 1 i j k l 1 1 1 1 m n o p There are two steps to scan a particular row: 1 Select that row by driving low while other rows are not driven. 2 Read the columns to see if any keys are pressed in that row (0 means key pressed, 1 means not pressed). The scanned keyboard operates properly if: 1 No key is pressed. 2 Exactly one key is pressed. 3 Exactly two keys are pressed. Scott R. Little (Lecture 6: Keypads) ECE/CS 5780/6780 17 / 20 Scott R. Little (Lecture 6: Keypads) ECE/CS 5780/6780 18 / 20 Software for a Matrix Scanned Keypad const struct Row { unsigned char direction; unsigned char keycode[4]; typedef const struct Row RowType; RowType ScanTab[5]={ { 0x80, "abcd", // row 3 { 0x40, "efgh", // row 2 { 0x20, "ijkl", // row 1 { 0x10, "mnop", // row 0 { 0x00, " " ; void Key_Init(void){ DDRT = 0x00; // PT3-PT0 inputs PTT = 0; // PT7-PT4 oc output PPST = 0; // pull-up on PT3-PT0 PERT = 0x0F; Scott R. Little (Lecture 6: Keypads) ECE/CS 5780/6780 19 / 20 Software for a Matrix Scanned Keypad (cont) /* Returns ASCII code for key pressed, Num is the number of keys pressed both equal zero if no key pressed */ unsigned char Key_Scan(short *Num){ RowType *pt; unsigned char column,key; short j; (*Num)=0; key=0; // default values pt=&scantab[0]; while(pt->direction){ DDRT = pt->direction; // one output column = PTT; // read columns for(j=3; j>=0; j--){ if((column&0x01)==0){ key = pt->keycode[j]; (*Num)++; column>>=1; // shift into position pt++; return key; Scott R. Little (Lecture 6: Keypads) ECE/CS 5780/6780 20 / 20