Sie sind auf Seite 1von 46

Kishinchand Chellaram College, Mumbai - 20

Practical No .1
Aim: Study of the embedded system Components
Description : _______________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________

Embedded System Practical Journal 2015-16

Page 1

Kishinchand Chellaram College, Mumbai - 20


__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________

Embedded System Practical Journal 2015-16

Page 2

Kishinchand Chellaram College, Mumbai - 20


Microcontroller/Microprocessors

Resistors

Embedded System Practical Journal 2015-16

Page 3

Kishinchand Chellaram College, Mumbai - 20


Capacitors

Inductors

LEDs/Displays

Diodes

Embedded System Practical Journal 2015-16

Page 4

Kishinchand Chellaram College, Mumbai - 20

Transistors

Sensors

Actuators

Embedded System Practical Journal 2015-16

Page 5

Kishinchand Chellaram College, Mumbai - 20


PRACTICAL NO:2

Aim: Write a program to blink an LED.

Description : _______________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________

Embedded System Practical Journal 2015-16

Page 6

Kishinchand Chellaram College, Mumbai - 20


Components:

CAP
CRYSTAL
LED-BIBY
RESISTOR

Design:

Component values:
Crystal -> Frequency = 11.059mhz
Cap -> Capacitance = 33p
Resistor -> Resistance (ohm)=100
Code:
# include <regx51.h>
Void delay_ms(unsigned int k)
{
Unsigned int i,j;
for (i=0;i<k;i++)
{
for (j=0;j<110;j++)
{
}

Embedded System Practical Journal 2015-16

Page 7

Kishinchand Chellaram College, Mumbai - 20


}
}
void main ()
{
while(1)
{
P1=0XDB;
while(1)
{
delay_ms(3);
P1=~P1 ;
delay_ms(3);
P1=~P1;
}
}
}
STEPS:
Go to Keil uVision4 and create a new project.

Embedded System Practical Journal 2015-16

Page 8

Kishinchand Chellaram College, Mumbai - 20

Select Atmel and then AT89C51.

Right click on the Source Group 1 and select Add Files to Group Source Group 1.

Embedded System Practical Journal 2015-16

Page 9

Kishinchand Chellaram College, Mumbai - 20


Select the file that has been created. blinkingled.c

Go the Project ->Options for Target Target 1.

In the Target tab, change the Xtal(mhz):11.059

Embedded System Practical Journal 2015-16

Page 10

Kishinchand Chellaram College, Mumbai - 20


In the Output tab, Select the create HEX file option

Go to Debug option and start debugging

Go to Peripherals and select the Port 1 and press F5 to run the code.

Embedded System Practical Journal 2015-16

Page 11

Kishinchand Chellaram College, Mumbai - 20


Output:
In the design page, right click on the micro controller and select Edit properties.

In the program file option, browse and add the hex file of the code. blinkingled.hex

Run the design.

PRACTICAL NO :3

Embedded System Practical Journal 2015-16

Page 12

Kishinchand Chellaram College, Mumbai - 20


Aim :WAP to serial data interface

Description : _______________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
COMPONENTS:

Embedded System Practical Journal 2015-16

Page 13

Kishinchand Chellaram College, Mumbai - 20


AT89C51:11.059MHz
CAP
C1:33PF
C2:1NF
C3:1UF
C4:10UF
C5:10UF
C6:10UF
C7:10UF
C8:10UF
C9:10UF
COMPIM
Physical baud rate:9600
Virtual baud rate:9600
CRYSTAL:11.059Mh
MAX232
RES
INSTRUMENTS > VIRTUAL TERMINAL:Baud rate:9600
DESIGN:

Embedded System Practical Journal 2015-16

Page 14

Kishinchand Chellaram College, Mumbai - 20

CODE:
#include<REG51.H>
#include<stdio.h>
voidserial_init(void);
voidserial_init(void)
{
SCON=0x50;
TMOD=0x20;
TH1=0xFD;
TR1=1;
TI=1;
}
void main(void)
{
serial_init();
while(1)
{
printf("hello world!! \n\r");
}
}
OUTPUT:

Embedded System Practical Journal 2015-16

Page 15

Kishinchand Chellaram College, Mumbai - 20

Port1(P1) TXD color changes to RED


Port2(P2) RXD color changes to RED

PRACTICAL NO :4

Embedded System Practical Journal 2015-16

Page 16

Kishinchand Chellaram College, Mumbai - 20


Aim :WAP for the keypad and LCD interface

Description : _______________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
COMPONENTS:

Embedded System Practical Journal 2015-16

Page 17

Kishinchand Chellaram College, Mumbai - 20


AT89C51:11.059MHz
BUTTON
CAPACITOR
C1:33pf
C2:33pf
C3:1uf
CRYSTAL:11.059MHz
LED-BLUE
LM016L
RES

CODE:
#include<reg51.h>
voidcct_init(void);
void delay(int);
voidlcdinit(void);
voidwritecmd(int);

Embedded System Practical Journal 2015-16

Page 18

Kishinchand Chellaram College, Mumbai - 20


voidwritedata(char);
void Return(void);
char READ_SWITCHES(void);
charget_key(void);
sbitRowA = P1^0;
sbitRowB = P1^1;
sbitRowC = P1^2;
sbitRowD = P1^3;
sbit
sbit
sbit
sbit

C1
C2
C3
C4

=
=
=
=

P1^4;
P1^5;
P1^6;
P1^7;

sbit E = P3^6;
sbit RS = P3^7;
int main(void)
{
char key;
cct_init();
lcdinit();

//RowA
//RowB
//RowC
//RowD
//Column1
//Column2
//Column3
//Column4
//E pin for LCD
//RS pin for LCD

// key char for keeping record of pressed key


// Make input and output pins as required
// Initilize LCD

while(1)
{
key = get_key();
// Get pressed key
writecmd(0x01);
// Clear screen
writedata(key);
// Echo the key pressed to LCD
}
}
voidcct_init(void)
{
P0 = 0x00;
P1 = 0xf0;
P2 = 0x00;
P3 = 0x00;
}

//not used
//used for generating outputs and taking inputs from Keypad
//used as data port for LCD
//used for RS and E

void delay(int a)
{
inti;
for(i=0;i<a;i++); //null statement
}
voidwritedata(char t)
{
RS = 1;
// This is data
P2 = t;
//Data transfer

Embedded System Practical Journal 2015-16

Page 19

Kishinchand Chellaram College, Mumbai - 20


E = 1;
delay(150);
E = 0;
delay(150);
}

// => E = 1
// => E = 0

voidwritecmd(int z)
{
RS = 0;
// This is command
P2 = z;
//Data transfer
E = 1;
// => E = 1
delay(150);
E = 0;
// => E = 0
delay(150);
}
voidlcdinit(void)
{
delay(15000);
writecmd(0x30);
delay(4500);
writecmd(0x30);
delay(300);
writecmd(0x30);
delay(650);
writecmd(0x38);
writecmd(0x0c);
writecmd(0x01);
writecmd(0x06);
}
void Return(void)
{
writecmd(0x02);
delay(1500);
}

//function set
//display on,cursoroff,blink off
//clear display
//entry mode, set increment
//Return to 0 location on LCD

char READ_SWITCHES(void)
{
RowA = 0; RowB = 1; RowC = 1; RowD = 1;
if
if
if
if

(C1
(C2
(C3
(C4

==
==
==
==

0)
0)
0)
0)

{
{
{
{

delay(10000);
delay(10000);
delay(10000);
delay(10000);

while
while
while
while

(C1==0);
(C2==0);
(C3==0);
(C4==0);

RowA = 1; RowB = 0; RowC = 1; RowD = 1;

//Test Row A
return
return
return
return

'A'; }
'B'; }
'C'; }
'0'; }

//Test Row B

if (C1 == 0) { delay(10000); while (C1==0); return 'D'; }

Embedded System Practical Journal 2015-16

Page 20

Kishinchand Chellaram College, Mumbai - 20


if (C2 == 0) { delay(10000); while (C2==0); return 'E'; }
if (C3 == 0) { delay(10000); while (C3==0); return 'F'; }
if (C4 == 0) { delay(10000); while (C4==0); return '1'; }
RowA = 1; RowB = 1; RowC = 0; RowD = 1;

//Test Row C

if
if
if
if

return
return
return
return

(C1
(C2
(C3
(C4

==
==
==
==

0)
0)
0)
0)

{
{
{
{

delay(10000);
delay(10000);
delay(10000);
delay(10000);

while
while
while
while

(C1==0);
(C2==0);
(C3==0);
(C4==0);

'G'; }
'H'; }
'I'; }
'2'; }

RowA = 1; RowB = 1; RowC = 1; RowD = 0;

//Test Row D

if
if
if
if

return
return
return
return

(C1
(C2
(C3
(C4

==
==
==
==

return 'n';

0)
0)
0)
0)

{
{
{
{

delay(10000);
delay(10000);
delay(10000);
delay(10000);

while
while
while
while

(C1==0);
(C2==0);
(C3==0);
(C4==0);

'J'; }
'K'; }
'3'; }
'4'; }

// Means no key has been pressed

}
charget_key(void)
//get key from user
{
char key = 'n';
//assume no key pressed
while(key=='n')
//wait untill a key is pressed
key = READ_SWITCHES(); //scan the keys again and again
return key;
//when key pressed then return its value
}

Output:

Embedded System Practical Journal 2015-16

Page 21

Kishinchand Chellaram College, Mumbai - 20

PRACTICAL NO :5
Aim :WAP to implement ADC0808 with 8051 microcontroller

Embedded System Practical Journal 2015-16

Page 22

Kishinchand Chellaram College, Mumbai - 20


Description : _______________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________

Components:
ADC0808
AT89C51:11.059MHz

Embedded System Practical Journal 2015-16

Page 23

Kishinchand Chellaram College, Mumbai - 20

CAP
C1:33pf
C2:33pf
C3:1uf

CAP-ELEC
CRYSTAL
LM016L
POT-HG
RES

Output:

Embedded System Practical Journal 2015-16

Page 24

Kishinchand Chellaram College, Mumbai - 20

PRACTICAL NO :6 A
Aim :Write a program to interface stepper motor (Full Wave Stepper Motor)

Embedded System Practical Journal 2015-16

Page 25

Kishinchand Chellaram College, Mumbai - 20


Description : _______________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
Component :
AT89C51
Capacitor (||)

Embedded System Practical Journal 2015-16

Page 26

Kishinchand Chellaram College, Mumbai - 20

Crystal
Resistor
ULN2003A
Stepper Motor 3 pins
Ground
Power

Design :

Components Value :
AT89C51 11.059 MHz
C1 & C2 33pF
C3 1uF
Crystal 11.059 MHz
R1 10k

Code :

Embedded System Practical Journal 2015-16

Page 27

Kishinchand Chellaram College, Mumbai - 20


#include<reg51.h>
#include<stdio.h>
void delay(int);
void main()
{
do
{
P2=0x09;
delay(500);
P2=0x0C;
delay(500);
P2=0x06;
delay(500);
P2=0x03;
delay(500);
}
while(1);
}
void delay(int k)
{
inti,j;
for(i=0;i<k;i++)
{
for(j=0;j<100;j++)
{
}
}
}
After implementing the code build the target and generate the .HEX file.
After generating the .HEX file -> go to the Circuit Design right click on the AT89C51 board ->
Select Edit properties and browse the .HEX file. -> Click on OK -> Click on play button

Output:

Embedded System Practical Journal 2015-16

Page 28

Kishinchand Chellaram College, Mumbai - 20

Embedded System Practical Journal 2015-16

Page 29

Kishinchand Chellaram College, Mumbai - 20


PRACTICAL NO :6B
Aim :Write a program to interface stepper motor (Half Wave Stepper Motor)

Description : _______________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________

Embedded System Practical Journal 2015-16

Page 30

Kishinchand Chellaram College, Mumbai - 20


Component :
AT89C51
Capacitor (||)
Crystal
Resistor
ULN2003A
Stepper Motor 3 pins
Ground
Power
Design :

Components Value :
AT89C51 11.059 MHz
C1 & C2 33pF
C3 1uF
Crystal 11.059 MHz
R1 10k
Code :

Embedded System Practical Journal 2015-16

Page 31

Kishinchand Chellaram College, Mumbai - 20


#include<reg51.h>
#include<stdio.h>
void delay(int);
void main()
{
do
{
P2=0x09;
delay(500);
P2=0x08;
delay(500);
P2=0x0C;
delay(500);
P2=0x04;
delay(500);
P2=0x06;
delay(500);
P2=0x02;
delay(500);
P2=0x03;
delay(500);
P2=0x01;
delay(500);
}
while(1);
}
void delay(int k)
{
inti,j;
for(i=0;i<k;i++)
{
for(j=0;j<100;j++)
{
}
}
}
After implementing the code build the target and generate the .HEX file.
After generating the .HEX file -> go to the Circuit Design right click on the AT89C51 board ->
Select Edit properties and browse the .HEX file. -> Click on OK -> Click on play button.

Embedded System Practical Journal 2015-16

Page 32

Kishinchand Chellaram College, Mumbai - 20


Output:

Embedded System Practical Journal 2015-16

Page 33

Kishinchand Chellaram College, Mumbai - 20


PRACTICAL NO :7
Aim : Write a program to simulate traffic signals

Description : _______________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________

Embedded System Practical Journal 2015-16

Page 34

Kishinchand Chellaram College, Mumbai - 20


Component :
AT89C51
Capacitor
Crystal
LED RED
LED GREEN
LED BLUE
LED YELLOW
Resistor
Ground
Power
Design :

Components Value :
AT89C51 11.059 MHz
C1 & C2 33pF
C3 1uF
Crystal 11.059 MHz
R1 10k
R2 R17 100

Embedded System Practical Journal 2015-16

Page 35

Kishinchand Chellaram College, Mumbai - 20

LED 10mA

Code :
#include<reg52.h>
void count1();
void delay();
unsigned int s,k;
sbit NR = P0^0;
sbit NY = P0^1;
sbit NG = P0^2;
sbit NL = P0^3;
sbit SR = P0^4;
sbit SY = P0^5;
sbit SG = P0^6;
sbit SL = P0^7;
sbit ER = P1^0;
sbit EY = P1^1;
sbit EG = P1^2;
sbit EL = P1^3;
sbit WRR = P1^4;
sbit WY = P1^5;
sbit WG = P1^6;
sbit WL = P1^7;
void main()
{
while(1)
{
NR =1;
NY=1;
NG=0;
NL=1;
SR=1;
SY=1;
SG=0;
SL=1;
WRR = 0;
WY=1;

Embedded System Practical Journal 2015-16

Page 36

Kishinchand Chellaram College, Mumbai - 20


WG=1;
WL=1;
ER=0;
EY=1;
EG=1;
EL=1;
count1();
WRR = 1;
WY=0;
WG=1;
WL=1;
ER=1;
EY=0;
EG=1;
EL=1;
count1();
ER = 1;
EY=1;
EG=0;
EL=1;
WRR =1;
WY=1;
WG=0;
WL=1;
NR=0;
NY=1;
NG=1;
NL=1;
SR=0;
SY=1;
SG=1;
SL=1;
count1();
NR=1;
NY=0;
NG=1;
NL=1;

Embedded System Practical Journal 2015-16

Page 37

Kishinchand Chellaram College, Mumbai - 20


SR=1;
SY=0;
SG=1;
SL=1;
count1();
NR =1;
NY=1;
NG=1;
NL=0;
SR=1;
SY=1;
SG=1;
SL=0;
WRR = 0;
WY=1;
WG=1;
WL=1;
ER=0;
EY=1;
EG=1;
EL=1;
count1();
NR =0;
NY=1;
NG=1;
NL=1;
SR=0;
SY=1;
SG=1;
SL=1;
WRR = 1;
WY=1;
WG=1;
WL=0;
ER=1;
EY=1;
EG=1;
EL=0;

Embedded System Practical Journal 2015-16

Page 38

Kishinchand Chellaram College, Mumbai - 20


count1();
}
}
void delay(void)
{
for(s=0;s<=230;s++)
{
for(k=0;k<238;k++)
{
}
}
}
void count1()
{
unsignedinti,j;
for(j=0;j<=2;)
{
for(i=0;i<=3;)
{
i++;
delay();
}
j++;
delay();
}
}
After implementing the code build the target and generate the .HEX file.
After generating the .HEX file -> go to the Circuit Design right click on the AT89C51 board ->
Select Edit properties and browse the .HEX file. -> Click on OK -> Click on play button
Output:

Embedded System Practical Journal 2015-16

Page 39

Kishinchand Chellaram College, Mumbai - 20

PRACTICAL NO :8
Aim : Write a program to simulate elevator function

Description : _______________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________

Embedded System Practical Journal 2015-16

Page 40

Kishinchand Chellaram College, Mumbai - 20


__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
DESIGN:

Code:
#include<reg51.h>
void delayd();
char key; // key char for keeping record of pressed key
//2. PUSH BUTTON SWITCHES TO CALL LIFT
sbit TF = P1^0;
sbit SF = P1^1;
sbit FF = P1^2;
sbit GF = P1^3;
sbit led = P1^4;
char READ_SWITCHES(void);

Embedded System Practical Journal 2015-16

Page 41

Kishinchand Chellaram College, Mumbai - 20


char get_key(void);
void main()
{
P2 = 0x3f;
P1 = 0x00;
while(1)
{
key = get_key(); // Get pressed key
P1 = 0x00;
led=0;
}
}
char get_key(void) //get key from user
{
char key = 'n'; //assume no key pressed
while(key=='n') //wait untill a key is pressed
key = READ_SWITCHES(); //scan the keys again and again
return key; //when key pressed then return its value
}
char READ_SWITCHES(void)
{
//ground floor
if (GF == 1)
{
led=1;
// third to ground
if(GF==1 && key=='T')
{
delayd();
P2 = 0x5b;
delayd();
P2 = 0x06;
delayd();
P2 = 0x3f;
}
// second to ground
if(GF==1 && key=='S')
{
delayd();
P2 = 0x06;
delayd();
P2 = 0x3f;
}
// first to ground
if(GF==1 && key=='F')
{
delayd();
P2 = 0x3f;

Embedded System Practical Journal 2015-16

Page 42

Kishinchand Chellaram College, Mumbai - 20


}
return 'G';
}
//first floor
if (FF == 1)
{ led=1;
//third floor to first floor
if(FF==1 && key=='T')
{
delayd();
P2 = 0x5b;
delayd();
P2 = 0x06;
}
//second floor to first floor
if(FF==1 && key=='S')
{
delayd();
P2 = 0x06;
}
//ground floor to first floor
if(FF==1 && key=='G')
{
delayd();
P2 = 0x06;
}
delayd();
return 'F';
}
//second floor
if (SF == 1)
{
led=1;
//third floor to second floor
if(SF==1 && key=='T')
{
delayd();
P2 = 0x5b;
}
//first floor to second floor
if(SF==1 && key=='F')
{
delayd();
P2 = 0x5b;
}
//ground floor to second floor
if(FF==1 && key=='G')
{

Embedded System Practical Journal 2015-16

Page 43

Kishinchand Chellaram College, Mumbai - 20


delayd();
P2 = 0x06;
delayd();
P2 = 0x5b;
}
delayd();
return 'S';
}
//third floor
if (TF == 1)
{
led=1;
if(TF==1 && key=='G') //ground floor to third floor
{
delayd();
P2 = 0x06;
delayd();
P2 = 0x5b;
delayd();
P2 = 0x4f;
}
if(TF==1 && key=='F') //first floor to third floor
{
delayd();
P2 = 0x5b;
delayd();
P2 = 0x4f;
}
if(TF==1 && key=='S') //second floor to third floor
{
delayd();
P2 = 0x4f;
}
delayd();
return 'T';
}
}
void delayd ( )
{
unsigned int s,k,i;
for(i=0;i<3;i++)
{
for(s=0;s<=230;s++)
{
for(k=0;k<238;k++);
}
}
}

Embedded System Practical Journal 2015-16

Page 44

Kishinchand Chellaram College, Mumbai - 20

Output:

Embedded System Practical Journal 2015-16

Page 45

Kishinchand Chellaram College, Mumbai - 20

Embedded System Practical Journal 2015-16

Page 46

Das könnte Ihnen auch gefallen