You are on page 1of 4

Bangladesh University of Business and

Technology (BUBT)

Lab Evaluation-2

Course Name : Microcontroller & Embedded Systems Lab


Course Code : CSE 426

Submitted By : Submitted To :
Satyajit Sarker Nourin Khandaker
ID – 17182103157 Lecture
Intake - 38 ; Section - 4 Department of CSE,
B. Sc. Engg in CSE BUBT

Submission Date : 2021 June 26


Problem : Interface a 8051 with a 4x4 keypad and a seven segment display. Program the
first 10 keys of keypad with digits 0-9. Now, make the design and code in such a way so that
when a key is pressed the digit will be shown in seven segment display i.e if key '9' is
pressed the display will show 9 and so on.

Code :

#include<reg51.h>
sbit r0=P1^0;
sbit r1=P1^1;
sbit r2=P1^2;
sbit r3=P1^3;
sbit c0=P1^4;
sbit c1=P1^5;
sbit c2=P1^6;

void seg(unsigned int);

void main(){

r0=r1=r2=r3=1;
r0=0;
if(c0==0)
seg(0xF9);

r0=r1=r2=r3=1;
r0=0;
if(c1==0)
seg(0xA4);

r0=r1=r2=r3=1;
r0=0;
if(c2==0)
seg(0xB0);

r0=r1=r2=r3=1;
r1=0;
if(c0==0)
seg(0x99);

r0=r1=r2=r3=1;
r1=0;
if(c1==0)
seg(0x92);

r0=r1=r2=r3=1;
r1=0;
if(c2==0)
seg(0x82);

r0=r1=r2=r3=1;
r2=0;
if(c0==0)
seg(0xF6);

r0=r1=r2=r3=1;
r2=0;
if(c1==0)
seg(0x80);

r0=r1=r2=r3=1;
r2=0;
if(c2==0)
seg(0x90);

r0=r1=r2=r3=1;
r3=0;
if(c1==0)
seg(0xC0);
}

void seg(unsigned int ch)


{
P2=0x00;
P2=ch;
}
Screenshot :

You might also like