LABORATORY MANUAL
ET3491 EMBEDDED SYSTEMS AND IOT DESIGN
EXP NO: 1
PROGRAMMING ARITHMETIC AND LOGICAL OPERATIONS
DATE:
USING 8051
AIM:
To write a program for basic arithmetic and logical operations using keil software.
APPARATUS REQUIRED :
Keil µ vision 5 software
PROCEDURE :
Open the keil software and create a new project.
Open the new file and save the name. A
Write a program and check the error if any using the build up button.
Click the debug and see the value of the register using the F11 button.
Go to the memory window and put the address line D:40H.
To see the output using the memory window.
PROGRAM:
// ARITHMETIC AND LOGICAL OPERATIONS OF 8051
// ADDITION
MOV A,#25H
MOV B,#12H
ADD A, B
MOV 40H,A
// SUBTRACTION
MOV A,#25H
SUBB A,B
MOV 41H,A
// MULTIPLICATION
MOV A,#25H
MUL AB
MOV 42H,A
MOV 43H,B
// DIVISON
MOV A,#25H
MOV B,#12H
DIV AB
MOV 44H,A
MOV 45H,B
// AND OPERATION
MOV A,#25H
MOV B,#12H
ANL A,B
MOV 46H,A
// OR OPERATION
MOV A,#25H
MOV B,#12H
ORL A,B
MOV 47H,A
LCALL 0003H
END
OUTPUT
RESULT
Thus the 8051 Assembly Language Program for basic arithmetic and logical operations using
Keil software was executed sucessfully.
EXP NO: 2
GENERATION OF SQUARE WAVEFORM USING 8051
DATE:
AIM:
To write a program for the Generation of a Square waveform using Keil software.
APPARATUS REQUIRED :
Keil µ vision 5 software
PROCEDURE :
Open the keil software and create a new project.
Open the new file and save the name. A
Write a program and check the error if any using the build up button.
Click the debug and see the value of the register using the F11 button.
Click the analyzer window and set the p2 in setup.
Click the run button to see the output in the analyzer window.
PROGRAM:
ORG 0000
CLR A
UP:MOV A,#00H
MOV P2,A
SJMP L1
L1: MOV A,#050H
MOV P2,A
SJMP UP
END
OUTPUT
RESULT:
Thus the 8051 assembly language program for Generation of Square waveform using Keil
software was executed and verified.
EXP NO: 3
PROGRAMMING USING ON-CHIP PORTS IN 8051
DATE:
AIM:
To write a program for on-chip port in 8051 using keil software.
APPARATUS REQUIRED :
Keil µ vision 5 software
PROCEDURE :
Open the keil software and create a new project.
Open the new file and save the name. A
Write a program and check the error if any using the build up button.
Click the debug and see the value of the register using the F11 button.
Click the peripherals button to see the port1 and port2.
Click the run button to see the output in port 2.
PROGRAM:
ORG 0H ; Start of program memory
MOV P1, #0FFH ; Set all pins of P1 as input
Main_Loop:
MOV A, P1 ; Read input from port P1
CPL A ; Complement the value read from P1
MOV P2, A ; Output the complemented value to port P2
SJMP Main_Loop ; Repeat indefinitely
END
OUTPUT
RESULT:
Thus the 8051assembly language program for on-chip port in 8051 using Keil software
was executed and verified.
EXP NO: 4
PROGRAMMING USING SERIAL PORTS IN 8051
DATE:
AIM:
To write a program for serial port in 8051 using keil software and proteus software.
APPARATUS REQUIRED :
Keil µ vision 5 software
Proteus 8 professional software
PROCEDURE :
Open the keil software and create a new project.
Open the new file and save the name. A
Write a program and check the error if any using the build up button.
Click the debug and see the value of the register using the F11 button.
Click the serial window and click the run button.
Open the proteus software and click a new project.
Design to connect the AT89C51, virtual terminal, and add the hex file.
Run the designed serial port and finally see the output in a virtual terminal.
PROGRAM:
#include<reg51.h>
void main()
SCON=0X50;
TMOD=0X20;
TH1=-3; //BAUDRATE 9600
TR1=1;
SBUF='I';
while(TI==0);
TI=0;
OUTPUT
RESULT:
Thus the 8051assembly language program for serial port in 8051 using Keil software and
proteus software was executed and verified sucessfully.
EXP NO: 5
DESIGN OF A DIGITAL CLOCK USING TIMERS/COUNTERS IN
DATE: 8051
AIM:
To write a program for designing a digital clock in 8051 using Keil software and Proteus software.
APPARATUS REQUIRED :
Keil µ vision 5 software
Proteus 8 professional software
PROCEDURE :
Open the keil software and create a new project.
Open the new file and save the name. A
Write a program and check the error if any.
Create a hex file of this program.
Open the proteus software and click a new project.
Design a digital clock using AT89C51 and add the hexfile.
Run the designed digital clock and finally see the output.
PROGRAM:
ORG 00H
LJMP MAIN
ORG 30H
MAIN:
MOV DPTR, #MYDATA
MOV P3,00000000B
START:
MOV R0,#00H
MOV R1,#00H
MOV R2,#00H
MOV R3,#00H
MOV R4,#00H
MOV R5,#00H
MOV R1,#5H //seconds
MOV R2,#5H //seconds
MOV R3,#9H //minutes
MOV R4,#5H //minutes
MOV R5,#05H //hours
MOV R1,#00H //hours
wait:JB P3.1,wait
DISPLAY:
ACALL SHOW
BACK:
INC R0
CJNE R0, #10D, DISPLAY
MOV R0, #00H
INC R1
CJNE R1, #6D, DISPLAY
MOV R1, #00H
INC R2
CJNE R2, #10D, DISPLAY
MOV R2, #00H
INC R3
CJNE R3, #6D, DISPLAY
MOV R3, #00H
MOV A, #01D
JZ DAYNIGHT
JNZ HOURS
HOURS:
INC R4
CJNE R4,#10D,DISPLAY
MOV R4,#00H
SJMP NEWDAY
DAYNIGHT:
INC R4
CJNE R4,#4D,DISPLAY
MOV R4, #00H
MOV R5,#02D
NEWDAY:
INC R5
CJNE R5,#3D,DISPLAY
SJMP START
SHOW:
MOV R6,#32D
REPEAT:
MOV A,R0
MOVC A,@A+DPTR
SETB P2.0
MOV P1,A
ACALL DELAY
CLR P2.0
MOV A,R1
MOVC A,@A+DPTR
SETB P2.1
MOV P1,A
ACALL DELAY
CLR P2.1
MOV A,R2
MOVC A,@A+DPTR
SETB P2.2
MOV P1,A
ACALL DELAY
CLR P2.2
MOV A,R3
MOVC A,@A+DPTR
SETB P2.3
MOV P1,A
ACALL DELAY
CLR P2.3
MOV A,R4
MOVC A,@A+DPTR
SETB P2.4
MOV P1,A
ACALL DELAY
CLR P2.4
MOV A,R5
MOVC A,@A+DPTR
SETB P2.5
MOV P1,A
ACALL DELAY
CLR P2.5
ACALL ALARM
DJNZ R6, REPEAT
RET
ALARM:
CJNE R5,#00H,NEXT
CJNE R4,#05H,NEXT
SETB P3.0
CLR P3.4
NEXT:
CJNE R5,#00H,NEXT1
CJNE R4,#05H,NEXT1
SETB P3.0
CLR P3.4
NEXT1:
CJNE R5,#01H,NEXT2
CJNE R4,#07H,NEXT2
SETB P3.2
CLR P3.1
NEXT2:
CJNE R5,#01H,NEXT3
CJNE R4,#09H,NEXT3
SETB P3.3
CLR P3.2
NEXT3:
CJNE R5,#02H,NEXT4
CJNE R4,#01H,NEXT4
SETB P3.4
CLR P3.3
NEXT4:
CJNE R5,#00H,NEXT5
CJNE R4,#06H,NEXT5
SETB P3.7
CLR P3.0
NEXT5:
RET
DELAY:
SETB PSW.4 //change bank 0 to bank 2
MOV R2,#10
AGAIN2: MOV R3,#100
AGAIN1: DJNZ R3,AGAIN1
DJNZ R2, AGAIN2
CLR PSW. 4
RET
MYDATA:
DB 3FH
DB 06H
DB 5BH
DB 4FH
DB 66H
DB 6DH
DB 7DH
DB 07H
DB 7FH
DB 6FH
END
OUTPUT
RESULT:
Thus the 8051assembly language program for designing a digital clock using Keil
software and the output has been verified in Proteus software successfully.
EXP NO: 6 (a)
INTERFACING ADC
DATE:
AIM:
To write a program for Interfacing ADC using Keil software and Proteus software.
APPARATUS REQUIRED :
Keil µ vision 5 software
Proteus 8 professional software
PROCEDURE :
Open the keil software and create a new project.
Open the new file and save the name. C
Write a program and check the error if any.
Create a hex file of this program.
Open the proteus software and click a new project.
Design ADC using AT89C51 and add the hexfile.
Finally to see the output in virtual terminal.
PROGRAM:
#include <reg51.h>
#include <intrins.h>
sbit scl=P2^0;
sbit sda=P2^1;
sbit green=P2^2;
sbit red=P2^2;
void start();
void delay();
void read ();
void write (unsigned char);
void conversion(unsigned char);
void check();
void nack();
void stop ();
bit c=0;
unsigned char res,v11,v15;
bit d;
unsigned char v1;
void main ()
{
green=red=0;
SCON=0X50;
TMOD=0X20;
TH1=-3;
TR1=1;
start();
write(0x90);
write(0x01);
while(1)
{
green=1;
red=0;
start();
write(0x91);
read();
nack();
}
}
void delay()
{
_nop_();
_nop_();
}
void nack()
{
sda=1;
scl=1;
delay();
scl=0;
}
void start()
{
scl=1;
sda=1;
delay();
sda=0;
delay();
scl=0;
}
void write(unsigned char val)
{
unsigned char v2=0x80,v3,v5;
v5=val;
for(v3=0;v3<8;v3++)
{
sda=v5&v2;
scl=1;
delay();
scl=0;
v5=v5<<1;
}
c=sda;
scl=1;
delay();
scl=0;
if(c==1)
{
red=1;
green=0;
stop();
}
sda=1;
}
void stop()
{
scl=1;
sda=0;
delay();
sda=1;
scl=0;
delay();
}
void conversion (unsigned char val)
{
unsigned char v12,v13,v14;
v12=val;
v13=v12/10;
v14=v12%10;
v13=v13|0x30;
v14=v14|0x30;
SBUF=v13;
while(TI==0);
TI=0;
SBUF=v14;
while(TI==0);
TI=0;
SBUF=0X0D;
while(TI==0);
TI=0;
}
void read()
{
unsigned char ch=0x00,v16;
bit m=0;
for(v16=0;v16<=7;v16++)
{
scl=1;
delay();
m=sda;
scl=0;
if(m==1)
{
ch|=0x01;
}
if(v16<=6)
ch=ch<<1;
delay();
}
conversion(ch);
}
OUTPUT
RESULT
Thus, the C program for performing the interfacing ADC using Keil software and the
output has been verified in proteus software.
EXP NO: 6 (b)
INTERFACING DAC
DATE:
AIM:
To write a program for Interfacing DAC using Keil software.
APPARATUS REQUIRED :
Keil µ vision 5 software
Proteus software
PROCEDURE :
Open the keil software and create a new project.
Open the new file and save the name. C
Write a program and check the error if any.
Create a hex file of this program.
Open the proteus software and click a new project.
Design DAC using AT89C51 and add the hexfile.
Finally to see the output in digital oscilloscope.
PROGRAM:
#include<reg51.h>
unsigned char sine[50] =
{52,57,62,66,70,74,77,80,82,84,85,86,86,86,85,83,81,78,75,72,69,65,61,56,52,48,44,39,35,31,28,25,
22,19,17,15,14,14,14,15,16,18,20,23,26,30,34,38,43,48};
// Function Purpose: Produce approximate delay in Secs.
void delay_us(unsigned int d)
{
unsigned int i;
for(i=0;i<(d*20);i++);
}
// Main function
void main()
{
int i;
while(1)
{ for(i=0;i<50;i++)
{
P2=sine[i]; // assign the sine wave values to PORTB for DAC0808 IC
delay_us(1);
} // Two second delay
}
}
SCHEMATIC DIAGRAM
OUTPUT
RESULT
Thus, the C program for performing the interfacing DAC using Keil software and the output
has been verified in proteus software.
EXP NO: 7 (a)
BLINKING OF LEDS
DATE:
AIM:
To write a program for blinking LEDs using Keil software and proteus software.
APPARATUS REQUIRED :
Keil µ vision 5 software
Proteus 8 professional software
PROCEDURE :
Open the keil software and create a new project.
Open the new file and save the name. A
Write a program and check the error if any.
Create a hex file of this program.
Open the proteus software and click a new project.
Design the LED using AT89C51 and add the hexfile.
Finally blink the LED to see the output.
PROGRAM:
ORG 0000H
UP : SETB P2.0
ACALL DELAY
CLR P2.0
ACALL DELAY
SJMP UP
DELAY: MOV R4,#35
H1: MOV R3,#225
H2: DJNZ R3,H2
DJNZ R4,H1
RET
END
OUTPUT
RESULT:
Thus the 8051 assembly language program for blinking of LEDs using Keil software
and the output has been verified in Proteus software.
EXP NO: 7 (b)
BLINKING OF LCD
DATE:
AIM:
To write a program for blinking LCDs using Keil software and proteus software.
APPARATUS REQUIRED :
Keil µ vision 5 software
Proteus 8 professional software
PROCEDURE :
Open the keil software and create a new project.
Open the new file and save the name. A
Write a program and check the error if any.
Create a hex file of this program.
Open the proteus software and click a new project.
Design the LCD using AT89C51 and add the hexfile.
Finally blink the LCD to see the output in proteus software.
PROGRAM:
ORG 0000H
RS BIT P2.0
RW BIT P2.1
EN BIT P2.2
MOV A,#38H
ACALL CMD
MOV A,#0EH
ACALL CMD
MOV A,#80H
ACALL CMD
MOV A,#06H
ACALL CMD
MOV A,#'E'
ACALL DATA1
MOV A,#'M'
ACALL DATA1
MOV A,#'B'
ACALL DATA1
MOV A,#'E'
ACALL DATA1
MOV A,#'D'
ACALL DATA1
MOV A,#'D'
ACALL DATA1
MOV A,#'E'
ACALL DATA1
MOV A,#'D'
ACALL DATA1
MOV A,#0C0H
ACALL CMD
MOV A,#'S'
ACALL DATA1
MOV A,#'Y'
ACALL DATA1
MOV A,#'S'
ACALL DATA1
MOV A,#'T'
ACALL DATA1
MOV A,#'E'
ACALL DATA1
MOV A,#'M'
ACALL DATA1
MOV A,#'S'
CMD:ACALL READY
MOV P1,A
CLR RS
CLR RW
SETB EN
ACALL DELAY
CLR EN
RET
READY:SETB P1.7
CLR RS
SETB RW
H:CLR EN
ACALL DELAY
SETB EN
JB P1.7,H
RET
DATA1:ACALL READY
MOV P1,A
SETB RS
CLR RW
SETB EN
ACALL DELAY
CLR EN
RET
DELAY:MOV R4,#180
HERE1:MOV R3,#255
HERE2:DJNZ R3,HERE2
DJNZ R4,HERE1
RET
END
OUTPUT
RESULT
Thus the 8051 assembly language program for blinking of LCD using Keil software and
the output has been verified in proteus software
EXP NO: 8 (a)
INTERFACING OF KEYBOARD
DATE
AIM:
To write a program for Interfacing of keyboard using Keil software.
APPARATUS REQUIRED :
Keil µ vision 5 software
Proteus 8 professional software
PROCEDURE :
Open the keil software and create a new project.
Open the new file and save the name. c
Write a program and check the error if any.
Create a hex file of this program.
Open the proteus software and click a new project.
Design the interfacing of keyboard and add the hexfile.
Finally run the designed interfacing of keyboard to see the output in the LCD display.
PROGRAM:
#include<reg51.h>
#define display_port P2
sbit rs=P3^2;
sbit rw=P3^3;
sbit e=P3^4;
sbit C4=P1^0;
sbit C3=P1^1;
sbit C2=P1^2;
sbit C1=P1^3;
sbit R4=P1^4;
sbit R3=P1^5;
sbit R2=P1^6;
sbit R1=P1^7;
void msdelay(unsigned int time)
{
unsigned i,j;
for(i=0;i<time;i++)
for(j=0;j<1275;j++);
}
void lcd_cmd(unsigned char command)
{
display_port = command;
rs=0;
rw=0;
e=1;
msdelay(1);
e=0;
}
void lcd_data(unsigned char disp_data) //function to send display data to LCD
{
display_port = disp_data;
rs=1;
rw=0;
e=1;
msdelay(1);
e=0;
}
void lcd_init()
{
lcd_cmd(0x38);
msdelay(10);
lcd_cmd(0x0F);
msdelay(10);
lcd_cmd(0x01);
msdelay(10);
lcd_cmd(0x81);
msdelay(10);
}
void row_finder1()
{
R1=R2=R3=R4=1;
C1=C2=C3=C4=0;
if(R1==0)
lcd_data('7');
if(R2==0)
lcd_data('4');
if(R3==0)
lcd_data('1');
if(R4==0)
lcd_data('e');
}
void row_finder2()
{
R1=R2=R3=R4=1;
C1=C2=C3=C4=0;
if(R1==0)
lcd_data('8');
if(R2==0)
lcd_data('5');
if(R3==0)
lcd_data('2');
if(R4==0)
lcd_data('0');
}
void row_finder3()
{
R1=R2=R3=R4=1;
C1=C2=C3=C4=0;
if(R1==0)
lcd_data('9');
if(R2==0)
lcd_data('6');
if(R3==0)
lcd_data('3');
if(R4==0)
lcd_data('=');
}
void row_finder4()
{
R1=R2=R3=R4=1;
C1=C2=C3=C4=0;
if(R1==0)
lcd_data('/');
if(R2==0)
lcd_data('x');
if(R3==0)
lcd_data('-');
if(R4==0)
lcd_data('+');
}
void main()
{
lcd_init();
while(1)
{
msdelay(30);
C1=C2=C3=C4=1;
R1=R2=R3=R4=0;
if(C1==0)
row_finder1();
else if(C2==0)
row_finder2();
else if(C3==0)
row_finder3();
else if(C4==0)
row_finder4();
}
}
OUTPUT
RESULT:
Thus, the C program for performing the interfacing of the keyboard using Keil software and
the output has been verified in proteus software.
EXP NO: 8 (b)
INTERFACING OF STEPPER MOTOR
DATE
AIM:
To write a program for interfacing of stepper motor using Keil software and proteus
software.
APPARATUS REQUIRED :
Keil µ vision 5 software
Proteus software
PROCEDURE :
Open the keil software and create a new project.
Open the new file and save the name. A
Write a program and check the error if any.
Create a hex file of this program.
Open the proteus software and click a new project.
Design the stepper motor and add the hexfile.
Finally run the stepper motor to see the output.
PROGRAM:
ORG 0000H
UP:MOV P2,#09H
ACALL DELAY
MOV P2,#0CH
ACALL DELAY
MOV P2,#06H
ACALL DELAY
MOV P2,#03H
ACALL DELAY
SJMP UP
DELAY:MOV R4,#18
H1:MOV R3,#255
H2:DJNZ R3,H2
DJNZ R4,H1
RET
END
OUTPUT
RESULT:
Thus, the assembly language program for performing the interfacing of the stepper motor
using Keil software and the output has been verified in proteus software.