SlideShare uma empresa Scribd logo
1 de 4
#include<reg51.h>
#define port P1;
#define dataport P2;
#define key P0 ;
void lcd_data_str(unsigned char *str);
void lcd(unsigned char str[10]);
void lcd_data(unsigned char item1);
void display(int a);
void lcd_cmd(unsigned char item);
void chek_col1();
void chek_col2();
void chek_col3();
void chek_col4();
void delay(unsigned int m);
sbit rs=port^1;
sbit rw=port^2;
sbit en=port^3;
sbit row1=key^0;
sbit row2=key^1;
sbit row3=key^2;
sbit row4=key^3;
sbit col1=key^4;
sbit col2=key^5;
sbit col3=key^6;
sbit col4=key^7;
//Main program

void main()
{
lcd_cmd(0x01);
lcd_data_str("welcome");
col1=col2=col3=col4=1;
while(1)
{
row1=row2=row3=row4=0;
if(col1==0)
chek_col1();
else if (col2==0)
chek_col2();
else if(col3==0)
chek_col3();
else
chek_col4();
}
}

//Function to decide the key pressed in col1
void chek_col1()
{
row1=row2=row3=row4=1;
row1=0;
if(col1==0)
display(1);
row1=1;
row2=0;
if(col1==0)
display(5);
row2=1;
row3=0;
if(col1==0)
display(9);
row3=1;
row4=0;
if(col1==0)
display(13);
row4=1;
}




//Function to decide the key pressed in col2
void chek_col2()
{
row1=row2=row3=row4=1;
row1=0;
if(col2==0)
display(2);
row1=1;
row2=0;
if(col2==0)
display(6);
row2=1;
row3=0;
if(col2==0)
display(10);
row3=1;
row4=0;
if(col2==0)
display(14);
row4=1;
}

//Function to decide the key pressed in col3

void chek_col3()
{
row1=row2=row3=row4=1;
row1=0;
if(col3==0)
display(3);
row1=1;
row2=0;
if(col3==0)
display(7);
row2=1;
row3=0;
if(col3==0)
display(11);
row3=1;
row4=0;
if(col3==0)
display(15);
row4=1;

}

//Function to decide the key pressed in col4
void chek_col4()
{
row1=row2=row3=row4=1;
row1=0;
if(col4==0)
display(4);
row1=1;
row2=0;
if(col4==0)
display(8);
row2=1;
row3=0;
if(col4==0)
display(12);
row3=1;
row4=0;
if(col4==0)
display(16);
row4=1;
}

//Function to send Command to LCD
void lcd_cmd(unsigned char item)
{
dataport=item;
rs=0;
rw=0;
en=1;
delay(1);
en=0;
return;
}
//Function to send Data to LCD
void lcd_data(unsigned char item1)
{
dataport=item1;
rs=1;
rw=0;
en=1;
delay(1);
en=0;
return;
}



// Function to send string to lcd_data
void lcd_data_str(unsigned char *str)
{
int i=0;
while(str[i]!='0')
{
lcd_data(str[i]);
i++;
delay(10);
}
return;
}

//Function to initialize the LCD
void lcd(unsigned char str[10])
{
lcd_cmd(0x38);
lcd_cmd(0x0E);
lcd_cmd(0x01);
lcd_cmd(0x82);
lcd_data_str(str);
}

//Function to send the string to be displayed

void display(int a)
{
switch(a)
{
case 1:lcd("One :1");
break;
case 2:lcd("Two :2");
break;
case 3:lcd("Three :3");
break;
case 4:lcd("Four :4");
break;
case 5:lcd("Five :5");
break;
case 6:lcd("Six :6");
break;
case 7:lcd("Seven :7");
break;
case 8:lcd("Eight :8");
break;
case 9:lcd("Nine :9");
break;
case 10:lcd("Ten :10");
break;
case 11:lcd("Eleven :11");
break;
case 12:lcd("Twelve :12");
break;
case 13:lcd("Thirteen :13");
break;
case 14:lcd("Fourteen :14");
break;
case 15:lcd("Fifteen :15");
break;
case 16:lcd("sixteen :16");
break;
default:lcd("others");
break;
}
}

//Delay Function
void delay(unsigned int m )
{
int i,j;
for(i=0;i<m;i++)
for(j=0;j<1275;j++);
}

Result:

Mais conteúdo relacionado

Mais procurados

Day4 順序控制的循序邏輯實現
Day4 順序控制的循序邏輯實現Day4 順序控制的循序邏輯實現
Day4 順序控制的循序邏輯實現
Ron Liu
 
Unit 1 ocs752 introduction to c programming
Unit 1 ocs752 introduction to c programmingUnit 1 ocs752 introduction to c programming
Unit 1 ocs752 introduction to c programming
vrgokila
 
Programme en C: Additionneur complet 4 bits ac4
Programme en C: Additionneur  complet 4 bits ac4Programme en C: Additionneur  complet 4 bits ac4
Programme en C: Additionneur complet 4 bits ac4
ilham ait hsain
 

Mais procurados (20)

Vcs15
Vcs15Vcs15
Vcs15
 
Dam gate open close lpc prog
Dam gate open close lpc progDam gate open close lpc prog
Dam gate open close lpc prog
 
گزارش کار
گزارش کارگزارش کار
گزارش کار
 
Day4 順序控制的循序邏輯實現
Day4 順序控制的循序邏輯實現Day4 順序控制的循序邏輯實現
Day4 順序控制的循序邏輯實現
 
Example MVS Console Interface
Example MVS Console InterfaceExample MVS Console Interface
Example MVS Console Interface
 
VHDL PROGRAMS FEW EXAMPLES
VHDL PROGRAMS FEW EXAMPLESVHDL PROGRAMS FEW EXAMPLES
VHDL PROGRAMS FEW EXAMPLES
 
Unit 1 ocs752 introduction to c programming
Unit 1 ocs752 introduction to c programmingUnit 1 ocs752 introduction to c programming
Unit 1 ocs752 introduction to c programming
 
VHDL CODE
VHDL CODE VHDL CODE
VHDL CODE
 
Controlling Motors for Robot
Controlling Motors for RobotControlling Motors for Robot
Controlling Motors for Robot
 
Vhdl
VhdlVhdl
Vhdl
 
MFC Rect2
MFC Rect2MFC Rect2
MFC Rect2
 
Verilog full adder in dataflow & gate level modelling style.
Verilog full adder in dataflow  & gate level modelling style.Verilog full adder in dataflow  & gate level modelling style.
Verilog full adder in dataflow & gate level modelling style.
 
Digital system design practical file
Digital system design practical fileDigital system design practical file
Digital system design practical file
 
Dsd lab Practical File
Dsd lab Practical FileDsd lab Practical File
Dsd lab Practical File
 
Programs of VHDL
Programs of VHDLPrograms of VHDL
Programs of VHDL
 
C++ assignment
C++ assignmentC++ assignment
C++ assignment
 
C test
C testC test
C test
 
REPORT
REPORTREPORT
REPORT
 
Practical file
Practical filePractical file
Practical file
 
Programme en C: Additionneur complet 4 bits ac4
Programme en C: Additionneur  complet 4 bits ac4Programme en C: Additionneur  complet 4 bits ac4
Programme en C: Additionneur complet 4 bits ac4
 

Destaque

Des Presentation
Des PresentationDes Presentation
Des Presentation
DavidTynan1
 
Interface gsm with 8051 microcontroller (at89 c51)
Interface gsm with 8051 microcontroller (at89 c51)Interface gsm with 8051 microcontroller (at89 c51)
Interface gsm with 8051 microcontroller (at89 c51)
mdkousik
 
13986149 c-pgming-for-embedded-systems
13986149 c-pgming-for-embedded-systems13986149 c-pgming-for-embedded-systems
13986149 c-pgming-for-embedded-systems
PRADEEP
 

Destaque (8)

Des Presentation
Des PresentationDes Presentation
Des Presentation
 
Interface gsm with 8051 microcontroller (at89 c51)
Interface gsm with 8051 microcontroller (at89 c51)Interface gsm with 8051 microcontroller (at89 c51)
Interface gsm with 8051 microcontroller (at89 c51)
 
13986149 c-pgming-for-embedded-systems
13986149 c-pgming-for-embedded-systems13986149 c-pgming-for-embedded-systems
13986149 c-pgming-for-embedded-systems
 
How to Build a Dynamic Social Media Plan
How to Build a Dynamic Social Media PlanHow to Build a Dynamic Social Media Plan
How to Build a Dynamic Social Media Plan
 
Learn BEM: CSS Naming Convention
Learn BEM: CSS Naming ConventionLearn BEM: CSS Naming Convention
Learn BEM: CSS Naming Convention
 
SEO: Getting Personal
SEO: Getting PersonalSEO: Getting Personal
SEO: Getting Personal
 
Lightning Talk #9: How UX and Data Storytelling Can Shape Policy by Mika Aldaba
Lightning Talk #9: How UX and Data Storytelling Can Shape Policy by Mika AldabaLightning Talk #9: How UX and Data Storytelling Can Shape Policy by Mika Aldaba
Lightning Talk #9: How UX and Data Storytelling Can Shape Policy by Mika Aldaba
 
Succession “Losers”: What Happens to Executives Passed Over for the CEO Job?
Succession “Losers”: What Happens to Executives Passed Over for the CEO Job? Succession “Losers”: What Happens to Executives Passed Over for the CEO Job?
Succession “Losers”: What Happens to Executives Passed Over for the CEO Job?
 

Semelhante a Keypad program

New text document
New text documentNew text document
New text document
Roja Patro
 
Embedded Systems Project 3rd Year
Embedded Systems Project 3rd YearEmbedded Systems Project 3rd Year
Embedded Systems Project 3rd Year
Andrew Kozik
 
Codigo fuente
Codigo fuenteCodigo fuente
Codigo fuente
BlackD10
 
How do I draw the Labview code for pneumatic cylinder(air pistion). .pdf
How do I draw the Labview code for pneumatic cylinder(air pistion). .pdfHow do I draw the Labview code for pneumatic cylinder(air pistion). .pdf
How do I draw the Labview code for pneumatic cylinder(air pistion). .pdf
footstatus
 

Semelhante a Keypad program (20)

New text document
New text documentNew text document
New text document
 
Microcontroladores: programas de CCS Compiler.docx
Microcontroladores: programas de CCS Compiler.docxMicrocontroladores: programas de CCS Compiler.docx
Microcontroladores: programas de CCS Compiler.docx
 
PIC and LCD
PIC and LCDPIC and LCD
PIC and LCD
 
Basic standard calculator
Basic standard calculatorBasic standard calculator
Basic standard calculator
 
Embedded Systems Project 3rd Year
Embedded Systems Project 3rd YearEmbedded Systems Project 3rd Year
Embedded Systems Project 3rd Year
 
Codigo fuente
Codigo fuenteCodigo fuente
Codigo fuente
 
131080111003 mci
131080111003 mci131080111003 mci
131080111003 mci
 
codings related to avr micro controller
codings related to avr micro controllercodings related to avr micro controller
codings related to avr micro controller
 
Pythonによるカスタム可能な高位設計技術 (Design Solution Forum 2016@新横浜)
Pythonによるカスタム可能な高位設計技術 (Design Solution Forum 2016@新横浜)Pythonによるカスタム可能な高位設計技術 (Design Solution Forum 2016@新横浜)
Pythonによるカスタム可能な高位設計技術 (Design Solution Forum 2016@新横浜)
 
LCD_Example.pptx
LCD_Example.pptxLCD_Example.pptx
LCD_Example.pptx
 
Functions for Nano 5 Card
Functions for Nano 5 CardFunctions for Nano 5 Card
Functions for Nano 5 Card
 
22 microcontroller programs
22 microcontroller programs22 microcontroller programs
22 microcontroller programs
 
How do I draw the Labview code for pneumatic cylinder(air pistion). .pdf
How do I draw the Labview code for pneumatic cylinder(air pistion). .pdfHow do I draw the Labview code for pneumatic cylinder(air pistion). .pdf
How do I draw the Labview code for pneumatic cylinder(air pistion). .pdf
 
Microcontroller Programming Assignment
Microcontroller Programming AssignmentMicrocontroller Programming Assignment
Microcontroller Programming Assignment
 
Atmega lcd programing_with_header_file
Atmega lcd programing_with_header_fileAtmega lcd programing_with_header_file
Atmega lcd programing_with_header_file
 
Fpga creating counter with external clock
Fpga   creating counter with external clockFpga   creating counter with external clock
Fpga creating counter with external clock
 
VHDL Programs
VHDL ProgramsVHDL Programs
VHDL Programs
 
2022-BEKM 3453 - LCD and keypad.pdf
2022-BEKM 3453 - LCD and keypad.pdf2022-BEKM 3453 - LCD and keypad.pdf
2022-BEKM 3453 - LCD and keypad.pdf
 
Tdm to vo ip 2
Tdm to vo ip 2Tdm to vo ip 2
Tdm to vo ip 2
 
Qno 1 (d)
Qno 1 (d)Qno 1 (d)
Qno 1 (d)
 

Último

MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MysoreMuleSoftMeetup
 
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdf
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdfContoh Aksi Nyata Refleksi Diri ( NUR ).pdf
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdf
cupulin
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
AnaAcapella
 

Último (20)

MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
 
The Liver & Gallbladder (Anatomy & Physiology).pptx
The Liver &  Gallbladder (Anatomy & Physiology).pptxThe Liver &  Gallbladder (Anatomy & Physiology).pptx
The Liver & Gallbladder (Anatomy & Physiology).pptx
 
Graduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxGraduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptx
 
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
 
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfFICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
 
diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....
 
How to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptxHow to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptx
 
How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17
 
UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024
 
Including Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdfIncluding Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdf
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdf
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdfContoh Aksi Nyata Refleksi Diri ( NUR ).pdf
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdf
 
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
 
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community PartnershipsSpring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
 
AIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptAIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.ppt
 
Major project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategiesMajor project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategies
 
Trauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical PrinciplesTrauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical Principles
 
An overview of the various scriptures in Hinduism
An overview of the various scriptures in HinduismAn overview of the various scriptures in Hinduism
An overview of the various scriptures in Hinduism
 

Keypad program

  • 1. #include<reg51.h> #define port P1; #define dataport P2; #define key P0 ; void lcd_data_str(unsigned char *str); void lcd(unsigned char str[10]); void lcd_data(unsigned char item1); void display(int a); void lcd_cmd(unsigned char item); void chek_col1(); void chek_col2(); void chek_col3(); void chek_col4(); void delay(unsigned int m); sbit rs=port^1; sbit rw=port^2; sbit en=port^3; sbit row1=key^0; sbit row2=key^1; sbit row3=key^2; sbit row4=key^3; sbit col1=key^4; sbit col2=key^5; sbit col3=key^6; sbit col4=key^7; //Main program void main() { lcd_cmd(0x01); lcd_data_str("welcome"); col1=col2=col3=col4=1; while(1) { row1=row2=row3=row4=0; if(col1==0) chek_col1(); else if (col2==0) chek_col2(); else if(col3==0) chek_col3(); else chek_col4(); } } //Function to decide the key pressed in col1 void chek_col1() { row1=row2=row3=row4=1; row1=0; if(col1==0) display(1); row1=1; row2=0; if(col1==0) display(5); row2=1; row3=0; if(col1==0) display(9); row3=1; row4=0; if(col1==0)
  • 2. display(13); row4=1; } //Function to decide the key pressed in col2 void chek_col2() { row1=row2=row3=row4=1; row1=0; if(col2==0) display(2); row1=1; row2=0; if(col2==0) display(6); row2=1; row3=0; if(col2==0) display(10); row3=1; row4=0; if(col2==0) display(14); row4=1; } //Function to decide the key pressed in col3 void chek_col3() { row1=row2=row3=row4=1; row1=0; if(col3==0) display(3); row1=1; row2=0; if(col3==0) display(7); row2=1; row3=0; if(col3==0) display(11); row3=1; row4=0; if(col3==0) display(15); row4=1; } //Function to decide the key pressed in col4 void chek_col4() { row1=row2=row3=row4=1; row1=0; if(col4==0) display(4); row1=1; row2=0; if(col4==0) display(8);
  • 3. row2=1; row3=0; if(col4==0) display(12); row3=1; row4=0; if(col4==0) display(16); row4=1; } //Function to send Command to LCD void lcd_cmd(unsigned char item) { dataport=item; rs=0; rw=0; en=1; delay(1); en=0; return; } //Function to send Data to LCD void lcd_data(unsigned char item1) { dataport=item1; rs=1; rw=0; en=1; delay(1); en=0; return; } // Function to send string to lcd_data void lcd_data_str(unsigned char *str) { int i=0; while(str[i]!='0') { lcd_data(str[i]); i++; delay(10); } return; } //Function to initialize the LCD void lcd(unsigned char str[10]) { lcd_cmd(0x38); lcd_cmd(0x0E); lcd_cmd(0x01); lcd_cmd(0x82); lcd_data_str(str); } //Function to send the string to be displayed void display(int a) { switch(a)
  • 4. { case 1:lcd("One :1"); break; case 2:lcd("Two :2"); break; case 3:lcd("Three :3"); break; case 4:lcd("Four :4"); break; case 5:lcd("Five :5"); break; case 6:lcd("Six :6"); break; case 7:lcd("Seven :7"); break; case 8:lcd("Eight :8"); break; case 9:lcd("Nine :9"); break; case 10:lcd("Ten :10"); break; case 11:lcd("Eleven :11"); break; case 12:lcd("Twelve :12"); break; case 13:lcd("Thirteen :13"); break; case 14:lcd("Fourteen :14"); break; case 15:lcd("Fifteen :15"); break; case 16:lcd("sixteen :16"); break; default:lcd("others"); break; } } //Delay Function void delay(unsigned int m ) { int i,j; for(i=0;i<m;i++) for(j=0;j<1275;j++); } Result: