PLT 206 MICROCONTROLLER SYSTEM LECTURE 4 INPUT AND

  • Slides: 43
Download presentation
PLT 206 MICROCONTROLLER SYSTEM LECTURE 4: INPUT AND OUPUT INTERFACING

PLT 206 MICROCONTROLLER SYSTEM LECTURE 4: INPUT AND OUPUT INTERFACING

Interfacing and Programming with Input/Output Device: Seven Segment A seven-segment display (SSD), or seven-segment

Interfacing and Programming with Input/Output Device: Seven Segment A seven-segment display (SSD), or seven-segment indicator, is a form of electronic display device for displaying decimal numerals that is an alternative to the more complex dot-matrix displays. Seven-segment displays are widely used in digital clocks, electronic meters, and other electronic devices for displaying numerical information A seven-segment display may have 7, 8, or 9 leads on the chip. Usually leads 8 and 9 are decimal points.

Interfacing and Programming with Input/Output Device: Seven Segment There are two types of displays

Interfacing and Programming with Input/Output Device: Seven Segment There are two types of displays available, common anode and common cathode. The common anode has all anodes joined together and goes to the positive supply. The cathodes are connected individually to ground, zero volts, or the negative supply. Each segment of the display needs a resistor to limit the currents through each segment to a safe value. The common cathode displays act the same and have all the cathodes joined too.

Interfacing and Programming with Input/Output Device: Seven Segment The light emitting diodes in a

Interfacing and Programming with Input/Output Device: Seven Segment The light emitting diodes in a seven-segment display are arranged in the figure below.

Interfacing and Programming with Input/Output Device: Seven Segment

Interfacing and Programming with Input/Output Device: Seven Segment

Interfacing and Programming with Input/Output Device: Seven Segment

Interfacing and Programming with Input/Output Device: Seven Segment

Interfacing and Programming with Input/Output Device: Seven Segment

Interfacing and Programming with Input/Output Device: Seven Segment

Interfacing and Programming with Input/Output Device: Seven Segment To convert the binary numbers to

Interfacing and Programming with Input/Output Device: Seven Segment To convert the binary numbers to signals that can drive the LEDs in the display, it is needed a display driver. In the lab use an MC 14511 chip. The pin-outs are shown below.

Interfacing and Programming with Input/Output Device: Seven Segment

Interfacing and Programming with Input/Output Device: Seven Segment

Interfacing and Programming with Input/Output Device: Seven Segment MC 14511 incorporates an input latch

Interfacing and Programming with Input/Output Device: Seven Segment MC 14511 incorporates an input latch so that it can hold and display a steady digit as part of a multi-digit count, while a new count is being accumulated in the background. The LE input shown to the right is the Latch Enable. A new number can only be accepted by this IC when the LE input is a logic 1. The main circuitry of this IC is the Decoder section. This section consists of combinational logic circuits to accept a fourbit BCD (Binary Coded Decimal) input and generate seven output signals to control the individual segments of a 7 -segment display device.

Interfacing and Programming with Input/Output Device: Seven Segment

Interfacing and Programming with Input/Output Device: Seven Segment

Interfacing and Programming with Input/Output Device: Seven Segment

Interfacing and Programming with Input/Output Device: Seven Segment

Interfacing and Programming with Input/Output Device: Seven Segment Example 1: Write a program and

Interfacing and Programming with Input/Output Device: Seven Segment Example 1: Write a program and create a circuit to count up decimal 0 to 9 using 7 -segment (common-cathode) for delay time is 1000 ms. Connect each cathode to RD 0, RD 1, RD 2, RD 3, RD 4, RD 5, and RD 6 of a microcontroller PIC 16 F 877 A. When the microcontroller on, the 7 -segment will count up the decimal 0 to 9. The decimal number will be off when the microcontroller off.

Interfacing and Programming with Input/Output Device: Seven Segment Example 1 - Solution

Interfacing and Programming with Input/Output Device: Seven Segment Example 1 - Solution

Interfacing and Programming with Input/Output Device: Seven Segment

Interfacing and Programming with Input/Output Device: Seven Segment

Interfacing and Programming with Input/Output Device: Seven Segment

Interfacing and Programming with Input/Output Device: Seven Segment

Interfacing and Programming with Input/Output Device: Seven Segment Example 2: Write a program and

Interfacing and Programming with Input/Output Device: Seven Segment Example 2: Write a program and create a circuit to count down decimal 9 to 0 using 7 -segment (common-cathode) for delay time is 1000 ms. Connect each cathode to RD 1, RD 2, RD 3, RD 4, RD 5, and RD 6 of a microcontroller PIC 16 F 877 A. When the microcontroller on, the 7 -segment will count down the decimal 9 to 0. The decimal number will be off when the microcontroller off.

Interfacing and Programming with Input/Output Device: Seven Segment Example 2 - Solution

Interfacing and Programming with Input/Output Device: Seven Segment Example 2 - Solution

Interfacing and Programming with Input/Output Device: Seven Segment

Interfacing and Programming with Input/Output Device: Seven Segment

Interfacing and Programming with Input/Output Device: Seven Segment

Interfacing and Programming with Input/Output Device: Seven Segment

Interfacing and Programming with Input/Output Device: Seven Segment Example 3: Write a program and

Interfacing and Programming with Input/Output Device: Seven Segment Example 3: Write a program and create a circuit to count up decimal 0 to 9 if a switch 1 is pushed and count down decimal 9 to 0 if a switch 2 is pushed using 7 segment (common-catohde) for delay time is 1000 ms. Connect each cathode to RD 1, RD 2, RD 3, RD 4, RD 5, and RD 6 of a microcontroller PIC 16 F 877 A.

Interfacing and Programming with Input/Output Device: Seven Segment

Interfacing and Programming with Input/Output Device: Seven Segment

Interfacing and Programming with Input/Output Device: Seven Segment

Interfacing and Programming with Input/Output Device: Seven Segment

Interfacing and Programming with Input/Output Device: Seven Segment

Interfacing and Programming with Input/Output Device: Seven Segment

Interfacing and Programming with Input/Output Device: Seven Segment

Interfacing and Programming with Input/Output Device: Seven Segment

LECTURE 4: INPUT AND OUPUT INTERFACING 4 x 4 Matix Keypad

LECTURE 4: INPUT AND OUPUT INTERFACING 4 x 4 Matix Keypad

Objectives Explain the basic operation of a keypad. Describe the key press and detection

Objectives Explain the basic operation of a keypad. Describe the key press and detection mechanisms. Interface a keypad to the PIC 16 F 877 A microcontroller.

Keypad Interfacing Keypad or keyboards are the most widely used I/O devices. Most of

Keypad Interfacing Keypad or keyboards are the most widely used I/O devices. Most of microcontroller applications require a keypad for users to enter numbers and commands. A matrix keypad provides a simple data entry device for microcontroller systems.

Basic Operation Organized in a matrix of rows and columns. Consists of an array

Basic Operation Organized in a matrix of rows and columns. Consists of an array of momentary pushbuttons switch or key. There are 4 column lines and 4 row lines. Each pushbutton has two terminals; one is connected to a column line and other to a row line. Internal Connection of a 4 x 4 Internal Structure of 4 x 4 Matrix Keypad.

Basic Operation Initially, there are not direct connection between row and column. When a

Basic Operation Initially, there are not direct connection between row and column. When a key is pressed, the adjacent row and column are connected, thus a row and column make a contact; otherwise there is no connection between rows and columns. For example if key ‘ 8’ is pressed, Row 3 and Column 2 will connect to each other.

Key Press and Detection Mechanisms In programming there are 2 processes: Key press detection

Key Press and Detection Mechanisms In programming there are 2 processes: Key press detection Interrupt method Scanning method – only this method will be covered Key identification

Scanning Method for Key Press Detection To read data from keypad (if the keypad

Scanning Method for Key Press Detection To read data from keypad (if the keypad is directly connected to MCU), the scanning method is used. The scanning is a process of checking all lines one by one. In this case, if we make row lines low/high one by one and then read the columns, we will be able to detect which key is pressed. To read the keypad, each row is set LOW in turn and the state of the inputs tested. If no button is pressed, all the inputs remain high. When a key is operated, a LOW on that row is detected on the column input for that key, which allows a corresponding code to be generated. This is a binary number or ASCII code, as required by the particular application. We can also make column lines low/high and then read the row to detect which switch is pressed

Scanning Method for Key Press Detection As example: If Row 1 is set to

Scanning Method for Key Press Detection As example: If Row 1 is set to LOW, when switch 3 is pressed, the Column 3 will become LOW

Flowchart for Scanning Method To detect a pressed key, the microcontroller grounds all rows

Flowchart for Scanning Method To detect a pressed key, the microcontroller grounds all rows by providing 0 to the output latch, then it reads the columns. If the data read from the columns are equal to 1111, no key has been pressed, and the process continues until a key press has occurred. If one of the column bits has a zero, this means that a key press has occurred. After a key press is detected, the microcontroller will go through the process of identifying the key.

Flowchart for Scanning Method Starting with the top row, the microcontroller grounds it by

Flowchart for Scanning Method Starting with the top row, the microcontroller grounds it by providing a LOW to the first row only; then it reads the columns. If the data read is all 1 s, no key in that row is activated and the process is moved to the next row. It grounds the next row, reads the columns, and checks for any zero. This process continues until the row is identified. After identification of the row in which the key has been pressed, the next task is to find out which column the pressed key belongs to. This should be easy since the microcontroller knows at any time which

Keypad Interfacing – PTK 40 A Schematic Keypad can directly being connected to MCU

Keypad Interfacing – PTK 40 A Schematic Keypad can directly being connected to MCU or used keypad decoder IC. MCU accesses both rows and columns through ports; therefore with two 8 -bit ports, an 8 x 8 matrix of keys can be connected to a microcontroller.

Keypad Interfacing – PTK 40 A Schematic The keypad’s pins need to be pulled

Keypad Interfacing – PTK 40 A Schematic The keypad’s pins need to be pulled up or pulled down to avoid floating cases Pull up is normally connect to 5 V Pull down is connect to ground.

Keypad Interfacing – PTK 40 A Schematic 4 x 4 matrix keypad connected to

Keypad Interfacing – PTK 40 A Schematic 4 x 4 matrix keypad connected to PORTB and PORTD Rows PORTD. High (RD 7 - RD 4) Columns PORTB. Low (RB 3 RB 0)

Keyboard Debounce Noise Stable

Keyboard Debounce Noise Stable

Keypad Programming Make rows as output and columns as input. For example: set (5

Keypad Programming Make rows as output and columns as input. For example: set (5 V, HIGH logic) all rows by default. For 1 st scan, clear (logic LOW) Row 1 and scan Column 1 to Column 4 (‘ 1’, ‘ 2’, ‘ 3’ and ‘A’) for LOW logic , this will determine which button is pressed in Row 1. If one of those buttons is pressed, record it and jump out from the scanning loop and continue with the action required. If none button is pressed in Row 1, set it back to default (logic high). Clear Row 2. Scan Column 1 to Column 4 again and this will scan button press of ‘ 4’, ‘ 5’, ‘ 6’ and ‘B’ for LOW logic. And this process should be repeated until all four rows are being completed scanned.

Keypad Programming Steps (based on in Slide 4, 11, 15): Make Row 1 =

Keypad Programming Steps (based on in Slide 4, 11, 15): Make Row 1 = 0 Delay Check every column If Column 1 = 0, return ‘ 1’ If Column 2 = 0, return ‘ 2’ If Column 3 = 0, return ‘ 3’ If Column 4 = 0, return ‘A’ The process continue by making Row 2, Row 3, and Row 4 low one by one and then check the column.

Keypad Programming (continued) unsigned char Read_Keypad() { KP_R 1 = 0; //make Row 1=0

Keypad Programming (continued) unsigned char Read_Keypad() { KP_R 1 = 0; //make Row 1=0 KP_R 2 = 1; //the rest =1 KP_R 3 = 1; KP_R 4 = 1; __delay_us(30); if(KP_C 1==0) PORTD=0 b 00000001; //return ‘ 1’ (return pressed key value) if(KP_C 2==0) PORTD=0 b 00000010; //return ‘ 2’ if(KP_C 3==0) PORTD=0 b 00000011; // return ‘ 3’ if(KP_C 4==0) PORTD=0 b 00001010; // return ‘blank’; return 0 x. FF; //indicates nothing being pressed } //the process continues for Row 2, Row 3 and Row 4

End of Chapter “I hear and I forget. I see and I remember. I

End of Chapter “I hear and I forget. I see and I remember. I do and I understand”