CS3691 - ES & IOT Lab
CS3691 - ES & IOT Lab
LAB MANUAL
III- Semester
LIST OF EXERCISES
PART – I
5.DATA TRANSFER
6.BLOCK EXCHANGE
7.LARGEST/SMALLEST NUMBER
8.ASENDING/DESENDING ORDER
PART – II
EMBEDDED C LANGUAGE
1.ADDITION
2.SUBTRACTION
3.MULTIPLICATION
4.DIVISION
INTRODUCTION TO 8051 MICROCONTROLLER
The 8051 memory is organized in a Harvard Architecture. Both the code memory space
and data memory space begin at location 0x00 for internal or external memory which is different
from the Princeton Architecture where code and data share same memory space. The advantage
of the Harvard Architecture is not only doubling the memory capacity of the microcontroller
with same number of address lines but also increases the reliability of the microcontroller, since
there are no instructions to write to the code memory which is read only.
Timer means which can give the delay of particular time between some events. For
example on or off the lights after every 2 sec. This delay can be provided through some assembly
program but in microcontroller two hardware pins are available for delay generation. These
hardware pins can be also used for counting some external events. How much times a number is
repeated in the given table is calculated by the counter.
In MC8051, two timer pins are available T0 and T1, by these timers we can give the
delay of particular time if we use these in timer mode. We can count external pulses at these
pins if we use these pins in counter mode. 16 bits timers are available. Means we can generate
delay between 0000H to FFFFH. Two special function registers are available. If we want to
load T0 with 16 bit data then we can load separate lower 8 bit in TL0 and higher 8 bit in TH0. In
the same way for T1. TMOD, TCON registers are used for controlling timer operation.
Serial Port
There are two pins available for serial communication TXD and RXD. Normally TXD is used
for transmitting serial data which is in SBUF register, RXD is used for receiving the serial data.
SCON register is used for controlling the operation.
Interrupts
Interrupts are defined as requests because they can be refused (masked) if they are not
used, that is when an interrupt is acknowledged. A special set of events or routines are followed
to handle the interrupts. These special routines are known as interrupt handler or interrupt service
routines (ISR). These are located at a special location in memory. • INT0 and INT1 are the pins
for external interrupts.
Pin Description
The EA' (External Access) pin is used to control the internal or external memory access.
The signal 0 is for external memory access and signal 1 for internal memory access. The
PSEN' (Program Store Enable) is for reading external code memory when it is low (0) and EA
is also 0. The ALE (Address Latch Enable) activates the port 0 joined with port 2 to provide 16
bit external address bus to access the external memory. The ALE multiplexes the P0: 1 for
latching address on P0 as A0-A7 in the 16 bit address buss, 0 for latching P0 as data I/O. P0.x
is named ADx because P0 is multiplexed for Address bus and Data bus at different clock time.
WR' provides the signal to write external data memory RD' provides the signal to read external
data and code memory.
PORT P1 (Pins 1 to 8): The port P1 is a port dedicated for general I/O purpose. The other ports
P0, P2 and P3 have dual roles in addition to their basic I/O function.
PORT P0 (pins 32 to 39): When the external memory access is required then Port P0 is
multiplexed for address bus and data bus that can be used to access external memory in
conjunction with port P2. P0 acts as A0-A7 in address bus and D0-D7 for port data. It can be
used for general purpose I/O if no external memory presents.
PORT P2 (pins 21 to 28): Similar to P0, the port P2 can also play a role (A8-A15) in the
address bus in conjunction with PORT P0 to access external memory.
PORT P3 (Pins 10 to 17): In addition to acting as a normal I/O port,
P3.0 can be used for serial receive input pin(RXD) • P3.1 can be used for serial
transmit output pin(TXD) in a serial port,
P3.2 and P3.3 can be used as external interrupt pins(INT0’ and INT1’),
P3.4 and P3.5 are used for external counter input pins(T0 and T1),
P3.6 and P3.7 can be used as external data memory write and read control signal
pins(WR’ and RD’)read and write pins for memory access.
5. Set the Target options using -> Project – Options for Target opens the
µ Options for Target – Target configuration dialog. Set the Xtal
(Crystal frequency) frequency as 11.0592 MHz, and also the Options for
Target
– Debug – use either Simulator / Keil Monitor- 51 driver.
6. If Keil Monitor- 51 driver is used click on Settings -> COM Port settings select
the COM Port to which the board is connected and select the baud rate as
19200 or 9600 (recommended). Enable Serial Interrupt option if the user
application is not using on-chip UART, to stop program execution.
7. Build the project; using Project -> Build Project.
application and links. Any errors in the code are indicated by – “Target not
created” in the Build window, along with the error line. Debug the errors. After
anerror free, to build go to Debug mode.
8. Now user can enter into Debug mode with Debug- Start / Stop Debug session
Running. Also the (reset, run, halt) icons can be used. Additional
icons are (step, step over, and step into, run till cursor).
10. If it is an interface program the outputs can be seen on the LCD, CRO, motor, led
status, etc. If it is a part-A program, the appropriate memory window is opened
using View -> memory window (for data RAM & XRAM locations), Watch
window (for timer program), serial window, etc.
11. Note: To access data RAM area type address as D: 0020h. Similarly to access the
DPTR region (XRAM-present on chip in AT89C51ED2) say 9000h location type
in X: 09000H.
EXERCISE - 1
16 BIT ADDITION
AIM:
SOFTWARE REQURIED:
ALGORTHIM:
1. Start.
2. Write the program in KEIL.
3. If no errors and warnings.
4. Executed the program.
5. Note the address and opcode
6. Stop
PROGRAM:
ORG 0000H
MOV DPTR,#4300H
MOVX A,@DPTR
MOV R0,A
INC DPTR
MOVX A,@DPTR
MOV R1,A
INC DPTR
MOVX A,@DPTR
MOV R2,A
INC DPTR
MOVX A,@DPTR
MOV R3,A
MOV A,R0
ADDC A,R2
MOV DPTR,#4500H
MOVX @DPTR,A
MOV A,R1
ADDC A,R3
MOV DPTR,#4501H
MOVX @DPTR,A
END
LOCATION DATA
INPUT 4300H 05
4301H 10
4302H 15
4303H 20
OUTPUT 4500H 1A
4501H 30
Result :
16 BIT SUBTRACTION
AIM:
SOFTWARE REQURIED:
ALGORTHIM:
7. Start.
8. Write the program in KEIL.
9. If no errors and warnings.
10. Executed the program.
11. Note the address and opcode
12. Stop
PROGRAM OF SUBSTRACTION:
ORG 0000H
LJMP MAIN
MAIN:
MOV A,#34H
MOV B, #12H
SUBB A, B
MOV R0,A
MOV A, #B4H
MOV B,#C2H
SUBB A, B
MOV R1,A
END
LOCATION DATA
INPUT
OUTPUT
RESULT:
AIM:
SOFTWARE REQURIED:
ALGORTHIM:
13. Start.
14. Write the program in KEIL.
15. If no errors and warnings.
16. Executed the program.
17. Note the address and opcode
18. Stop
PROGRAM:
ORG 0000H
MOV A,40H
MOV B,41H
MUL AB
MOV 42H,A
MOV A,B
MOV 43H,A
END
OUTPUT:
LOCATION DATA
INPUT 40H 02
41H 02
OUTPUT 42H 04
43H 00
RESULT:
8- BIT DIVISION
AIM:
SOFTWARE REQURIED:
ALGORTHIM:
19. Start.
20. Write the program in KEIL.
21. If no errors and warnings.
22. Executed the program.
23. Note the address and opcode
24. Stop
PROGRAM:
ORG 000H
MOV A,40H
MOV B,41H
DIV AB
MOV 42H,A
MOV A,B
MOV 43H,A
END
OUTPUT:
LOCATION DATA
INPUT 40H 02
41H 02
OUTPUT 42H 01
43H 00
RESULT:
DATA TRANSFER
AIM:
SOFTWARE REQURIED:
PROGRAM:
MOV R0,#50H // Initialize the source memory pointer
MOV R1,#60H // Initialize the destination memory pointer
Before execution:
D:0x50H: 22 AB 03 44 55 00
D:0X60H: 00 00 00 00 00 00
After execution:
D:0x50H: 22 AB 03 44 55 00
D:0X60H: 22 AB 03 44 55 00
RESULT:
Transfer A Block Of Data Bytes From Source Memory To Destination Memory
Using 8051 is performed.
EXERCISE - 6
BLOCK EXCHANGE
AIM:
SOFTWARE REQURIED:
PROGRAM:
MOV R0,#50H // Initialize the source memory pointer
MOV R1,#60H // Initialize the destination memory pointer
MOV R2,#05H // Initialize Iteration counter
BACK: MOV A,@R0 // Get the data from source memory pointer and Load
// into Accumulator
XCH A,@R1 // Exchange data between Accumulator and
// destination memory pointer
MOV @R0,A // Store the data into source memory pointer
INC R0 // Increment the source memory pointer
INC R1 // Increment the destination memory pointer
DJNZ R2, BACK /* Decrement iteration count and if it is not zero,go to
relative Address and repeat the same process
until count become zero*/
END
MEMORY WINDOW:
Before execution:
D:0x50H: 01 02 03 04 05 00
D:0X60H: 06 07 08 09 10 00
After execution:
D:0x50H: 06 07 08 09 10 00
D:0X60H: 01 02 03 04 05 00
RESULT:
AIM:
SOFTWARE REQURIED:
Before execution:
D:0x50h: 22 AB 3D 44 55 00
D:0x60h: 00 00 00 00 00 00
After execution:
D:0x50h: 22 AB 3D 44 55 00
D:0x60h: AB 00 00 00 00 00
RESULT:
SMALLEST NUMBER
AIM:
SOFTWARE REQURIED:
Before execution:
D:0x50H: 22 AB 3D 44 55 00
D:0X60H: 00 00 00 00 00 00
After execution:
D:0x50H: 22 AB 3D 44 55 00
D:0X60H: 22 00 00 00 00 00
RESULT:
ASCENDING ORDER
AIM:
SOFTWARE REQURIED:
PROGRAM:
Before execution:
D:0x50H: 06 04 03 07 02 01
After execution:
D:0x50H: 01 02 03 04 06 07
RESULT:
ASCENDING ORDER
AIM:
SOFTWARE REQURIED:
PROGRAM:
MOV R2, #05H // Initialize the iteration counter
DEC R2 // Decrement the iteration count
BACK1: MOV R0, #50H // Initialize memory pointer1 MOV
R1, #51H // Initialize memory pointer2
MOV A, R2 // Store outer loop count
MOV R3, A // Store inner loop count
BACK: MOV A,@R0 // Get the data from memory pointer1 MOV
B,@R1 // Get the data from memory pointer2
CJNE A, B, LOOP // Compare if not equal go to relative address (LOOP) LOOP:
JNC LOOP1 // If carry generates, go to relative address (LOOP1)MOV @R0,B //
Exchange the data in memory pointer
MOV @R1, A
LOOP1: INC R0 // Increment the memory pointer1
INC R1 // Increment the memory pointer2
DJNZ R3, BACK /* Decrement inner loop count, if not zero go to back*/ DJNZ
R2, BACK1 /* Decrement outer loop count, if not zero go to back1*/ END
MEMORY WINDOW:
Before execution:
D:0x50H: 06 04 03 07 02 01
After execution:
D:0x50H: 07 06 04 03 02 01
RESULT:
AIM:
SOFTWARE REQURIED:
ALGORTHIM:
1. Start.
2. Write the program in KEIL.
3. If no errors and warnings.
4. Executed the program.
5. Stop
PROGRAM:
#include<reg51.h>
voidmain(void)
a=0x02;
b=0x03;
P1=0x00;
P1=a+b;
OUTPUT:
RESULT:
Embedded C program of Addition is Performed.
EXERCISE - 12
AIM:
SOFTWARE REQURIED:
ALGORTHIM:
6. Start.
7. Write the program in KEIL.
8. If no errors and warnings.
9. Executed the program.
10. Stop
PROGRAM:
#include<reg51.h>
voidmain(void)
a=0x05;
b=0x03;
P1=0x00;
P1=a-b;
OUTPUT:
RESULT:
Embedded C program of Subtraction is Performed.
EXERCISE - 13
AIM:
SOFTWARE REQURIED:
ALGORTHIM:
11. Start.
12. Write the program in KEIL.
13. If no errors and warnings.
14. Executed the program.
15. Stop
PROGRAM:
#include<reg51.h>
voidmain(void)
a=0x05;
b=0x02;
P1=0x00;
P1=a*b;
OUTPUT:
RESULT:
Embedded C program of Multiplication is Performed.
EXERCISE - 14
AIM:
SOFTWARE REQURIED:
ALGORTHIM:
1. Start.
2. Write the program in KEIL.
3. If no errors and warnings.
4. Executed the program.
5. Stop
PROGRAM:
#include<reg51.h>
voidmain(void)
a=0x06;
b=0x02;
P1=a / b;
OUTPUT:
RESULT:
Embedded C program of Multiplication is Division.