MA Lab Manual - 2024-2025 RA - Second Year
MA Lab Manual - 2024-2025 RA - Second Year
Laboratory Manual
2024-2025
Semester - IV
Preface
Microcontroller and Applications
Microcontrollers are small computers that consist of a single System-on-Chip (SoC) that includes
a CPU, memory, and additional peripheral components. By using a single chip, the computing
element's footprint within the entire system package is reduced, obviating the need for additional
chips. Microcontrollers in this category include PIC, 8051 and many more. The 8-bit
Microcontroller C8051F340 from Silicon Labs, which employs the conventional 8051 architecture
with enhanced functionality needed to design embedded products, is included in this course.
Undergraduate students are introduced to the field of microcontrollers, including their definition,
operation, and interface with I/O devices such as keyboards, motors, and displays. Additionally,
hardware-based programming in assembly and embedded C is covered in the microcontroller
course. There will also be an explanation of several system design examples centered around these
CPUs. This course's lab consists of studies involving the C8051F340 peripheral interface.
Assembly and embedded C programming are done using Keil µvision and Simplicity Studio as the
IDE. Knowledge of Microcontroller enhances employability in companies specializing in
hardware development and semiconductor manufacturing. Microcontroller programming skills are
highly sought after by companies involved in the development of embedded products.
Microcontroller and Applications
INDEX
CERTIFICATE
Keil MicroVision is an Integrated Development Environment (IDE), which includes a text editor
to write programs, a compiler to convert the source code to hex files and a debugger to test, verify,
and optimize the application code.
Now Select the new folder and give the name to Project.
Step 2: After Creating project now Select your device model eg. Silicon Lab’s C8051F340
Step 3: So now your project is created and the Message window will appear to add the start-up file
of your device. Click on Yes so it will be added to your project folder you are programming in C
and click on No if you are programming in assembly.
Step 4: Now go to File and create new file and save it with .asm extension in the folder where you
created the project if you want to write program in assembly language
Step 6: After that on the left you see the project window [if it’s not there….go to View tab and
click on restore window to default].
Step 7: Now Expand target and you will see source group
Right click on group and click on Add existing files to source group
Now add your program file which you have written in C/assembly.
You can see the program file added under the source group.
Step 8: Now Click on translate and then Build target. You can find it under Project tab or in the
toolbar. It can also be done by pressing the F7 key.
Step 9: you can see Status of your program in Build output window
[If it’s not there go to view and click on Build output window]
Submitted on:
Aim:
1. Simple Assembly language programming.
a. Write assembly language program for addition of two 8-bit numbers.
b. Write assembly language program for addition of two 16-bit numbers.
b. Write assembly language program for addition of N 8-bit numbers Take the input numbers
from memory and store the result in memory.
2. Complex Assembly language programming.
a. Find the square of a number using DPTR.
b. Program to count number of 1’s in a given byte.
c. Program to count number of Odd and Even numbers from a given array.
d. Program to find positive and negative numbers
Theory:
Programming in the sense of Microcontrollers (or any computer) means writing a sequence
of instructions that are executed by the processor in a particular order to perform a predefined task.
The three levels of Programming Languages are as shown in figure 1.1.
▪ The Programs written in Assembly gets executed faster and they occupy less memory.
▪ With the help of Assembly Language, you can directly exploit all the features of a
Microcontroller.
▪ Using Assembly Language, you can have direct and accurate control of all the
Microcontroller’s resources like I/O Ports, RAM, SFRs, etc.
▪ Compared to High-level Languages, Assembly Language has less rules and restrictions.
CY AC FO RS1 RS0 OV UD P
CY Carry flag
OV Overflow flag
P Parity flag; P=1 for odd no. of 1’s; P=0 for Even no. of 1’s
Algorithm:
Sample Example:
Program:
Note: Attach the printout of the code and output
Conclusion:
Additional links:
1. https://nptel.ac.in/courses/108105102
2. https://www.electronicshub.org/8051-microcontroller-assembly-language-programming/
NOTE: Use this tool for Experiments No. 3 to 10. Draw the interfacing diagram ona separate sheet and
attach the printout of the tested code.
F340 Hardware
The EPB-F340Mini is a stand-alone card--allowing developers to evaluate the C8051F340 USB
Flash MCU Family to determine if it meets their application requirements. Furthermore, the
module is an excellent platform to develop and run software for the 8051 processor. The EPB-
F340Mini is shipped with a C8051F340. The EPB-F340Mini allows full speed verification of 8051
code. In addition, an onboard C2 connector provides interface to emulators, with assembly
language and ‘C’ high level language debug.
The ASK-25A has 10 connectors. The function of each connector is shown in the table below:
Table 3.2 ASK-25A connector description
Unit Reference Description
SPI PL1 6 Pins
I2C PL2 4 Pins
I/O Port PL3 GPIO
Stepper Motor Connector PL4 6 Pins Connector
DC Motor Connector PL5 2 Pin Green Terminal
Buzzer Connector PL6 2 Pin Connector
Relay Connector PL7 3 Pin Green Terminal
I/O Ports PL8 GPIO
Stepper Motor Power Supply PL9 Power Socket
Analog Output PL10 3 Pin Connector
S. Y. B. Tech (MECH-R&A)
Semester: IV Subject: Microcontroller and Applications
Name: Class:
Roll No: Batch:
Experiment No: 03 and 04
Name of the Experiment:
1. Interfacing of LED with C8051F340
2. Interfacing of LED, Buzzer, Relay and Switch with C8051F340
Performed on:
Marks Teacher’s Signature with date
Submitted on:
Aim: Write C program for interfacing of LED, Buzzer, Relay and Switch with C8051F340 to turn
it ON when key is pressed.
Apparatus: EPBF340 Board, ASK25 board, Connectors
Theory:
Ports in C8051F340:
Digital and analog resources are available through 40 I/O pins. These pins are available on ports.
C8051F340 has 5 ports, each port has eight pins. Each of the Port pins can be defined as general-
purpose I/O (GPIO) or analog input. This resource assignment flexibility is achieved through the
use of a Priority Crossbar Decoder. Registers XBR0, XBR1, and XBR2 are used to assign the
digital I/O resources to the physical I/O Port pins.
Expt. No 03 & 4: - Interfacing of LED, Buzzer, Relay and Switch with C8051F340
Step 5. Enable the Crossbar (XBARE = ‘1’).
SFR definitions:
Expt. No 03 & 4: - Interfacing of LED, Buzzer, Relay and Switch with C8051F340
LED, Buzzer, Relay and Switch:
LED: LED is an output device. 8 LEDs are connected to 8 port pins. The LEDs are connected in
common anode configuration. Thus, to turn ON the LED logic ‘0’ must be given and to turn OFF
the led logic ‘1’ must be given.
Buzzer: Buzzer is an output device. The buzzer is turned ON when logic ‘1’ is applied to the port
pin and turned OFF when logic ‘0’ is applied to port pin.
Relay: Relay is an output device. The relay is turned ON when logic ‘0’ is applied to port pin and
turned OFF when logic ‘1’ is applied to the port pin.
Switch/button: Switch is an input device. Push button switches are used. When the switch is
released the port pin has logic ‘1’ and when the switch is pushed the port pin has logic ‘0’.
Algorithm:
Interfacing Diagram:
Expt. No 03 & 4: - Interfacing of LED, Buzzer, Relay and Switch with C8051F340
Figure 3.4 LED, Buzzer, Relay, and Switch Interfacing Diagram
Hardware Connections:
Expt. No 03 & 4: - Interfacing of LED, Buzzer, Relay and Switch with C8051F340
Connect flat cable between PL8 connector of ASK25 and PL6 connector of EPBF340 board.
Connect other flat cable between PL3 connector of ASK25 and PL3 connector of EPBF340 board.
Table 3.3 Hardware connections between EPBF340 and ASK25 board
Expected Result:
LEDs, Buzzer and Relay should turn on when respective key is pressed.
Expt. No 03 & 4: - Interfacing of LED, Buzzer, Relay and Switch with C8051F340
Conclusion:
Study Question:
1. Explain the common anode and common cathode configuration of LED.
2. How many ports are available in C8051F340?
3. How to configure port as an input/output?
4. Explain Priority Crossbar Decoder.
Additional links:
1. https://www.silabs.com/documents/public/data-sheets/C8051F34x.pdf
2. https://aticleworld.com/interfacing-of-switch-and-led-using-the-8051/
Expt. No 03 & 4: - Interfacing of LED, Buzzer, Relay and Switch with C8051F340
S. Y. B. Tech (MECH-R&A)
Semester: IV Subject: Microcontroller and Applications
Name: Class:
Roll No: Batch:
Experiment No: 05
Name of the Experiment: Interfacing of LCD with C8051F340
Submitted on:
Aim: Write C program for interfacing of 16x2 LCD with C8051F340 in 8-bit mode.
Theory:
LCD has the ability to display letters, numbers and characters. A 16x2 LCD can display 16
characters per line and there are 2 such lines. In this LCD each character is displayed in 5x7 pixel
matrix.
LCD pin descriptions:
VCC VSS and VEE:
While VCC and VSS provide +5V and ground, respectively, VEE is used for controlling LCD
contrast.
Register Select (RS):
There are two very important registers inside the LCD. The RS pin is used for their
selection as follows.
a. RS = 0: the instruction command code register is selected, allowing the user to send a
command such as clear display, cursor at home.
b. RS = 1: the data register is selected, allowing the user to send the data to be displayed on
the LCD.
0 = Instruction input
4 RS 0/1 I
1 = Data input
15 VB+ 1 -
Backlight Supply
16 VB- 0 -
In 8-bit mode eight data pins are used. 8-bit ASCII value of a character is sent at a single
time period and displayed on the LCD.
Interfacing Diagram:
Hardware Connections:
Connect flat cable between PL3 connector of ASK25 and PL3 connector of EPBF340 board.
Table 4.2 Hardware connections between EPBF340 and ASK25 board for LCD Interfacing
Result:
String should be displayed on the LCD.
Conclusion:
Study Question:
1. Explain the 4-bit mode of LCD.
2. Explain the significance of RS pin and list commands of LCD.
Additional link:
1. https://www.electronicshub.org/interfacing-16x2-lcd-8051/
Submitted on:
Theory:
Analog to digital converter is among the most widely used device for data acquisition. It is
used to convert the analog signals to digital numbers so that microcontroller can read and process
them.
On-chip ADC Features:
● 10-Bit ADC
● Up to 200 ksps
● Built-in analog multiplexer with single-ended and differential mode
● VREF from external pin, internal reference, or VDD
Hardware Connections: Connect single lead wire between P2.5 (Pin15 of PL3 connector) of
EPBF340 board and Pin1 of PL10 connector of ASK25. To provide the ground also connect 20pin
flat cable between PL6 connector of EBF340 board and PL8 connector of ASK25.
Connect USB cable between PL8 connector of EPBF340 board and PC.
F340 Reference Device ASK25
P2.5 (Pin15 of PL3 connector) Pin 1 of PL10 connector (Pot RV2)
P0.4 TXD
P0.5 RXD
Result:
Digital output should be observed on the HyperTerminal.
Conclusion:
Study Question:
1. Give the main factor affecting the step size of ADC in C8051F340.
2. Give the formats for control registers associated with C8051F340 ADC.
Additional link:
https://www.silabs.com/documents/public/data-sheets/C8051F34x.pdf
Aim: Write C program to generation PWM using C8051F340 to control speed of DC motor
Theory:
DC Motors: A direct current (DC) motor is widely used device that translate electrical pulses into
mechanical movement. In the DC motor we have only + and _ leads. Connecting them to a DC
voltage source moves the motor in one direction. By reversing the polarity, the DC motor will
move in the opposite direction.
Unidirectional control:
The Programmable Counter Array (PCA0) provides enhanced timer functionality. The PCA
consists of a dedicated 16-bit counter/timer and five 16-bit capture/compare modules. Each
module can be used independently to generate a pulse width modulated (PWM) output on its
associated CEXn pin. The frequency of the output is dependent on the timebase for the PCA
counter/timer. The duty cycle of the PWM output signal is varied using the module's PCA0CPLn
capture/compare register.
Interfacing Diagram:
Hardware Connections: Output is available on Port pin P1.4. Observe waveform at pin no. 5
of PL3 connector of EPBF340 board with respect to ground on DSO/CRO. After this, connect
DC motor between the same pin.
Result:
The duty cycle of the PWM waveform should be observed on DSO/CRO.
OR
DC Motor should run with speed varying w.r.t the change in value of PWM.
Conclusion:
Study Question:
1. Define duty cycle.
2. Write the steps to program PCA to generate PWM
3. Write down the equations for the frequency and duty cycle of PWM in C8051F340
Additional links:
1. https://www.silabs.com/documents/public/data-sheets/C8051F34x.pdf
2. https://www.microcontroller-project.com/dc-motor-speed-control-using-8051-
microcontroller.html
Submitted on:
Aim: Write a C program for serial communication using C8051F340 to transfer data from
C8051F340 to PC
Hardware Connections: Connect USB cable between PL8 connector of EPBF340 board and PC.
Expected Result:
The string should be displayed on HyperTerminal.
Study Question:
1. Explain the need of MAX232 in serial communication.
2. Write the Port Properties for setting Hyper Terminal connection.
3. Explain UART registers.
Additional link:
https://exploreembedded.com/wiki/A4.8051_Communication_Protocols:UART,_RS232
Submitted on:
Aim: Write C program for interfacing of Stepper motor with C8051F340 to rotate in clockwise
and anticlockwise direction.
Theory:
A stepper motor is known by its important property to convert a train of pulses into a
precisely defined increment in the shaft position. A stepper motor is a widely used a device that
translates electrical pulses into mechanical movement. In applications such as disk drivers, dot
matrix printers, and robotics, the stepper motor is used for position control. Every stepper motor
has a permanent magnet rotor ( also called as shaft ) surrounded by a stator the most common
stator motors have four stator windings that are paired with a centre-tapped common as shown in
the figure. This type of stator motor is commonly referred to as four phase stepper motor. The
centre tap allows a change of current direction in each of two coils, when a winding is grounded,
thereby resulting in polarity change of the stator. Notice that while a conventional motor shaft runs
freely, the stepper motor shaft moves in a fixed repeatable increment which allows one to move it
to a precise position.
This repeatable fixed movement is possible as a result of basic magnetic theory where poles
of same polarity repel and opposite attract. The direction of rotation is indicated by the stator poles.
The stator poles are determined by the current sent through the wire coils A, B,C and D as shown
in Figure 8.1. As the direction of current is changed, the polarity is also changed causing the reverse
motion of the rotor. The stepper motor discussed here has a total of six leads: four leads
representing the four stator windings and two commons for the centre tapped leads. As the
sequence of power is applied to each stator winding, the rotor will rotate. There are several widely
used sequences where each has a different degree of precision. The stepping sequence of
excitations is as shown in Table 8.1.
Permanent Magnet Stepper Motor: Permanent magnet motors use a permanent magnet (PM) in
the rotor and operate on the attraction or repulsion between the rotor PM and the stator
electromagnets.
Variable Reluctance Stepper Motor: Variable reluctance (VR) motors have a plain iron rotor
and operate based on the principle that minimum reluctance occurs with minimum gap, hence the
rotor points are attracted toward the stator magnet poles.
Hybrid Synchronous Stepper Motor: Hybrid stepper motors are named because they use a
combination of permanent magnet (PM) and variable reluctance (VR) techniques to achieve
maximum power in a small package size.
Applications:
1. Industrial Machines – Stepper motors are used in automotive gauges and machine tooling
automated production equipment.
2. Security – new surveillance products for the security industry.
3. Medical – Stepper motors are used inside medical scanners, samplers, and also found
inside digital dental photography, fluid pumps, respirators and blood analysis machinery.
4. Consumer Electronics – Stepper motors in cameras for automatic digital camera focus
and zoom functions.
Interfacing Diagram:
Hardware Connections:
Connect flat cable between PL3 connector of ASK25 and PL6 connector of EPBF340 board.
Connect stepper motor at PL4 connector of ASK25. Connect 9V power supply at PL9 connector
of ASK25 before connecting the stepper motor. Press DIP switch SW9 on ASK25 to run the motor.
Expected Result:
Stepper Motor will rotate in the clockwise and anticlockwise direction
Conclusion:
Study Questions:
Additional Links:
https://nptel.ac.in/courses/112103174/16