UNIT 8 Keypad Interface Contact Closure Counter Exceptions (Interrupts and Reset)

Slides:



Advertisements
Similar presentations
Dr. Rabie A. Ramadan Al-Azhar University Lecture 3
Advertisements

Interrupts, Low Power Modes and Timer A (Chapters 6 & 8)
Programmable Interval Timer
External Interrupt Module MTT EXTERNAL INTERRUPT REQUEST MODULE (IRQ)
I/O Unit.
68HC11 Polling and Interrupts
EET 2261 Unit 9 Interrupts  Read Almy, Chapters 17 – 19.  Homework #9 and Lab #9 due next week.  Quiz next week.
ECE 372 – Microcontroller Design Parallel IO Ports - Interrupts
Interrupts What is an interrupt? What does an interrupt do to the “flow of control” Interrupts used to overlap computation & I/O – Examples would be console.
COMP3221: Microprocessors and Embedded Systems Lecture 15: Interrupts I Lecturer: Hui Wu Session 1, 2005.
Communication Lab - Interrupts 1/13 Sequential Programming  Our C++ programs are sequential ( סדרתיים), they start at the first instruction and end at.
Computer System Structures memory memory controller disk controller disk controller printer controller printer controller tape-drive controller tape-drive.
1 Interrupts INPUT/OUTPUT ORGANIZATION: Interrupts CS 147 JOKO SUTOMO.
INPUT/OUTPUT ORGANIZATION INTERRUPTS CS147 Summer 2001 Professor: Sin-Min Lee Presented by: Jing Chen.
The 8051 Microcontroller and Embedded Systems
INTERRUPTS PROGRAMMING
ECE 265 – LECTURE 12 The Hardware Interface 8/22/ ECE265.
Interrupts. 2 Definition: An electrical signal sent to the CPU (at any time) to alert it to the occurrence of some event that needs its attention Purpose:
1 EKT 225 MICROCONTROLLER I CHAPTER 3 I/O PORT PROGRAMMING.
COMP201 Computer Systems Exceptions and Interrupts.
Interrupts. What Are Interrupts? Interrupts alter a program’s flow of control  Behavior is similar to a procedure call »Some significant differences.
Ch. 9 Interrupt Programming and Real-Time Sysstems From Valvano’s Introduction to Embedded Systems.
Week #5 General Interfacing Techniques
Chapter 6: Interrupts and Resets
Revised: Aug 1, ECE 263 Embedded System Design Lessons 23, 24 - Exceptions - Resets and Interrupts.
MICROPROCESSOR INPUT/OUTPUT
Nurudeen Olayiwola Thomas Gutierrez
Interrupts and reset operations. Overview  Introduction to interrupts – What are they – How are they used  68HC11 interrupt mechanisms – Types of interrupts.
Microprocessors 1 MCS-51 Interrupts.
8279 KEYBOARD AND DISPLAY INTERFACING
ECE 371 – Unit 9 Interrupts (continued). Example Set up Two Interrupt Request Inputs: –Port H[0] Set Interrupt Flag on “0” to “1” transition (rising edge)
13-Nov-15 (1) CSC Computer Organization Lecture 7: Input/Output Organization.
1 Interrupts, Resets Today: First Hour: Interrupts –Section 5.2 of Huang’s Textbook –In-class Activity #1 Second Hour: More Interrupts Section 5.2 of Huang’s.
PPI-8255.
Interrupts  An interrupt is any service request that causes the CPU to stop its current execution stream and to execute an instruction stream that services.
8279 KEYBOARD AND DISPLAY INTERFACING
System Integration Module MTT Motoola SYSTEM INTEGRATION MODULE (SIM)
Embedded Systems Design 1 Lecture Set 8 MCS-51 Interrupts.
UNIT 7 - INTRODUCTION TO I/O INTERFACING. TWO MAJOR TYPES OF I/O INTERFACING ISOLATED I/O - DEDICATED I/O INSTRUCTIONS ARE USED TO ACCESS I/O DEVICES.
MICRO-CONTROLLER MOTOROLA HCS12 Interrupts Mechatronics Department Faculty of Engineering Ain Shams University.
بسم الله الرحمن الرحيم MEMORY AND I/O.
George W. Woodruff School of Mechanical Engineering, Georgia Tech ME4447/6405 ME 4447/6405 Microprocessor Control of Manufacturing Systems and Introduction.
CS-280 Dr. Mark L. Hornick 1 Sequential Execution Normally, CPU sequentially executes instructions in a program Subroutine calls are synchronous to the.
Interrupts and Exception Handling. Execution We are quite aware of the Fetch, Execute process of the control unit of the CPU –Fetch and instruction as.
Networked Embedded Systems Pengyu Zhang & Sachin Katti EE107 Spring 2016 Lecture 4 Timers and Interrupts.
Introduction to Exceptions 1 Introduction to Exceptions ARM Advanced RISC Machines.
INTV1 & MMCV4 By: Prof. Mahendra B. Salunke Asst. Prof., Department of Computer Engg., SITS, Pune-41 URL: microsig.webs.com.
FOR MORE CLASSES VISIT   ECET 340 Week 1 HomeWork 1  ECET 340 Week 1 iLab 1  ECET 340 Week 2 HomeWork 2  ECET 340 Week 2 iLab.
Chapter 10 Interrupts. Basic Concepts in Interrupts  An interrupt is a communication process set up in a microprocessor or microcontroller in which:
An Interrupt is either a Hardware generated CALL (externally derived from a hardware signal) OR A Software-generated CALL (internally derived from.
HCS12 Exceptions Maskable Interrupts
ECE 3430 – Intro to Microcomputer Systems
MICROPROCESSOR BASED SYSTEM DESIGN
68HC11 Interrupts & Resets.
Microprocessor Systems Design I
Timer and Interrupts.
Interrupts In 8085 and 8086.
Dr. Michael Nasief Lecture 2
Chapter 8 Input/Output I/O basics Keyboard input Monitor output
ECET 340 Competitive Success/snaptutorial.com
ECET 340 Education for Service-- snaptutorial.com.
ECET 340 Teaching Effectively-- snaptutorial.com.
X1 & X2 These are also called Crystal Input Pins.
COMPUTER PERIPHERALS AND INTERFACES
Interrupts.
Md. Mojahidul Islam Lecturer Dept. of Computer Science & Engineering
Md. Mojahidul Islam Lecturer Dept. of Computer Science & Engineering
Interrupts 1/18/2019.
ME 4447/6405 Microprocessor Control of Manufacturing Systems and
COMP3221: Microprocessors and Embedded Systems
Presentation transcript:

UNIT 8 Keypad Interface Contact Closure Counter Exceptions (Interrupts and Reset)

Keypad Figure 5.5 Use as Outputs Use as Inputs

Interface Keypad to Port H Port H[3:0] – Output –Full Drive Port H[7:4] – Input –Pulls are Optional since Pull-ups on Keypad –Disable Interrupts

Port H Definitions /* Port H Port Definitions */ #define PTH _P(0x260) #define PTIH _P(0x261) #define DDRH _P(0x262 #define RDRH _P( 0x263 #define PERH _P( 0x264 #define PPSH _P( 0x265 #define PIEH _P( 0x266 #define PIFH _P( 0x267

Port H Initialization /* Direction */ DDRH = 0x0F; /* Full Drive */ RDRH = 0x00; /* Pulls Not Required since pull resistors on keypad */ PERH = 0x00; /* Disable Interrupts */ PIEH = 0x00; /* Unselect Rows in Keypad */ PTH = 0x0F;

Procedure to Read Keypad /* if key is pressed, return ‘0’, ‘1’, …, ‘F’ else ‘z’ */ unsigned char keypress(void) {unsigned char mask[4]=0x0E,0x0D,0x0B,0x07; //1110, 1101, 1011, 0111 int i,j; char key; for(key=‘z’,i=0;i<4;i++) {PTH = mask[i]; // assert a 0 on a row in keypad for(j=0;j<4;j++) {if((PTH>>4) == mask[j]) //check each column for a returned 0 {if (((i<<2)+j)<10) key = ‘0’+(i<<2)+j; //value = 4*row# + column# else key=‘A’+(i 9 } PTH = 0x0F; // unselect row return (key); }

Algorithm Implemented in C i=0 PTH[3:0] = 0xE // Row 0 j=0 PTH[7:4] = 0xE key=‘0’ j=1 PTH[7:4] = 0xD key=‘1’ j=2 PTH[7:4] = 0xB key=‘2’ j=3 PTH[7:4] = 0x7 key=‘3’ i=1 PK[3:0] = 0xD // Row 1 j=0 PTH[7:4] = 0xE key=‘4’ j=1 PTH[7:4] = 0xD key=‘5’ j=2 PTH[7:4] = 0xB key=‘6’ j=3 PTH[7:4] = 0x7 key=‘7’ i=2 PTH[3:0] = 0xB // Row 2 j=0 PTH[7:4] = 0xE key=‘8’ j=1 PTH[7:4] = 0xD key=‘9’ j=2 PTH[7:4] = 0xB key=‘A’ j=3 PTH[7:4] = 0x7 key=‘B’ i=3 PTH[3:0] = 0x7 //Row 3 j=0 PTH[7:4] = 0xE key=‘C’ j=1 PTH[7:4] = 0xD key=‘D’ j=2 PTH[7:4] = 0xB key=‘E’ j=3 PTH[7:4] = 0x7 key=‘F’ keycode = 4*i+j; If(keycode<10) key = ‘0’ + keycode; else key = ‘A’ + keycode – 10;

Another Procedure Read Keypad /* if key is pressed, return ‘0’, ‘1’, …, ‘F’ else ‘z’ */ unsigned char keypress(void) {unsigned char mask[16]=0xEE,0xDE,0xBE,0x7E, 0XED,0xDD,0xBD,0x7D, 0xEB,0xDB,0xBB,0x7B, 0xE7,0xD7,0xB7,0x77; int i; char key; for(key=‘z’,i=0;i<16;i++) {PTH = mask[i]; // assert row in keypad if(PTH == mask[i]) {if (i<10) key = ‘0’+i; else key=‘A’+i-10;} } PTH = 0x0F; // unselect row return (key); } //SEE NEXT PAGE

EE key = 0 DE key = 1 BE key = 2 7E key = 3 sent out EB key = 8 DB key = 9 BB key = A 7B key = B E key = C D key = D B key = E key = F ED key = 4 DD key = 5 BD key = 6 7D key = 7 Row 0 Row 3 Row 2 Row 1

Keypads - Section Example Uses Port B and not Port H Uses switch() statements rather than for loops.

Another I/O Example: Contact Closure Counter Connect 8 Push-Button to the Pins of Port H Push-Button is normally open => “1” is input Press Momentary Push-Button => “0” is input Count Number of Times a Push-Button is Pressed Count “1” to “0” Transitions on each Pin

/* port definitions */ int main() {int count[8] = 0,0,0,0,0,0,0,0; int sum=0, int i; unsigned char oldsw, newsw, change; /* init port h */ oldsw = PTH; newsw = PTH; while(sum<1000) { while(oldsw == newsw) newsw = PTH; change = (oldsw^newsw) & oldsw; oldsw = newsw; for(i=0, i<8, i++) if(((change>>i)&0x01)!=0) {count[i]++; sum++} } return(0); } //count only 1->0 transitions

Details Old = 0x23 = 0b New = 0x32 = 0b Old ^ New = 0b (Old ^ New) & Old = 0b Increment count[0]

Exceptions, Interrupts, and Resets

“Exception”: A break in normal program flow, normally initiated by some hardware condition.

Two types of exceptions: Resets Interrupts

Exceptions can be initiated by either Internal or external events When exceptions occurs, the microcontroller: - Uses an address from a Vector Table to get to a Service Routine. - Saves the processor state on the stack (for Interrupts)

Events that Can Cause a Reset: –External Reset (via active low reset pin) –Power-on Reset –Computer Operating Properly (COP) Reset –Clock Monitor Reset Disabled by Debugger in Lab

Computer Operating Properly (COP Reset) Also called Watch Dog Timer User-configurable countdown timer If timer reaches 0, a system reset is triggered User must repeatedly reset using a reset timer sequence Disabled in Lab

Clock Monitor Reset Clock Monitor Reset when system clock frequency drops below a prescribed value or stops

Two Classes of Interrupts: –Nonmaskable Interrupts (cannot be disabled by software) –Maskable Interrupts Masked – Disabled (By software) Unmasked – Enabled (By software)

Nonmaskable Interrupts X bit – Condition Code Register (CCR) –X=“1” – Disables all Interrupts –X=“0” – Enable all Interrupts During Normal System Reset, X=“1” After System Initialization, X=“0” by software X can not be set to “1” by software

Types of Nonmaskable Interrupts Nonmaskable Interrupt Request (/XIRQ) –/XIRQ is External Pin –/XIRQ Active Low Generates Request Unimplemented Instruction Trap Software Interrupt Instruction (SWI)

Enabling of Maskable Interrupts I bit in Condition Code Register (CCR) –I = “0” Enable Maskable Interrupts –I = “1” Disable Maskable Interrupts C Program Instructions –ENABLE(); – Sets I=“0” –DISABLE(); – Sets I=“1”

Maskable Interrupt Sources IRQ Pin Real Time Clock Interrupt Enhanced Capture Timer Channels Pulse Accumulators SPI and SCI Serial I/O A/D System Port J, H, and P Pins Network Serial I/O Other

Interrupt Initialization (Fig. 4.21)

Interrupt Vector Table 2 Bytes Allocated for each Interrupt Source Contents of Vector –Starting Address of Interrupt Service Routine Vectored System –Each Source has a dedicated Vector “Boost” priority of one maskable interrupt to highest priority (HPRIO Register)

Interrupt Handling – Fig. 4.21

Interrupt Handling Save State of CPU on Stack by Hardware Disable Masked Interrupt System Determine Interrupt Source by Hardware Transfer Control to Interrupt Handling Software by Hardware Service Interrupt Request by Interrupt Service Routine (ISR) – User written Restore State of CPU from Stack using RTI instruction

Why Interrupts? Most operating systems support multiprocessing – Several application running at same time. Desirable to eliminate “busy waits” in all software since busy waits can monopolize CPU resources.

Recall: Parallel Printer Interface (Not using interrupts) Printer /Strobe Busy Data[7:0] Busy Write Data Strobe Yes No

Print a Character on Printer void printc(unsigned char c) { /* Wait while Printer is Busy */ while((PTJ&0x02)!=0); // BUSY WAIT /* Printer not Busy, Output Data */ PTH = c; /* Generate Strobe * PTJ = PTJ & 0xFE; // Bit 0 Low PTJ = PTJ | 0x01; // Bit 0 High }

Busy Data /Strobe ACK Printer Waveforms PC Parallel Printer Port Definition

Parallel Printer Interface Printer /Strobe Busy Data[7:0] ACK Busy Write Data Strobe Yes No

Interfacing a Parallel Printer Using Interrupts Present data to printer Send Strobe signal to printer When printer is no long busy, it sends out an ACK pulse to request an interrupt (The interrupt indicates the printer is ready to receive a new character to print.)