Mca Lab-Ece-3014-Manual - Ay 2022-23
Mca Lab-Ece-3014-Manual - Ay 2022-23
Mca Lab-Ece-3014-Manual - Ay 2022-23
for
VI Semester B. Tech.
Presidency University
School of Engineering
Itagalpura, Rajanukunte, Yelahanka,
Bangalore-560064
CONTENTS Page
No.
I Course Handout 3-9
II Precautions 10
10
III Tools and operating system required
5. Code conversion: BCD – ASCII; ASCII – Decimal; HEX – Decimal and Decimal –
31 - 33
HEX
7. Generate different waveforms Sine, Square, Triangular, Ramp etc. using DAC
39-44
interface to 8051; change the frequency and amplitude
(Established under the Presidency University Act, 2013 of the Karnataka Act 41 of 2013)
[2022-23 EVEN/ WINTER SEMESTER]
COURSE HAND OUT [Revision 02 - Jan 2022]
SCHOOL: SOE DEPT.: ECE DATE OF ISSUE: 23-1-2023
CONTACT HOURS : 3 Periods per Week Theory and 2 Periods for Lab
COURSE INSTRUCTOR : Mr. Syed Abrar Ahmed, Mr. Tony Aby Varkey M,
Mrs. Kehkeshan Jallal S
COURSE URL : www.camu.in
PROGRAM OUTCOMES: (Bolded outcomes are met by this course. Others are not met.)
Graduates of the B. Tech. Program in Electronics and Communication Engineering will be able to:
PO.3. Design/development of Solutions: Design solutions for complex engineering problems and design
system components or processes that meet th e specified needs with appropriate consideration for the
public health and safety, and the cultural, societal, and environmental considerations.
PO.4. Conduct Investigations of Complex Problems: Use research-based knowledge and research methods
including design of experiments, analysis and interpretation of data, and synthesis of the information to
provide valid conclusions.
PO.5. Modern Tool usage: Create, select, and apply appropriate techniques, resources, and modern
engineering and IT tools including prediction and modelling to complex engineering activities with an
understanding of the limitations.
PO.6. The Engineer and Society: Apply reasoning informed by the contextual knowledge to assess societal,
health, safety, legal and cultural issues and the consequent responsibilities relevant to the professional
engineering practice.
PO.7. Environment and Sustainability: Understand the impact of the professional engineering solutions in
societal and environmental contexts, and demonstrate the knowledge of, and need for sustainable
development.
PO.8. Ethics: Apply ethical principles and commit to professional ethics and responsibilities and norms of
the engineering practice.
PO.9. Individual and Team Work: Function effectively as an individual, and as a member or leader in
diverse teams, and in multidisciplinary settings.
PO.10. Communication: Communicate effectively on complex engineering activities with the
engineering community and with society at large, such as, being able to comprehend and write
effective reports and design documentation, make effective presentations, and give and receive clear
instructions.
PO.11. Project Management and Finance: Demonstrate knowledge and understanding of the engineering and
management principles and apply these to one’s own work, as a member and leader in a team, to manage
projects and in multidisciplinary environments.
PO.12. Life-long Learning: Recognize the need for, and have the preparation and ability to engage in
independent and life-long learning in the broadest context of technological change.
COURSE PREREQUISITES:
Student should have successfully completed ECE 3014
COURSE DESCRIPTION:
COURSE OUTCOMES:
After the completion of the course students shall be able to:
CO. PO1
PO1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 PO11 P12
NO. 0
1. H L L
2. H H M M L
3. H H H H H M M
4. H H H H H M M
5. H H M H H M M
6. H H M H M M M
List of Experiments
Sl. Experi
Experiment Name List of skill set CO
No ment no
CO2,
i) Understand the various types of CO3
bit manipulation instructions.
Boolean & Logical Instructions
5. 4 (Bit manipulations) ii) Write an ALP to realize the
given Boolean expression .iii)
Obtain the simulation output and
analyze the results.
2. P2 Experiment 1
3. P3 Experiment 2
4. P4 Experiment 2
5. P5 Experiment 3
6. P6 Experiment 4
7. P7 Practice session I
8. P8 Mid-term Evaluation
9. P9 Experiment 5
* These dates are only indicative - applicable to one section handled by subject IC. Dates will vary from
section to section.
ASSESSMENT SCHEDULE:
Sl. Course
Assessment type Duration Venue, DATE
No List of Tasks outcome Marks weightage
In Hours &TIME
. Number
Experiment
Lab Exercises 1 to MCA Lab
(Conduction Experiment 9 Every week 2
of lab exercises CO
1. And the NA 40 20% hours
conducted in every 2,3,4
assignment
lab including lab
and seminar
records(20 M))
tasks
3 2 2 3 10
PRECAUTIONS
INTRODUCTION
The 8051 is the name of a big family of microcontrollers. The device which we are going to use
along this tutorial is the 'AT89S52' which is a typical 8051 microcontroller manufactured by
Atmel™. Note that this part doesn't aim to explain the functioning of the different components of
a 89S52 microcontroller, but rather to give you a general idea of the organization of the chip and
the available features, which shall be explained in detail along this tutorial.
The block diagram provided by Atmel™ in their datasheet showing the architecture the
89S52 device can seem very complicated, and since we are going to use the C high level
language to program it, a simpler architecture can be represented as the figure
This figures shows the main features and components that the designer can interact with.
You can notice that the 89S52 has 4 different ports, each one having 8 Input/output lines
providing a total of 32 I/O lines. Those ports can be used to output DATA and orders do other
devices, or to read the state of a sensor, or a switch. Most of the ports of the 89S52have 'dual
function' meaning that they can be used for two different functions: the first one is to perform
input/output operations and the second one is used to implement special features of the
microcontroller like counting external pulses, interrupting the execution of the program
according to external events, performing serial data transfer or connecting the chip to a computer
to update the software.
Each port has 8 pins, and will be treated from the software point of view as an 8-bit variable
called 'register', each bit being connected to a different Input/output pin. You can also notice two
different memory types: RAM and EEPROM. Shortly, RAM is used to store variable during
program execution, while the EEPROM memory is used to store the program itself, that's why it
is often referred to as the 'program memory'. The memory organization will be discussed in
detail later.
The special features of the 89S52 microcontroller are grouped in the blue box at the bottom of
figure At this stage of the tutorial, it is just important to note that the 89S52 incorporates
hardware circuits that can be used to prevent the processor from executing various repetitive
tasks and save processing power for more complex calculations. Those simple tasks can be
counting the number of external pulses on a pin, or generating precise timing sequences.
Features of 8051:
The main features of 8051 microcontroller are:
1) RAM – 128 Bytes (Data memory)
2) ROM – 4Kbytes (ROM signify the on – chip program space)
3) Serial Port – Using UART makes it simpler to interface for serial communication.
4) Two 16 bit Timer/ Counter
5) Input/output Pins – 4 Ports of 8 bits each on a single chip.
6) Five Interrupt Sources
7) 8 – bit ALU (Arithmetic Logic Unit)
8) Harvard Memory Architecture – It has 16 bit Address bus (each of RAM and ROM) and 8 bit Data
Bus.
9) 8051 can execute 1 million one cycle instructions per second with a clock frequency of 12MHz.
This microcontroller is also called as “System on a chip” because it has all the features on a single chip
AT89C51ED2 MICROCONTROLLER
Description
AT89C51RD2/ED2 is high performance CMOS Flash version of the 80C51 CMOS single chip
8- bit microcontroller. It contains a 64-Kbyte Flash memory block for code and for data. The 64-
Kbytes Flash memory can be programmed either in parallel mode or in serial mode with the ISP
capability or with software. The programming voltage is internally generated from the standard
VCC pin.
The AT89C51RD2/ED2 retains all of the features of the Atmel 80C51 with 256 bytes of internal
RAM, a 5 source 4-level interrupt controller and three timer/counters. TheAT89C51ED2
provides 2048 bytes of EEPROM for non-volatile data storage. In addition, the
AT89C51RD2/ED2 has a Programmable Counter Array, an XRAM of 1792bytes, a Hardware
Watchdog Timer, SPI interface, Keyboard, a more versatile serial channel that facilitates
multiprocessor communication (EUART) and a speed improvement mechanism (X2 Mode). The
fully static design of the AT89C51RD2/ED2 allows reducing system power consumption by
bringing the clock frequency down to any value, including DC, without loss of data.
Clock prescaler for further reduction in power consumption. In the Idle mode the CPU is frozen
while the peripherals and the interrupt system are still operating. In the Power-down mode the
RAM is saved and all other functions are inoperative.
The added features of the AT89C51RD2/ED2 make it more powerful for applications that need
pulse width modulation, high speed I/O and counting capabilities such as alarms, motor control,
corded phones, and smart card readers.
INTERUPTS
Five sources of interrupt (both external and internal).
Two External interrupts INTO and INTI are provided with push button switches: these can
also be used as general-purpose switches.
I/O (Port) Lines Four 10-pin connectors for all the 32 I/O lines.
project window browse for the created project folder type the project name
<pro1.µv2> click ok
4. To create a file:gotofile menu click new type the program in editor window
5. Toadd the files to source group : right click source group in project work space
6. Build the project:gotoProject menu click Build Project (note: if the target not
Experiment 1
1. Data Transfer - Block move, Exchange, Sorting, Finding largest element in an array
1a) Data Transfer
Aim: To write an ALP to transfer block data from one memory location to another
Program: 8051 program
ORG 00H
MOV R2 ,#04H ; No of elements = 4
MOV R0, #40H ; block 1 address
MOV R1, #50H ; block 2 address
NXT_LOC:
MOV A,@R0 ; transfer the element in present address
MOV @R1, A
INC R0 ; go to next element address of block1
INC R1 ; go to next element address of block2
DJNZ R2, NXT_LOC ; jump to NXT_LOC for next element
; Transfer till the end of an array
END
Result:
I/P:
O/P:
END
Result:
I/P:
O/P:
O/P:
END
Result:
I/P:
O/P:
Experiment 2
2. Arithmetic Instructions - Addition/subtraction, multiplication and division, square, Cube – (16
bits Arithmetic operations – bit addressable)
2a) Multi byte addition
Aim: To write an ALP to find the sum of 2 16 bit number
Program:
ORG 00H
MOV R0,#40H ;address of Lower byte of 1st number
MOV R1,#50H ; address of Lower byte of 2nd number
MOV A,@R0
ADDC A,@R1 ; add lower bytes of 2 numbers
MOV 60H,A ; save the lower byte of sum in 60h
INC R0 ; address of higher byte of 1st number
INC R1 ; address of higher byte of 2nd number
MOV A,@R0 ; add the higher bytes of 2 numbers with
ADDC A,@R1 ; along with carry generated by lower byte Addition
MOV 61H,A ; save the second byte of sum in 61h
MOV 62H,#00H
JNC N_C
MOV 62H,#01H ; save the third byte of sum in 62h
N_C: END
Result:
I/P:
O/P:
Result:
I/P:
O/P:
P2 P1 B3B1
+ P4 P3 B4B1
P6 P5 P1
+ P8 P7 B3B2
P11 P10 P9 P1
+ P13 P12 B4B2
P15 P14 P9 P1
Save in 63h 62h 61h 60h
ORG 00H
MOV A,20H ;lower byte of 1st number (say B1)
MOV B,40H ;lower byte of 2nd number (say B3)
MUL AB ; B3xB1= product of 16 bit say (P2 P1)
MOV 60H,A ;[60h]=P1
MOV 61H,B ;[61h]=P2
MOV A,21H
MOV B,40H
MUL AB
ADD A,61H
MOV 61H,A
MOV A,B
ADDC A,62H
MOV 62H,A
MOV A,#00
ADDC A,#00
MOV 63H,A
MOV A,21H
MOV B,41H
MUL AB
ADD A,62H
MOV 62H,A
MOV A,B
ADDC A,63H
MOV 63H,A
END
Result:
I/P:
O/P:
2d) Division
Aim: To write an ALP to divide 16 bit number by 8 bit number
Program: 8051 program
ORG 00H
MOV DPTR,#2000H
MOVX A,@DPTR
MOV B,A
MOV DPTR,#2001H
MOVX A,@DPTR
DIV AB
MOV DPTR,#2010H
MOVX @DPTR,A
END
Result:
I/P:
O/P:
O/P:
Experiment 3
Counters
Aim: To write an ALP to count decimal UP
Program: 8051 program
ORG 00H
MOV A,40H
NXT_CNT: MOV P1,A
ADD A,#01H ADD A,#0FFH (FOR BINARY DOWN) ,
ADD A,#99H ( FOR DECIMAL DOWN)
DA A ; DELETE THIS INSTRUCTION FOR BINARY COUNTER
ACALL DELAY
CJNE A,41H,NXT_CNT
MOV P1,A
RET
Experiment 4
4. Boolean & Logical Instructions (Bit manipulations)
Aim: To write an ALP to realise the given Boolean expression
Program: 8051 program
Y=ABC'+AB'C+AB'C'
ORG 00H
MOV C,20H
ANL C,01H
ANL C,/00H
MOV 8H,C
MOV C,20H
ANL C,/01H
ANL C,00H
ORL C,8
MOV 8,C
MOV C,20H
ANL C,/01H
ANL C,/00H
ORL C,8
MOV 8,C
END
Result:
Truth Table
A B C Y=ABC'+AB'C+AB'C'
0 0 0 0
0 0 1 0
0 1 0 0
0 1 1 0
1 0 0 1
1 0 1 1
1 1 0 1
1 1 1 0
Experiment 5
5. Code conversion: BCD – ASCII; ASCII – Decimal; HEX - Decimal and Decimal - HEX
5a) BCD - ASCII
Aim: To write an ALP to find the ASCII code of given BCD number
Program: 8051 program
ORG 0000
MOV A,40H
ANL A,#0F0H
SWAP A
ADD A,#30H
MOV 41H,A
MOV A,40H
ANL A,#0FH
ADD A,#30H
MOV 42H,A
SJMP $
END
Result:
I/P:
O/P:
Result:
I/P:
O/P:
Result:
I/P:
O/P:
Result:
Run 1
Run 2
8051
ADC Interface
& relay control
P0 for heater
P3 LCD Interface
P2
Interfacing Diagram
Program:
//#include "D:\Keil\C51\INC\Atmel\reg51f.h"
#include<at89c51xd2.h>
#include<stdio.h>
// LCD FUNCTION PROTOTYPE
voidlcd_init(void);
voidlcd_comm(void);
voidlcd_data(void);
void delay(int);
floatadc_temp;
sbit EOC = P0^4;
sbit START_ALE = P0^7;
unsigned char xdata arr1[12]={"ADC O/P = "};
unsigned char xdata arr2[12]={"ADC I/P = "};
unsigned char i,a,temp_hi,temp_low;
unsignedint vtemp1,adc_val;
unsigned char temp_msg[]={" "};
void main ()
{
START_ALE = 0;
lcd_init();
temp1 = 0x80; // Display the data from first position of first line
lcd_comm(); // Command Writing
for(i=0;i<10;i++)
{
temp2 = arr1[i];
lcd_data(); // Data Writing
}
delay(200);
while(1)
{
P0 &= 0xF0; // Select the as input channel
temp_hi=adc_val>>4;
temp_hi=temp_hi& 0x0f;
temp_low=adc_val& 0x0f;
if(temp_low>9)
temp_low = temp_low + 0x37;
else
temp_low = temp_low + '0';
delay(100);
temp_msg[1] = temp_hi ;
temp_msg[2] = temp_low ;
temp1 = 0x8A;
lcd_comm(); // Command Writing
temp2 = temp_hi;
lcd_data();
temp2 = temp_low;
lcd_data();
adc_temp = (int)(adc_temp*100);
i=100;
for(a=0;a<4;a++)
{
buf[a] = adc_temp / i;
adc_temp -= buf[a] * i;
buf[a] += '0';
i /= 10;
}
buf[3] = buf[2];
buf[2] = buf[1];
buf[1] = '.';
buf[4] = '\0';
temp1 = 0xC0;
lcd_comm(); // Displaying at 1st line of LCD
for(i=0;i<10;i++)
{
temp2 = arr2[i];
lcd_data(); // Data Writing
}
for(i=0;(buf[i]!='\0');i++)
{
temp2 = buf[i];
lcd_data();
}
} // end of while(1)
}
Result:
Thus the program was executed successfully and the output is seen.
7. Generate different waveforms Sine, Square, Triangular, Ramp etc. using DAC interface
to 8051; change the frequency and amplitude.
Aim: To interface DAC and to write a C program to generate sine, square, triangle and ramp
waveforms
8051
P0 DAC Interface CRO
Module
}
}
#include<at89c51xd2.h>
// variables used:
// msg : a character array contains the string to output
// on to lcd
// cptr : character pointer used to point to msg array
// required to pass to function lcd_outstr()
void delay(void);
//unsigned char xdatamsg[]={"Square"};
//unsigned char xdata *cptr;
void main ()
{
// the program is in a endless loop
// ie it executes the code within while(1) for ever
// program ouputs 0 and 0xff alternatively to port P0
// with a delay in between
// user can observe square waveform at dac output
while(1)
{
P0 = 0x0;
delay();
P0 = 0xff;
delay();
{
Int i;
for(i=0;i<=300;i++);
}
for(count=0xff; count>0;count--)
{
P0=count;
}
}
}
while(1)
{
P0 = count; // output count to Port P0
count++; // increment count
}
}
Result:
Thus the program was executed successfully and the output is seen.
5V GND
8051
Stepper Motor
P0 Interface Stepper
Module Motor
**************************************************************************/
Program:
#include "at89c51xd2.h"
static bit Dir=0;
sbit buzzer = P0^5;
while(1)
{
if(Dir) //* If Dir Clockwise
{
Val = 0x08;
for(i=0;i<4;i++)
{
P0 = Val; //* Write data for clock wise direction
Val = Val>>1;
delay(575);
}
}
else // AntiClockwise Direction
{
Val = 0x01;
for(i=0;i<4;i++)
{
P0 = Val; // Write data for anticlock wise direction
Val = Val<<1;
delay(575);
}
}
}
}
10b) DC motor
8051
DC Motor
P0 Interface DC Motor
Module
#include "at89c51xd2.h"
off_time = 1000;
on_time = 1000;
while(1)
{
DC1 = DC2 = 0 ; // make P0.6 & P0.7 lo
// 0;
for(i=0;i<on_time;i++)
{
TL0 = 0x00 ; //timer count set for delay
TH0 = 0x10 ;
TR0 =1; // Timer-0 ON
while(!TF0); // Wait untill Timer-0 Overflows
TF0 = 0; // Clear Overflow flag
TR0 = 0; // Timer-0 OFF
}
DC1 = 0 ; // make P0.6 high & make P0.7 low
DC2 = 1;
for(i=0;i<off_time;i++)
{
TL0 = 0x00; //timer count set for delay
TH0 = 0x10;
TR0 =1; // Timer-0 ON
while(!TF0); // Wait untill Timer-0 Overflows
TF0 = 0; // Clear Overflow flag
}
Result: Thus the program was executed successfully and the output is seen.
SAMPLE VIVA QUESTIONS