0% found this document useful (0 votes)
741 views34 pages

ET3491: 8051 Programming Manual

The document is a laboratory manual for the ET3491 Embedded Systems and IoT Design course, detailing various experiments using the 8051 microcontroller with Keil software. Each experiment includes an aim, required apparatus, procedure, program code, output, and results, covering topics such as arithmetic operations, waveform generation, on-chip and serial ports, digital clock design, ADC/DAC interfacing, and LED blinking. The manual serves as a comprehensive guide for students to learn and verify their programming skills in embedded systems.

Uploaded by

naveenmani8025
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
741 views34 pages

ET3491: 8051 Programming Manual

The document is a laboratory manual for the ET3491 Embedded Systems and IoT Design course, detailing various experiments using the 8051 microcontroller with Keil software. Each experiment includes an aim, required apparatus, procedure, program code, output, and results, covering topics such as arithmetic operations, waveform generation, on-chip and serial ports, digital clock design, ADC/DAC interfacing, and LED blinking. The manual serves as a comprehensive guide for students to learn and verify their programming skills in embedded systems.

Uploaded by

naveenmani8025
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

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.

Common questions

Powered by AI

Debugging and error checking are crucial for program development in embedded systems to ensure functional correctness, especially given the real-time operation constraints. Tools like Keil's build and debug options help identify syntax and logical errors, providing an interactive assessment of how programs manipulate memory and registers. This reduces deployment errors, ensuring that hardware behavior matches the design specifications, which is vital for high-reliability systems .

Interfacing an ADC with the 8051 involves initializing the serial control register with values for the desired communication protocol (SCON=0X50). Start and stop conditions are generated using sbit commands. Writing commands are used to send the start condition, followed by reading the ADC data. The digital value is converted using conversion functions and sent to the virtual terminal using SBUF for serial output once conversion is complete .

Implementing a digital clock using the 8051 microcontroller involves using timers and counters. Set the data pointer with MOV DPTR followed by incrementing various registers R0 to R5 for different time components like seconds, minutes, and hours. Jump instructions (CJNE) are used to check and increment the time registers, and logic is implemented to reset after reaching respective limits (e.g., 6 for minutes).

Data conversion in microcontroller systems typically involves basic operations such as division and modulus to separate digit values followed by bitwise operations for ASCII conversion. Instructions like MOVC fetch data from code memory, and SBUF send converted characters to serial output interfaces. The commands are executed in a loop to ensure all data pieces are processed. Such techniques, combined with delay subroutines, ensure synchronized data output .

Interfacing a keyboard with the 8051 involves setting up port pins for column and row connections. Use C program functions to check active key presses in rows and columns by sending and reading signals. Implement delay functions to debounce keys. Each key press corresponds to a character output function that sends corresponding display data to an LCD initialized in 4-bit mode. Commands are sent using lcd_cmd and lcd_data functions defined in the program .

To generate a square waveform using the 8051 microcontroller and Keil software, first, define the start of the program memory using ORG 0000. Clear the accumulator, use MOV instructions to move appropriate values to the ports configured for waveform generation, and employ jump instructions such as SJMP to create a loop between high and low states. P2 is configured and toggled between 0H and 50H to generate square waveforms .

A stepper motor can be interfaced with the 8051 microcontroller by sending specific sequences to the port controlling the motor coils. Begin by moving predefined bit patterns, like 09H, 0CH, 06H, and 03H, into an output port (P2) to energize the coils in the right sequence needed for stepping the motor. A delay routine is implemented to control the speed of rotation, and SJMP UP creates a loop to repeat the sequence continuously .

To program on-chip ports in the 8051 microcontroller using Keil software, initialize port pins using instructions like MOV to set P1. Enter a main loop where the port is read, complemented, and the result is outputted on another port. Use SJMP for indefinite looping and debugging features such as viewing register values via the F11 button and executing the code using the run button to check the output on port 2 .

Keil and Proteus software together provide a comprehensive environment for the development and simulation of embedded systems. Keil's µVision allows for creating and editing assembly/C programs with debugging features such as watching register and memory values. Proteus complements Keil by simulating hardware implementations, running hex files, and visually verifying digital designs like waveforms, ports, and interfacing modules, thus facilitating a holistic design-to-deployment workflow .

To perform arithmetic and logical operations using the 8051 microcontroller in assembly language, one can use instructions such as MOV to transfer data to registers. For addition, use ADD A, B; for subtraction, SUBB A, B; for multiplication, MUL AB; for division, DIV AB; and similarly, for logical operations, use ANL A, B for AND and ORL A, B for OR operations. The operations are executed, and results are saved to specific memory addresses such as 40H for addition results .

You might also like