SlideShare a Scribd company logo
1 of 22
Download to read offline
BEKM 3453
Microcontroller
Technology
PIC module –
LCD Interfacing
Learning Outcomes
1. Explain the basic concept of Liquid Crystal Display (LCD)
2. Interface the LCD with a microcontroller
3. Explain the basic concept of Keypad
4. Interface the keypad with a microcontroller
Some LCD Examples
What are Alphanumeric LCDs?
• Alphanumeric LCD can display alphabet and numbers
• Graphic LCD can display shapes (e.g. Laptop screen)
Alphabets
(A,B, h,e,k,!)
Numerics
(0,1,2,3,…,9)
Types of LCDs
• Alphanumeric LCDs have Columns and Rows
• i.e 16 x 2 LCD has 16 characters (column) maximum in one line, total 2 lines (rows)
• LCD used in
With backlight
Without backlight
Color
16
2
Capability of LCDs
• Alphanumeric LCD can display a large
number of characters and symbols
• Based on the maximum Columns x Rows,
these characters can be displayed
simultaneously
• I.e. 16 x 2 LCD  total of 32 characters
can be displayed at one time
LCD pins
• Most LCDs use Hitachi 44780 based
character LCD
• Has 14 pins; 3 control, 3 for supply, ground,
contrast and 8 for 8 bit data
• RS = set register (instruction or data)
• RW = read/write mode; 0 -> Write to LCD
• E = enable signal
• Some LCD has 16 pins, and two Hitachi
44780 controllers, extra 2 pins for backlight
(Vcc, Gnd)
LCD connections (4bit)
• LCD library
• 3 pins [Vdd (supply), Vss (ground),
Vee (contrast)]
• 3 pins (RS – register Select, RW –
read/write, EN – enable )
• 4 pins for data bus
Program (4bit)
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D7 at RB3_bit;
sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;;
Declare LCD Connections
char txt1[] = "Microcontroller";
char txt2[] = "Technology";
char txt3[] = "3BEKM";
char txt4[] = "2022/2023";;
Declare Texts to display
Program (4bit)
void main(){
TRISB = 0;
PORTB = 0;
Lcd_Init();
Initialize Ports and LCD
Lcd_Cmd(_LCD_CLEAR);
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Out(1,6,txt3);
Clear LCD, write txt3 contents
while(1)
{
Lcd_Out(2,6,txt4);
Delay_ms(2000);
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,1,txt1);
Lcd_Out(2,5,txt2);
Delay_ms(1000);
}
}
Loop: Display different text
Simulation (Assemble Circuit)
Simulation (Run program)
Displaying numbers
value = 9999;
• Assign the number to be displayed
WordToStr ( value, txt1);
• Converts the value into string (text)
LCD_Out ( 1, 1, txt1)
• Displays the text at row 1, column 1
Keypad
Keypad is an array of switches where 2 wires are
connected each time a button is pressed
The keypad pins need to be pulled up or pulled
down to avoid floating cases
The connections depend on the keypad matrix
Rows and Columns.
(4 x 4  8, 4 x 3  7) 8 connections
Column
pins
Row
pins
Keypad examples
4 x 3 keypad
4 x 4 keypad
4 x 4 membrane keypad
Keypad connections
7 pins for 4 x 3 keypad, 8 pins for 4 x
4 keypad
Needs pull down resistors for pins
Using voltage divider on the keypad
to PIC input
Column connected to PIC as input
and Row connected as output
Keypad library
Initialization
Char keypadPort at PORTD;
Keypad_init();
Detecting key click
char kp;
kp = Keypad_Key_Click();
Detecting key pressed
char kp;
kp = Keypad_Key_Press();
Program (Keypad, LCD)
unsigned short kp, cnt, oldstate = 0;
char txt[6];
char keypadPort at PORTD;
// LCD module connections
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D7 at RB3_bit;
sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;
// End LCD module connections
Declare LCD Connections
Declare PORT for keypad
Program (Keypad, LCD)
Declare count, PORTS,
LCD, Keypad
void main() {
cnt = 0;
TRISB = 0; TRISD = 0xFF;
Keypad_Init();
LCD_Init();
Lcd_Cmd(_LCD_CLEAR);
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Out(1, 1, "Key :");
Lcd_Out(2, 1, "Times:");
while(1)
{
kp = 0;
do
kp = Keypad_Key_Press();
while (!kp);
switch (kp) {
case 1: kp = 49; break; // 1
case 2: kp = 50; break; // 2
case 3: kp = 51; break; // 3
Detect a Key Pressed?
switch (kp) {
case 1: kp = 49; break; // 1
case 2: kp = 50; break; // 2
case 3: kp = 51; break; // 3
case 4: kp = 65; break; // A
case 5: kp = 52; break; // 4
case 6: kp = 53; break; // 5
case 7: kp = 54; break; // 6
case 8: kp = 66; break; // B
case 9: kp = 55; break; // 7
case 10: kp = 56; break; // 8
case 11: kp = 57; break; // 9
case 12: kp = 67; break; // C
case 13: kp = 42; break; // *
case 14: kp = 48; break; // 0
case 15: kp = 35; break; // #
case 16: kp = 68; break; // D
}
Program (Keypad, LCD)
Detect key (Read KP input)
16 possibilities (keys)
Program (Keypad, LCD)
if (kp != oldstate)
{
cnt = 1;
oldstate = kp;
}
else cnt++;
Lcd_Chr(1, 10, kp);
if (cnt == 255)
{
cnt = 0;
Lcd_Out(2, 10, " ");
}
WordToStr(cnt, txt);
Lcd_Out(2, 10, txt };
}
Display key pressed on LCD
Convert cnt to string and
display on LCD (2nd row)
Simulation (Keypad and LCD)

More Related Content

Similar to 2022-BEKM 3453 - LCD and keypad.pdf

Moving message display
Moving message displayMoving message display
Moving message displayviraj1989
 
Microcontroller Programming Assignment
Microcontroller Programming AssignmentMicrocontroller Programming Assignment
Microcontroller Programming Assignmentbabak danyal
 
Embedded systems design @ defcon 2015
Embedded systems design @ defcon 2015Embedded systems design @ defcon 2015
Embedded systems design @ defcon 2015Rodrigo Almeida
 
m.tech esd lab manual for record
m.tech esd lab manual for recordm.tech esd lab manual for record
m.tech esd lab manual for recordG Lemuel George
 
Embedded Systems Project 3rd Year
Embedded Systems Project 3rd YearEmbedded Systems Project 3rd Year
Embedded Systems Project 3rd YearAndrew Kozik
 
Automatic room light controller with visible counter
Automatic room light controller with visible counterAutomatic room light controller with visible counter
Automatic room light controller with visible counterMafaz Ahmed
 
Water Level Indicator using 8051 Microcontroller.pptx
Water Level Indicator using 8051 Microcontroller.pptxWater Level Indicator using 8051 Microcontroller.pptx
Water Level Indicator using 8051 Microcontroller.pptxshayanzafar2
 
Functions for Nano 5 Card
Functions for Nano 5 CardFunctions for Nano 5 Card
Functions for Nano 5 CardOmar Sanchez
 
Calculator design with lcd using fpga
Calculator design with lcd using fpgaCalculator design with lcd using fpga
Calculator design with lcd using fpgaHossam Hassan
 
Embedded systems development Defcon 19
Embedded systems development Defcon 19Embedded systems development Defcon 19
Embedded systems development Defcon 19Rodrigo Almeida
 

Similar to 2022-BEKM 3453 - LCD and keypad.pdf (20)

Moving message display
Moving message displayMoving message display
Moving message display
 
Microcontroller Programming Assignment
Microcontroller Programming AssignmentMicrocontroller Programming Assignment
Microcontroller Programming Assignment
 
Microcontroller part 4
Microcontroller part 4Microcontroller part 4
Microcontroller part 4
 
Embedded systems design @ defcon 2015
Embedded systems design @ defcon 2015Embedded systems design @ defcon 2015
Embedded systems design @ defcon 2015
 
m.tech esd lab manual for record
m.tech esd lab manual for recordm.tech esd lab manual for record
m.tech esd lab manual for record
 
Embedded Systems Project 3rd Year
Embedded Systems Project 3rd YearEmbedded Systems Project 3rd Year
Embedded Systems Project 3rd Year
 
PIC and LCD
PIC and LCDPIC and LCD
PIC and LCD
 
Interfacing with LCD
Interfacing with LCDInterfacing with LCD
Interfacing with LCD
 
Automatic room light controller with visible counter
Automatic room light controller with visible counterAutomatic room light controller with visible counter
Automatic room light controller with visible counter
 
Water Level Indicator using 8051 Microcontroller.pptx
Water Level Indicator using 8051 Microcontroller.pptxWater Level Indicator using 8051 Microcontroller.pptx
Water Level Indicator using 8051 Microcontroller.pptx
 
Functions for Nano 5 Card
Functions for Nano 5 CardFunctions for Nano 5 Card
Functions for Nano 5 Card
 
report cs
report csreport cs
report cs
 
Password based door locksystem
Password  based door locksystemPassword  based door locksystem
Password based door locksystem
 
Lcd interfacing1
Lcd interfacing1Lcd interfacing1
Lcd interfacing1
 
08_lcd.pdf
08_lcd.pdf08_lcd.pdf
08_lcd.pdf
 
Lab Activity 3
Lab Activity 3Lab Activity 3
Lab Activity 3
 
Calculator design with lcd using fpga
Calculator design with lcd using fpgaCalculator design with lcd using fpga
Calculator design with lcd using fpga
 
LCD Keypad Shield
LCD Keypad ShieldLCD Keypad Shield
LCD Keypad Shield
 
Arduino: Arduino lcd
Arduino: Arduino lcdArduino: Arduino lcd
Arduino: Arduino lcd
 
Embedded systems development Defcon 19
Embedded systems development Defcon 19Embedded systems development Defcon 19
Embedded systems development Defcon 19
 

Recently uploaded

Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxUnboundStockton
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxEyham Joco
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentInMediaRes1
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitolTechU
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
MICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptxMICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptxabhijeetpadhi001
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxAvyJaneVismanos
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.arsicmarija21
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupJonathanParaisoCruz
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 

Recently uploaded (20)

Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docx
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptx
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media Component
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptx
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
MICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptxMICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptx
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptx
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized Group
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 

2022-BEKM 3453 - LCD and keypad.pdf

  • 2. Learning Outcomes 1. Explain the basic concept of Liquid Crystal Display (LCD) 2. Interface the LCD with a microcontroller 3. Explain the basic concept of Keypad 4. Interface the keypad with a microcontroller
  • 4. What are Alphanumeric LCDs? • Alphanumeric LCD can display alphabet and numbers • Graphic LCD can display shapes (e.g. Laptop screen) Alphabets (A,B, h,e,k,!) Numerics (0,1,2,3,…,9)
  • 5. Types of LCDs • Alphanumeric LCDs have Columns and Rows • i.e 16 x 2 LCD has 16 characters (column) maximum in one line, total 2 lines (rows) • LCD used in With backlight Without backlight Color 16 2
  • 6. Capability of LCDs • Alphanumeric LCD can display a large number of characters and symbols • Based on the maximum Columns x Rows, these characters can be displayed simultaneously • I.e. 16 x 2 LCD  total of 32 characters can be displayed at one time
  • 7. LCD pins • Most LCDs use Hitachi 44780 based character LCD • Has 14 pins; 3 control, 3 for supply, ground, contrast and 8 for 8 bit data • RS = set register (instruction or data) • RW = read/write mode; 0 -> Write to LCD • E = enable signal • Some LCD has 16 pins, and two Hitachi 44780 controllers, extra 2 pins for backlight (Vcc, Gnd)
  • 8. LCD connections (4bit) • LCD library • 3 pins [Vdd (supply), Vss (ground), Vee (contrast)] • 3 pins (RS – register Select, RW – read/write, EN – enable ) • 4 pins for data bus
  • 9. Program (4bit) sbit LCD_RS at RB4_bit; sbit LCD_EN at RB5_bit; sbit LCD_D4 at RB0_bit; sbit LCD_D5 at RB1_bit; sbit LCD_D6 at RB2_bit; sbit LCD_D7 at RB3_bit; sbit LCD_RS_Direction at TRISB4_bit; sbit LCD_EN_Direction at TRISB5_bit; sbit LCD_D4_Direction at TRISB0_bit; sbit LCD_D5_Direction at TRISB1_bit; sbit LCD_D6_Direction at TRISB2_bit; sbit LCD_D7_Direction at TRISB3_bit;; Declare LCD Connections char txt1[] = "Microcontroller"; char txt2[] = "Technology"; char txt3[] = "3BEKM"; char txt4[] = "2022/2023";; Declare Texts to display
  • 10. Program (4bit) void main(){ TRISB = 0; PORTB = 0; Lcd_Init(); Initialize Ports and LCD Lcd_Cmd(_LCD_CLEAR); Lcd_Cmd(_LCD_CURSOR_OFF); Lcd_Out(1,6,txt3); Clear LCD, write txt3 contents while(1) { Lcd_Out(2,6,txt4); Delay_ms(2000); Lcd_Cmd(_LCD_CLEAR); Lcd_Out(1,1,txt1); Lcd_Out(2,5,txt2); Delay_ms(1000); } } Loop: Display different text
  • 13. Displaying numbers value = 9999; • Assign the number to be displayed WordToStr ( value, txt1); • Converts the value into string (text) LCD_Out ( 1, 1, txt1) • Displays the text at row 1, column 1
  • 14. Keypad Keypad is an array of switches where 2 wires are connected each time a button is pressed The keypad pins need to be pulled up or pulled down to avoid floating cases The connections depend on the keypad matrix Rows and Columns. (4 x 4  8, 4 x 3  7) 8 connections Column pins Row pins
  • 15. Keypad examples 4 x 3 keypad 4 x 4 keypad 4 x 4 membrane keypad
  • 16. Keypad connections 7 pins for 4 x 3 keypad, 8 pins for 4 x 4 keypad Needs pull down resistors for pins Using voltage divider on the keypad to PIC input Column connected to PIC as input and Row connected as output
  • 17. Keypad library Initialization Char keypadPort at PORTD; Keypad_init(); Detecting key click char kp; kp = Keypad_Key_Click(); Detecting key pressed char kp; kp = Keypad_Key_Press();
  • 18. Program (Keypad, LCD) unsigned short kp, cnt, oldstate = 0; char txt[6]; char keypadPort at PORTD; // LCD module connections sbit LCD_RS at RB4_bit; sbit LCD_EN at RB5_bit; sbit LCD_D4 at RB0_bit; sbit LCD_D5 at RB1_bit; sbit LCD_D6 at RB2_bit; sbit LCD_D7 at RB3_bit; sbit LCD_RS_Direction at TRISB4_bit; sbit LCD_EN_Direction at TRISB5_bit; sbit LCD_D4_Direction at TRISB0_bit; sbit LCD_D5_Direction at TRISB1_bit; sbit LCD_D6_Direction at TRISB2_bit; sbit LCD_D7_Direction at TRISB3_bit; // End LCD module connections Declare LCD Connections Declare PORT for keypad
  • 19. Program (Keypad, LCD) Declare count, PORTS, LCD, Keypad void main() { cnt = 0; TRISB = 0; TRISD = 0xFF; Keypad_Init(); LCD_Init(); Lcd_Cmd(_LCD_CLEAR); Lcd_Cmd(_LCD_CURSOR_OFF); Lcd_Out(1, 1, "Key :"); Lcd_Out(2, 1, "Times:"); while(1) { kp = 0; do kp = Keypad_Key_Press(); while (!kp); switch (kp) { case 1: kp = 49; break; // 1 case 2: kp = 50; break; // 2 case 3: kp = 51; break; // 3 Detect a Key Pressed?
  • 20. switch (kp) { case 1: kp = 49; break; // 1 case 2: kp = 50; break; // 2 case 3: kp = 51; break; // 3 case 4: kp = 65; break; // A case 5: kp = 52; break; // 4 case 6: kp = 53; break; // 5 case 7: kp = 54; break; // 6 case 8: kp = 66; break; // B case 9: kp = 55; break; // 7 case 10: kp = 56; break; // 8 case 11: kp = 57; break; // 9 case 12: kp = 67; break; // C case 13: kp = 42; break; // * case 14: kp = 48; break; // 0 case 15: kp = 35; break; // # case 16: kp = 68; break; // D } Program (Keypad, LCD) Detect key (Read KP input) 16 possibilities (keys)
  • 21. Program (Keypad, LCD) if (kp != oldstate) { cnt = 1; oldstate = kp; } else cnt++; Lcd_Chr(1, 10, kp); if (cnt == 255) { cnt = 0; Lcd_Out(2, 10, " "); } WordToStr(cnt, txt); Lcd_Out(2, 10, txt }; } Display key pressed on LCD Convert cnt to string and display on LCD (2nd row)