L13_Keypads - Keypads ECET 209 – Lecture 13 Introduction to Microcontrollers Overview • Keypads • Review the Bitwise C Operators to interface

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Keypads ECET 209 – Lecture 13 Introduction to Microcontrollers Overview • Keypads • Review the Bitwise C Operators to interface with Hardware ECET 209 Purdue University 2 Keypads ECET 209 Purdue University 3 How Do Keypads Work? ECET 209 Purdue University 4 How Do Keypads Work? ECET 209 Purdue University 5 How Do Keypads Work? ECET 209 Purdue University 6 How Do Keypads Work? ECET 209 Purdue University 7 Scanning a Keypad ECET 209 Purdue University 8 Scanning a Keypad High High High High ECET 209 Purdue University 9 Scanning a Keypad Pull one line low at a time High High High High ECET 209 Purdue University 10 Scanning a Keypad Low Low Low Low High High High High ECET 209 Purdue University 11 Scanning a Keypad Low High High High High ECET 209 Purdue University 12 Scanning a Keypad Low High High High High ECET 209 Purdue University 13 Scanning a Keypad Low vs. High Low High High High High ECET 209 Purdue University 14 Scanning a Keypad Low Low High High High High ECET 209 Purdue University 15 Scanning a Keypad w/ Micro Microcontroller ECET 209 Purdue University 16 Buy a Chip!! ECET 209 Purdue University 17 Fairchild MM74C922 ECET 209 Purdue University 18 Fairchild MM74C922 ECET 209 Purdue University 19 Fairchild MM74C922 ECET 209 Purdue University 20 How does an encoded keypad work? • Encoder Chip constantly scans the keypad • When any key is pressed: – DAV goes HIGH – 4-bit data is Binary for the key pressed • When key is released: – DAV goes LOW – Data removed from data lines. ECET 209 Purdue University 21 Press Pressing “5” Release DAV 0101 DATA 74922 KEYPAD ENCODER C D E F 8 9 A B 4 5 6 7 0 1 2 1 3 ECET 209 DAV D3 D2 D1 D0 Purdue University 0 1 0 1 22 Keypad Example • Create a program that will read the value on the keypad when a key is pressed. – Check for a key to be pressed – Read the value ECET 209 Purdue University 23 Keypad Example • Create a program that will read the value on the keypad when a key is pressed. – Check for a key to be pressed – Read the value ECET 209 Purdue University 24 Keypad Example • Create a program that will wait for a key on the keypad to be pressed and then read the value. – Wait for a key to be pressed – Read the value ECET 209 Purdue University 25 Keypad Example • Create a program that will wait for a key on the keypad to be pressed and then read the value. – Wait for a key to be pressed – Read the value ECET 209 Purdue University 26 Keypad Example • Create a program that will wait for a key to be pressed, then read the value on the keypad. After reading the value on the keypad, wait until the key is released before continuing. – Wait for a key to be pressed – Read the value – Wait for the key to be released ECET 209 Purdue University 27 Keypad Example – Wait for a key – Read the key – Wait for release ECET 209 Purdue University 28 Flowchart vs. Application ECET 209 Purdue University 29 I/O Hookup 74922 KEYPAD ENCODER DAV D3 D2 D1 D0 ECET 209 PORTA.4 PORTA.3 PORTA.2 PORTA.1 PORTA.0 Purdue University 30 Masking for DAV PORT Value “MASK” ECET 209 AND xxx1xxxx 00010000 00010000 Purdue University 31 Masking for Data PORT Value “MASK” ECET 209 AND xxxx1111 00001111 00001111 Purdue University 32 Solution Steps • For Lab #5 – – – – – – Wait for a key to be pressed (DAV goes high) Read the key value Wait for key release (DAV goes low) Place the value on the LEDs Send the value out the serial port Loop back to the Top ECET 209 Purdue University 33 Flowchart vs. Application ECET 209 Purdue University 34 Handshaking • CodeVisionAVR allows direct control or access to the port pins for input and output – Symbolically refer to port pins – Can allow for easier to read code* PORTC.7 = 0; if( PINB.0 == 1) ECET 209 // turn on MSB // test LSB Purdue University 35 Handshaking with the Keypad while ( (PINA & 0x10) == 0) while ( PINA.4 == 0) key = PINA & 0x0F; key = PINA & 0x0F; while ( (PINA & 0x10) != 0) while (PINA.4 != 0) ECET 209 Purdue University 36 Handshaking with the Keypad while ( (PINA & 0x10) == 0) while ( PINA.4 == 0) key = PINA & 0x0F; key = PINA & 0x0F; while ( (PINA & 0x10) != 0) while (PINA.4 != 0) while (PINA.4 == 1) ECET 209 Purdue University 37 Press Release DAV 0101 DATA #define DAV PINA.4 while( DAV == 0 ) { } ECET 209 Purdue University 38 Press Release DAV 0101 DATA #define DAV PINA.4 while( DAV == 0 ) { } ECET 209 Purdue University 39 Press Release DAV DATA 0101 #define KEYPAD_DATA (PINA & 0x0F) key = KEYPAD_DATA; ECET 209 Purdue University 40 Press Release DAV 0101 DATA #define DAV PINA.4 while( DAV == 1 ) { } ECET 209 Purdue University 41 Keypad Handshaking Wait for Not Dav Wait for Dav Read the Key Wait for Dav Wait for Not Dav ECET 209 Read the Key Purdue University 42 Solution Steps • For Lab – – – – – – Wait for key release (DAV goes low) Wait for a key to be pressed (DAV goes high) Read the key value Place the value on the LEDs Send the value out the serial port Loop back to the Top ECET 209 Purdue University 43 ...
View Full Document

This note was uploaded on 02/22/2012 for the course ECET 209 taught by Professor Richardson during the Fall '08 term at Purdue University-West Lafayette.

Ask a homework question - tutors are online