Chapter 12 Capturing Input

Slides:



Advertisements
Similar presentations
Module 3: Block 3 Call Management
Advertisements

1 Concurrency: Deadlock and Starvation Chapter 6.
Copyright © 2003 Pearson Education, Inc. Slide 1.
© 2010 Pearson Addison-Wesley. All rights reserved. Addison Wesley is an imprint of Chapter 5: Repetition and Loop Statements Problem Solving & Program.
Computational Environment for Radiotherapy Research CERR 3.0 beta 1 - Getting Started -
Know About Function keys
1 Daily ATM/Debit Maintenance through CU*BASE A Preview of ATM and Debit Card Maintenance Screens Prepared June 24, 2009.
Chapter 4 Linked Lists. © 2005 Pearson Addison-Wesley. All rights reserved4-2 Preliminaries Options for implementing an ADT List –Array has a fixed size.
Data Structures ADT List
The New User Interface MEDITECH Training & Education.
MEDITECH TIPS and TRICKS.
C Language Programming
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 13 Pointers and Linked Lists.
Select a time to count down from the clock above
Interrupts, Low Power Modes and Timer A (Chapters 6 & 8)
C Examples 1.
Interrupt Controller Introduction to 8259.
Chung-Ta King National Tsing Hua University
The 8051 Microcontroller Chapter 5 SERIAL PORT OPERATION.
Programmable Keyboard/ Display Interface: 8279
ECE 447 Fall 2009 Lecture 9: TI MSP430 Interrupts & Low Power Modes.
The 8051 Microcontroller and Embedded Systems
INTERRUPTS PROGRAMMING
Chapter 12 Capturing Input. Di Jasio - Programming 32-bit Microcontrollers in C Button Inputs.
1 Timing System Timing System Applications. 2 Timing System components Counting mechanisms Input capture mechanisms Output capture mechanisms.
UNIT 8 Keypad Interface Contact Closure Counter Exceptions (Interrupts and Reset)
V 0.91 Polled IO versus Interrupt Driven IO Polled Input/Output (IO) – processor continually checks IO device to see if it is ready for data transfer –Inefficient,
ARM Timers.
Unit 10.2 Timer Examples. Example – Music Generation Channel 6 – Set up as a timer Output to Generate Square Waves Channel 4 – Set up as a timer Output.
Revised: Aug 1, ECE 263 Embedded System Design Lessons 23, 24 - Exceptions - Resets and Interrupts.
Another Example: #include<BIOS.H> #include<DOS.H>
LAB 8: Program Design Pattern and Software Architecture
Time Measurement Capture Mode of the Capture/Compare/PWM module is used for time measurement. TMR1 or TMR3 16-bit value transferred to 16-bit capture.
1. Registers Used in Timer/Counter  TH0, TL0, TH1, TL1  TMOD (Timer mode register)  TCON (Timer control register) 2.
8279 KEYBOARD AND DISPLAY INTERFACING
Timer Timer is a device, which counts the input at regular interval (δT) using clock pulses at its input. The counts increment on each pulse and store.
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)
ECS642U Embedded Systems Cyclic Execution and Polling William Marsh.
1 68HC11 Timer Chapter HC11 Timer Subsystem Several timing functions: Basic timing Basic timing Real time interrupts Real time interrupts Output.
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.
Chapter 10 Glass Bliss Using the Parallel Master Port to communicate with Alphanumeric LCD displays.
12/16/  List the elements of 8255A Programmable Peripheral Interface (PPI)  Explain its various operating modes  Develop a simple program to.
1 68HC11 Timer HC11 or HC12: Chapter HC11 Timer Subsystem  Several timing functions: Basic timing Basic timing Real time interrupts Real time.
Real Time Interrupts Section Real-Time Interrupt (RTI) Most operating systems (OS) require an interrupt every T seconds by the RTI RTI interrupts.
8279 KEYBOARD AND DISPLAY INTERFACING
Handling multiple input signals Version #2 – co-operative scheduler Version #3 – pre-emptive scheduler.
Chapter 5 - Interrupts.
Programming Microcontrollers in C Lecture L7.1. C Data Types TypeSizeRange char1 byte-128 – 127 unsigned char1 byte0 – 255 Int2 bytes – unsigned.
CSCI1600: Embedded and Real Time Software Lecture 16: Advanced Programming with I/O Steven Reiss, Fall 2015.
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.
EE/CS-352: Embedded Microcontroller Systems Part V The 8051 Assembly Language Interrupts.
Polled IO versus Interrupt Driven IO
kashanu.ac.ir Microprocessors Interrupts Lec note 8.
Embedded Programming and Robotics Lesson 11 Arduino Interrupts 1.
Interrupts ELEC 330 Digital Systems Engineering Dr. Ron Hayne Images Courtesy of Ramesh Gaonkar and Delmar Learning.
The 8051 Microcontroller Chapter 6 INTERRUPTS. 2/29 Interrupt is the occurrence of a condition an event that causes a temporary suspension of a program.
One more PIC18F252 example and revision for exam B222L Branislav Vuksanovic, UoP, ECE.
Microprocessors A practical approach..
Chapter 10 Interrupts. Basic Concepts in Interrupts  An interrupt is a communication process set up in a microprocessor or microcontroller in which:
Microprocessor Systems Design I
BVM Engineering College Electrical Engineering Department : Microprocessor and Microcontroller Interfacing Interrupts of 8051 Prepared by:
CSCI1600: Embedded and Real Time Software
Lecture 22.
Interrupts, Tasks and Timers
전자의료시스템 및 실습 System Configuration/Interrupt
Lecture 9: TI MSP430 Interrupts & Low Power Modes
8279 – Programmable Keyboard/Display Interface
CSCI1600: Embedded and Real Time Software
Source: Serial Port Source:
The Programmable Peripheral Interface (8255A)
Presentation transcript:

Chapter 12 Capturing Input

Change Notification Module

Using CN to Capture Keyboard Inputs

CN - ISR void __ISR( _CHANGE_NOTICE_VECTOR, ipl1) CNInterrupt( void) { // change notification interrupt service routine   // 1. make sure it was a falling edge if ( PS2CLK == 0) { switch( PS2State){ default: case PS2START: // verify start bit if ( ! PS2DAT) KCount = 8; // init bit counter KParity = 0; // init parity check PS2State = PS2BIT; } break; case PS2BIT: KBDBuf >>=1; // shift in data bit if ( PS2DAT) KBDBuf += 0x80; KParity ^= KBDBuf; // update parity if ( --KCount == 0) // if all bit read, move on PS2State = PS2PARITY; case PS2PARITY: if ( PS2DAT) // verify parity KParity ^= 0x80; if ( KParity & 0x80) // if parity odd, continue PS2State = PS2STOP; else PS2State = PS2START; case PS2STOP: if ( PS2DAT) // verify stop bit { KBDCode = KBDBuf; // save code in mail box KBDReady = 1; // set flag, code available } PS2State = PS2START; break;   } // switch state machine } // if falling edge // clear interrupt flag mCNClearIntFlag(); } // CN Interrupt

I/O Polling (Timer based)

I/O Polling State Machine

I/O Polling - ISR else { // state 0 if ( k) // PS2CLK == 1 void __ISR( _TIMER_4_VECTOR, ipl1) T4Interrupt( void) { int d, k; // sample the inputs clock and data at the same time d = PS2DAT; k = PS2CLK; // keyboard state machine if ( KState) { // previous time clock was high KState 1 if ( !k) // PS2CLK == 0 { // falling edge detected, KState = 0; // transition to State0   <<<< insert data state machine here >>>> } // falling edge else { // clock still high, remain in State1 } // clock still high } // state 1 else { // state 0 if ( k) // PS2CLK == 1 { // rising edge, transition to State1 KState = 1;   } // rising edge { // clocl still low, remain in State0 } // clock still low } // state 0 // clear the interrupt flag mT4ClearIntFlag(); } // T4 Interrupt

I/O Polling w/Timeout

I/O Polling w/Timeout - ISR void __ISR( _TIMER_4_VECTOR, ipl1) T4Interrupt( void) { int d, k;   // sample the inputs clock and data at the same time d = PS2DAT; k = PS2CLK; // keyboard state machine if ( KState) { // previous time clock was high KState 1 if ( !k) // PS2CLK == 0 { // falling edge detected, KState = 0; // transition to State0 KTimer = KMAX; // restart the counter <<<< insert data state machine here >>>> } // falling edge else { // clock still high, remain in State1 KTimer--; if ( KTimer ==0) // Timeout PS2State = PS2START; // Reset data SM } // clock still high } // Kstate 1 else { // Kstate 0 if ( k) // PS2CLK == 1 { // rising edge, transition to State1 KState = 1; } // rising edge { // clocl still low, remain in State0 KTimer--; if ( KTimer == 0) // Timeout PS2State = PS2START; // Reset data SM } // clock still low } // Kstate 0   // clear the interrupt flag mT4ClearIntFlag(); } // T4 Interrupt

Switch switch( PS2State){ default: case PS2START: if ( !d) // PS2DAT == 0 { KCount = 8; // init bit counter KParity = 0; // init parity check PS2State = PS2BIT; } break;   case PS2BIT: KBDBuf >>=1; // shift in data bit if ( d) // PS2DAT == 1 KBDBuf += 0x80; KParity ^= KBDBuf; // calculate parity if ( --KCount == 0) // all bit read PS2State = PS2PARITY; case PS2PARITY: KParity ^= 0x80; if ( KParity & 0x80) // parity odd, continue PS2State = PS2STOP; else PS2State = PS2START; case PS2STOP: KBDCode = KBDBuf; // write in the buffer KBDReady = 1; } // switch

InitKBD void initKBD( void) { // init I/Os ODCGbits.ODCG13 = 1; // make RG13 open drain (PS2clk) _TRISG13 = 1; // make RG13 an input pin (for now) _TRISG12 = 1; // make RG12 an input pin   // clear the kbd flag KBDReady = 0; // configure Timer4 PR4 = 25*TPS - 1; // 25 us T4CON = 0x8000; // T4 on, prescaler 1:1 mT4SetIntPriority( 1); // lower priority mT4ClearIntFlag(); // clear interrupt flag mT4IntEnable( 1); // enable interrupt } // init KBD

Efficiency Evaluation void __ISR(..) T4Interrupt( void) { _RA2 = 1; // flag up, inside the ISR   <<< Interrupt service routine here >> _RA2 = 0; // flag down, back to the main }

Keyboard Buffering A Circular Buffer // circular buffer unsigned char KCB[ KB_SIZE];   // head and tail or write and read pointers volatile int KBR, KBW;

Using the Circular Buffer Insertion: case PS2STOP: if ( PS2IN & DATMASK) // verify stop bit { KCB[ KBW] = KBDBuf; // write in the buffer // check if buffer full if ( (KBW+1)%KB_SIZE != KBR) KBW++; // else increment ptr KBW %= KB_SIZE; // wrap around } PS2State = PS2START; break; Extraction: int getKeyCode( char *c) { if ( KBR == KBW) // buffer empty return FALSE;   // else buffer contains at least one key code *c = KCB[ KBR++]; // extract the first key code KBR %= KB_SIZE; // wrap around the pointer return TRUE; } // getKeyCode

KeyCodes Decoding // PS2 keyboard codes (standard set #2) const char keyCodes[128]={ 0, F9, 0, F5, F3, F1, F2, F12, //00 0, F10, F8, F6, F4, TAB, '`', 0, //08 0, 0,L_SHFT, 0,L_CTRL,'q','1', 0, //10 0, 0, 'z', 's', 'a', 'w', '2', 0, //18 0, 'c', 'x', 'd', 'e', '4', '3', 0, //20 0, ' ', 'v', 'f', 't', 'r', '5', 0, //28 0, 'n', 'b', 'h', 'g', 'y', '6', 0, //30 0, 0, 'm', 'j', 'u', '7', '8', 0, //38 0, ',', 'k', 'i', 'o', '0', '9', 0, //40 0, '.', '/', 'l', ';', 'p', '-', 0, //48 0, 0,'\'', 0, '[', '=', 0, 0, //50 CAPS, R_SHFT,ENTER, ']', 0,0x5c, 0, 0, //58 0, 0, 0, 0, 0, 0, BKSP, 0, //60 0, '1', 0, '4', '7', 0, 0, 0, //68 0, '.', '2', '5', '6', '8', ESC, NUM, //70 F11, '+', '3', '-', '*', '9', 0, 0 //78 };   const char keySCodes[128] = { 0, F10, F8, F6, F4, TAB, '~', 0, //08 0, 0,L_SHFT, 0,L_CTRL,'Q','!', 0, //10 0, 0, 'Z', 'S', 'A', 'W', '@', 0, //18 0, 'C', 'X', 'D', 'E', '$', '#', 0, //20 0, ' ', 'V', 'F', 'T', 'R', '%', 0, //28 0, 'N', 'B', 'H', 'G', 'Y', '^', 0, //30 0, 0, 'M', 'J', 'U', '&', '*', 0, //38 0, '<', 'K', 'I', 'O', ')', '(', 0, //40 0, '>', '?', 'L', ':', 'P', '_', 0, //48 0, 0,'\"', 0, '{', '+', 0, 0, //50 CAPS, R_SHFT,ENTER, '}', 0, '|', 0, 0, //58

getc() char getC( void) { unsigned char c; while( 1) while( !KBDReady); // wait for a key pressed // check if it is a break code while (KBDCode == 0xf0) { // consume the break code KBDReady = 0; // wait for a new key code while ( !KBDReady); // check if the shift button is released if ( KBDCode == L_SHFT) CapsFlag = 0; // and discard it // wait for the next key } // check for special keys CapsFlag = 1; else if ( KBDCode == CAPS) CapsFlag = !CapsFlag; else // translate into an ASCII code { if ( CapsFlag) c = keySCodes[KBDCode%128]; else c = keyCodes[KBDCode%128]; break; } // consume the current character KBDReady = 0; return ( c); } // getC