ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
Lab 4 microcontroller
1. CENTRE OF DIPLOMA STUDIES
COMPUTER ADDED DESIGN LABORATORY
LABORATORY INSTRUCTION SHEET
DEK 3133
Subject Code and Name
MICROCONTROLLER
Experiment Code 04
Introduction to Keypad and LCD
Experiment Title program
Course Code DET/DEE/DEX
2. Document Reference
No. RPP-05 Page. Number Page |1
Edition 1
LABORATORY Revision No. 4
Document Title
PRACTICUM Effective Date 03/8/2010
Amendment Date 03/8/2010
SUBJECT INFORMATION
SUBJECT : DEK 3133 MICROCONTROLLER
TOPIC : Lab 4 – Introduction to Keypad and LCD program.
AIM To apply the knowledge and understanding on theory and applications of keypad.
1 OBJECTIVES
1.1 To understand the design of keypad.
1.2 To determine and analyze the function of keypad.
1.3 To understand the configuration of LCD.
2 EQUIPMENT
2.1 PIC Development Board – PICDEV
2.2 PIC16F877A
2.3 MPLAB IDE Program
2.4 Mikro C
2.5 Proteus
2.6 The PIC Development Board User manual
2.7 Power supply 9V
3 THEORY
3.1 KEYPAD SYSTEM
Keypads are an excellent way of entering data into the microcontroller. The keys are usually numbered but
they could be labeled as function keys, for example in a remote control handset in a TV to adjust the sound or
color, etc.
As well as remote controls, keypads find applications in burglar alarms, door entry system, calculators,
microwave ovens, etc. Keypads are usually arranged in a matrix format to reduce the number of I/O
connections. A 12 keypad is arranged in a 3 x 4 format requiring seven connections.
3. Document Reference
No. RPP-05 Page. Number Page |2
Edition 1
LABORATORY Revision No. 4
Document Title
PRACTICUM Effective Date 03/8/2010
Amendment Date 03/8/2010
This is arranged in three columns and four rows as shown in Table 1. There are seven connections to
the keypad – C1, C2, C3, R1, R2, R3 and R4.
Column1,C1 Column2,C2 Coulmn3,C3
Row1, R1 1 2 3
Row2, R2 4 5 6
Row3, R3 7 8 9
Row4, R4 * 0 #
Table 1
This connection to PIC is shown in Figure 1. The keypad works in the following way:
If, for example, key 6 is pressed then A3 will be joined to B5. For key 1, A1 would be joined to B4, etc. as
shown in Figure 1.
Port A [1:3] = output Port B [0:3] = output and Port B [4:7] = input
RA1
RA2 RB0
RA3
RB1
RB2
RB3
1 2 3 Row1 RB4
4 5 6 Row2 RB5
7 8 9 Row3 RB6
* 0 # Row4 RB7
Figure 1
The figure 1 above show the 4x3 keypad size which is 3 columns and 4 rows. To tell the PIC which button is
pressed, the PIC need to set only one of the column to be high at one time. Then the PIC will scan which row is
4. Document Reference
No. RPP-05 Page. Number Page |3
Edition 1
LABORATORY Revision No. 4
Document Title
PRACTICUM Effective Date 03/8/2010
Amendment Date 03/8/2010
at current column send the HIGH value (1) to the PIC input at PORTB. For example, Let say the PIC need to
recognize the buttons at column 1 which the available button are 1, 4, 7 and *. So the PIC will send the
PORTA.F1 (COLUMN 1) to HIGH (1). Then the PIC will scan each row of PORTB begin from PORTB.F4
(ROW 1). At this stage, if the scanned result is HIGH that means the pressed button is equal to 1. If the result is
LOW (0), then the PIC will continue to scan for the next row(ROW2, ROW3, and ROW4). When all rows at
PORTB are scanned, the PIC will send the HIGH (1) value to the next column (COLUMN 2 at PORTA.F2)
and repeat to scan each row of port B. This process is repeated to all columns. When the last column
(COLUMN3: PORTA.F3) is reached, PIC will scan again for all rows at column1, 2 and so on.
The value need to submit to the columns and read the rows value are actually can be vary. It depends on how
the keypad is designed.
3.2 LCD Display
Figure 2: 4 Bit Interface of 16x2 LCD
Figure 2 showing a Liquid Crystal Display (LCD) which is 16 x 2 characters. It has 4 bit interface data
(D4,D5,D6,D7) which is parallel connected to the PIC port.
5. Document Reference
No. RPP-05 Page. Number Page |4
Edition 1
LABORATORY Revision No. 4
Document Title
PRACTICUM Effective Date 03/8/2010
Amendment Date 03/8/2010
3.2.1 Pin Functions
Signal Function
Selects registers.
RS 0: Instruction register (for write) Busy flag:
address counter (for read)
1: Data register (for write and read)
Selects read or write.
R/W 0: Write
1: Read
E Starts data read/write.
Four high order bidirectional tristate data bus
pins. Used for data transfer and receive between
D4 to D7 the PIC and the LCD. DB7 can be used
as a busy flag.
VSS
Ground
VDD
Power
VEE
Contact with variable resistor to control the LCD contrast
6. Document Reference
No. RPP-05 Page. Number Page |5
Edition 1
LABORATORY Revision No. 4
Document Title
PRACTICUM Effective Date 03/8/2010
Amendment Date 03/8/2010
4 ATTENTION
4.1 Do not move any IC or device inside the board without any order from your instructor.
4.2 Make sure all jumpers on the development board are placed in correct positions.
5 EXPERIMENT PROCEDURE
5.1.1 The code below is shown how to scan the keypad buttons at column 1 (button 1, 4, 7 and
5.1 KEYPAD (See Circuit 1)
*). Pressed button will switch ON the LED base on the binary numbers of the button
location. Ie. Button no. 1 = 0001, button no. 4 = 0100, button no. 7 = 0111, and button * =
1111. Type the code below and test on the development board. Write your observation.
7. Document Reference
No. RPP-05 Page. Number Page |6
Edition 1
LABORATORY Revision No. 4
Document Title
PRACTICUM Effective Date 03/8/2010
Amendment Date 03/8/2010
5.2 Exercise 1 : Keypad
5.2.1 Base on the code above, complete the source code, so that the PIC can scan all the pressed
buttons and show it on LED as a binary value.
5.2.2 Draw a flow chart for the complete program.
5.3.1 The code below is a program to show texts in LCD 16x2. Type the code and test it on the
5.3 LCD Display (See Circuit 2)
development board or Proteus simulation. Write your observation on the report.
8. Document Reference
No. RPP-05 Page. Number Page |7
Edition 1
LABORATORY Revision No. 4
Document Title
PRACTICUM Effective Date 03/8/2010
Amendment Date 03/8/2010
5.4.1 Base on the circuit 2(see attachment). Write a program that will show a text “BUTTON IS
5.4 Exercise 2: LCD and Button(PORTA.F4)
PRESSED” on the LCD when the button at PORTA.F4 is pressed and show a text “BUTTON
IS NOT PRESSED” if the button at PORTA.F4 is not pressed.
5.4.2 Draw a flow chart for a complete program.
6 REPORT PREPARATION AND SCHEMA.
(1) 2 persons for 1 report.
(2) Due date to send report is 1 weeks after lab date.
(3) Report schema following below requirements:
Lab report cover sheet for 1st page.
Objective, theory, equipments for the 2nd page. (5) (5M)
Observations. (20)
1.Keypad observations from 5.1.1 (10 M)
2.LCD observations from 5.3.1 (10 M )
Result. (40)
1. Keypad: Exercise 1 source code & Flow Chart ( 20 M )
2. LCD: Exercise 2 source code & Flow Chart (20 M)
Discussion. (20)
1. By using all the PORT A and PORT B, what is the maximum buttons for PIC16F877A can support?
Draw a diagram to support your answer. (15 M)
2. Give the example of applications that using a keypad with PIC. (5 M)
9. Document Reference
No. RPP-05 Page. Number Page |8
Edition 1
LABORATORY Revision No. 4
Document Title
PRACTICUM Effective Date 03/8/2010
Amendment Date 03/8/2010
Conclusions. (15)
7 CIRCUIT ATTACMENT
Circuit 1: KEYPAD and LED
10. Document Reference
No. RPP-05 Page. Number Page |9
Edition 1
LABORATORY Revision No. 4
Document Title
PRACTICUM Effective Date 03/8/2010
Amendment Date 03/8/2010
Circuit 2: LCD with Button