Presentation is loading. Please wait.

Presentation is loading. Please wait.

Peripherals – Keypad The Keypad provides a simple means of numerical data or control input. The keys can be attributed whatever data or control values.

Similar presentations


Presentation on theme: "Peripherals – Keypad The Keypad provides a simple means of numerical data or control input. The keys can be attributed whatever data or control values."— Presentation transcript:

1 Peripherals – Keypad The Keypad provides a simple means of numerical data or control input. The keys can be attributed whatever data or control values are needed in a particular application (e.g. setting clock values, entering an alarm code, etc.). The Keypad has 12 buttons arranged in a 4 Row * 3 Column Matrix: C0 C1 C2 R R R R3 * 0 # Interface connections Port bit: Keypad signal: N/C R0 R1 R2 R3 C0 C1 C2 Connector pin 0 Column Row 1 2 3 1 Embedded Systems Programming II Richard Anthony, Computer Science, The University of Greenwich

2 Peripherals – Keypad (continued)
Operation: When a key is pressed, the corresponding row and column signals are connected (according to the matrix). Reading (scanning) the keypad requires: Set the port so that row pins are outputs and column pins are inputs. Use ‘pullup resistors’ to make each column read as a ‘1’ when no key is pressed (i.e. set the pullup resistors ‘on’ on the column bits of the port). (Without the ‘pullup resistors’ the signal lines ‘float’ between 0 and 5 volts and thus can read as either a ‘1’ or ‘0’, i.e. they are unpredictable). For one row at a time, set the output bit to ‘0’, while setting the other row bits to ‘1’. Read all column inputs and check to see if there are any with a ‘0’ value. This indicates that the key where the column crosses the current ‘0’ value row (in step 3) is pressed (otherwise they are pulled high and read as ‘1’). Cycle through steps 3 and 4 for all rows. After a key-press is detected, wait a short time to allow for mechanical bouncing of the key contacts before reading the keypad again (this is called the ‘debounce delay’ – typically between 20 and 100 milliseconds). 2 Embedded Systems Programming II Richard Anthony, Computer Science, The University of Greenwich

3 indicate if a ‘special’ key
Peripherals – Keypad – A simple demonstration program A simple keyboard demonstration program is available on the course website. The program shows how to set the port for mixed input and output, how to set the pullup resistors, and how to do the row / column scanning. The connection of the keypad, and the output when the ‘5’ key is pressed is shown below. These bits show which key was pressed indicate if a ‘special’ key was pressed (‘*’ ‘0’ ‘#’) 3 Embedded Systems Programming II Richard Anthony, Computer Science, The University of Greenwich

4 indicate if a ‘special’ key
Peripherals – Keypad – Simple demonstration program (continued) The output when the ‘0’ key is pressed is shown below. (The keys * 0 # are implemented as special keys for illustration of the concept of control keys which have specific handler routines). The ‘special key’ indicator for ‘0’ is illuminated, as well as the key-code value (1011 binary = B hex = 11 decimal). These bits indicate if a ‘special’ key was pressed (‘*’ ‘0’ ‘#’) show which key was pressed 4 Embedded Systems Programming II Richard Anthony, Computer Science, The University of Greenwich

5 Peripherals – Liquid Crystal Display (LCD)
The LCD provides a versatile means of displaying alphanumeric data and messages (such as error codes, status messages, and user instructions). The LCD can display 2 rows of 16 characters. The cursor can be turned on / off and positioned wherever required. The system clock must be set to 1MHz (set via ‘fuses’) because of timing constraints of the LCD. Fit the LCD via the dedicated connector on the edge of the STK300 board and make sure it is the same way around as shown. LCD display panel 5 Embedded Systems Programming II Richard Anthony, Computer Science, The University of Greenwich

6 Peripherals – Liquid Crystal Display (LCD)
The LCD is a quite complex peripheral, with its own on-board controller chip (With registers, memory, special command modes etc. Retains data in between data / control inputs). In addition to 8-bit data (Port A, output); there are also various control signals that must be set: ‘Register Select’ Port C bit 6, Low to access command register High to access data register ‘Device Enable’ Port C bit 7, Low to disable LCD, High to enable LCD ‘Write’ Port G bit 0, for write (command or data) ‘Read’ Port G bit 1, for read (command or data) ‘Busy Flag’ Port A bit 7, (from the control register, not data) To access, this bit must be set for input in DDRA and Register Select must be ‘low’ 6 Embedded Systems Programming II Richard Anthony, Computer Science, The University of Greenwich

7 Peripherals – Liquid Crystal Display (LCD) - Continued
To simplify using the LCD, a library of commonly needed subroutines has been provided (see teachmat). The subroutines provide functions such as: Check if the LCD device is busy, if so wait. Output a function command to the LCD. Clear the LCD display and set the cursor to the 'home' position. Set the cursor to a specific display position. Write a data character to the LCD at the current cursor position. Display a 2-bar bar graph on the LCD. 7 Embedded Systems Programming II Richard Anthony, Computer Science, The University of Greenwich

8 Peripherals – Liquid Crystal Display (LCD) - Continued
The LCD has a 256 symbol character set: Place this code in the upper 4 bits in the lower 4 bits For example ‘£’ has the code:0xA5 8 Embedded Systems Programming II Richard Anthony, Computer Science, The University of Greenwich

9 Peripherals – Liquid Crystal Display (LCD) - Continued
The second half of the character set: 9 Embedded Systems Programming II Richard Anthony, Computer Science, The University of Greenwich

10 Peripherals – LCD A simple demonstration program has been provided, showing how to display a message (stored in program memory) on the LCD. The use of the ‘include’ file, and the library subroutines with in it is illustrated. The demonstration program also shows how to use special characters, in addition to standard ASCII alpha-numeric values. 10 Embedded Systems Programming II Richard Anthony, Computer Science, The University of Greenwich


Download ppt "Peripherals – Keypad The Keypad provides a simple means of numerical data or control input. The keys can be attributed whatever data or control values."

Similar presentations


Ads by Google