Sahil Es
Sahil Es
EMBEDDED SYSTEMS
Subject Code: EC306
LAB FILE
Theory
MPLAB X IDE v6.20 is a powerful integrated development environment (IDE) designed for
Microchip microcontrollers and digital signal controllers (DSCs), available for Windows, macOS,
and Linux. It includes a comprehensive set of tools, such as an advanced code editor with syntax
highlighting and code completion, making coding more efficient. The IDE’s project management
features enable seamless organization of codebases, enhancing developer productivity.
Additionally, its robust debugging capabilities, including breakpoints and variable tracking, assist
in identifying and resolving issues effectively.
With broad device support, MPLAB X IDE v6.20 provides access to device-specific libraries and
configuration tools, simplifying development for Microchip hardware. The IDE’s plugin system
allows users to extend its functionality, tailoring it to specific project needs. Furthermore,
integration with version control systems like Git ensures streamlined collaboration, version
tracking, and project synchronization. As an essential tool for embedded development, MPLAB X
IDE v6.20 empowers developers to create, debug, and deploy projects with confidence and
efficiency.
1
Getting started with MPLAB IDE:
Creating a new project in MPLAB X IDE v6.20
2
3) Select the Device then click Next.
3
5) Give Project name & specify project location.
6) At last, the final project has been built successfully. Now user can start adding files &
writing codes in the given project.
4
Simulation Software: Proteus 8 Professional
5
Experiment 2
Aim: To blink LEDs in ON/OFF pattern using PIC.
Tools used: MPLAB x IDE v6.20 and Proteus 8 Professional.
Theory
Light-emitting diodes (LEDs) are semiconductor devices that emit light when a voltage is
applied across their terminals. Operating as p-n junction diodes, they facilitate electron-hole
recombination within the device, releasing energy in the form of photons. The emitted light's
colour, representing the photon's energy, is determined by the semiconductor material's
energy band gap.
The PIC microcontroller's adoption in diverse applications stems from its robust
architecture, offering features such as GPIO (General Purpose Input/Output) pins for
interfacing with external components like LEDs. By configuring GPIO pins as outputs and
controlling their states through software, developers can implement tasks like blinking LEDs
in specific patterns. This process involves writing code using development tools like MPLAB
X IDE, compiling it into machine code, and programming the microcontroller to execute the
desired functionality.
Simulation Results:
Result: The LEDs successfully blinked in an ON/OFF pattern using the PIC microcontroller. The
experiment demonstrated GPIO pin control through MPLAB X IDE and Proteus simulation.
7
Experiment 3
Aim: To blink LEDs in alternate fashion using PIC.
Tools used: MPLAB x IDE v6.20 and Proteus 8 Professional.
Theory
In this experiment, the PIC16F84A microcontroller was implemented using Proteus software to
control multiple LEDs. The LEDs were connected to the output ports of the microcontroller and
properly grounded, ensuring correct circuit operation. The program for LED blinking was written
in MPLAB X IDE v6.20, where the microcontroller’s GPIO pins were configured as outputs. The
code was compiled to generate a HEX file, which was then loaded into the microcontroller using
Proteus. Once programmed, the microcontroller executed the instructions, causing the LEDs to
blink in an alternate ON/OFF pattern, demonstrating basic microcontroller-based LED control.
Code:
Simulation Results:
9
Experiment 4
Aim: To blink LEDs in a one-by-one pattern and Sandglass pattern using PIC.
Tools used: MPLAB x IDE v6.20 and Proteus 8 Professional.
Theory
In this experiment, the PIC16F84A microcontroller was simulated using Proteus software,
where multiple LEDs were connected to its output ports and properly grounded to ensure
correct operation. The program for generating one-by-one and sandglass LED blinking
patterns was written using MPLAB X IDE v6.20. The microcontroller’s GPIO pins were
configured as outputs, and the code was compiled to generate a HEX file. This HEX file was
then loaded into the microcontroller within Proteus. Upon execution, the microcontroller
controlled the LEDs to blink in a sequential one-by-one pattern and a sandglass pattern,
demonstrating advanced LED control using embedded programming.
Simulation Results:
11
LEDs glowing in sandglass pattern.
Results: Using PIC16F84A Microcontroller and MPLAB Software, we have successfully
simulated both one-by-one and sandglass pattern blinking of LED.
12
Experiment 5
The 7-segment display comes in two configurations which are common cathode & common
anode configuration.
1. The Common Cathode (CC) – In the common cathode display, all the cathode
connections of the LED segments are joined together to logic “0” or ground. The
individual segments are illuminated by application of a “HIGH”, or logic “1” signal via
a current limiting resistor to forward bias the individual Anode terminals (a-g).
2. The Common Anode (CA) – In the common anode display, all the anode connections
of the LED segments are joined together to logic “1”. The individual segments are
illuminated by applying a ground, logic “0” or “LOW” signal via a suitable current
limiting resistor to the Cathode of the particular segment (a-g).
13
1.) Common Cathode
Binary
Digit Hexcode
0gfedcba
0 00111111 0x3F
1 00000110 0x06
2 01011011 0x5B
3 01001111 0x4F
4 01100110 0x66
5 01101101 0x6D
6 01111101 0x7D
7 00000111 0x07
8 01111111 0x7F
9 01101111 0x6B
Code:
#include <xc.h>
void main(void) {
int i;
TRISB = 0; // Set PORTB as output
while (1) {
PORTB = 0x3F; // Display 0
for (i = 0; i < 3000; i++); // Delay
PORTB = 0x06; // Display 1
for (i = 0; i < 3000; i++); // Delay
PORTB = 0x5B; // Display 2
for (i = 0; i < 3000; i++); // Delay
PORTB = 0x4F; // Display 3
for (i = 0; i < 3000; i++); // Delay
PORTB = 0x66; // Display 4
for (i = 0; i < 3000; i++); // Delay
PORTB = 0x6D; // Display 5
for (i = 0; i < 3000; i++); // Delay
PORTB = 0x7D; // Display 6
for (i = 0; i < 3000; i++); // Delay
PORTB = 0x07; // Display 7
for (i = 0; i < 3000; i++); // Delay
PORTB = 0x7F; // Display 8
for (i = 0; i < 3000; i++); // Delay
PORTB = 0x6F; // Display 9
for (i = 0; i < 3000; i++); // Delay
}
return;
}
14
Simulation Results:
15
2.) Common Anode
Binary
Digit Hexcode
1gfedcba
0 11000000 0xC0
1 11111001 0xF9
2 10100100 0xA4
3 10110000 0xB0
4 10011001 0x99
5 10010010 0x92
6 10000010 0x80
7 11111000 0xF8
8 10000000 0x80
9 10010000 0x90
Code:
#include <xc.h>
void main(void) {
int i;
TRISB = 0; // Set PORTB as output
while (1) {
PORTB = 0xC0; // Display 0
for (i = 0; i < 3000; i++); // Delay
PORTB = 0xF9; // Display 1
for (i = 0; i < 3000; i++); // Delay
PORTB = 0xA4; // Display 2
for (i = 0; i < 3000; i++); // Delay
PORTB = 0xB0; // Display 3
for (i = 0; i < 3000; i++); // Delay
PORTB = 0x99; // Display 4
for (i = 0; i < 3000; i++); // Delay
PORTB = 0x92; // Display 5
for (i = 0; i < 3000; i++); // Delay
PORTB = 0x82; // Display 6
for (i = 0; i < 3000; i++); // Delay
PORTB = 0xF8; // Display 7
for (i = 0; i < 3000; i++); // Delay
PORTB = 0x80; // Display 8
for (i = 0; i < 3000; i++); // Delay
PORTB = 0x90; // Display 9
for (i = 0; i < 3000; i++); // Delay
}
return;
}
16
Simulation Results:
Results: We have Successfully simulated and displayed the numbers from 0 to 9 on both
Common Cathode and Common Anode 7-segment Digital LED Display.
17
Experiment 6
Binary
Digit Hex code
0gfedcba
2 01011011 0x5B
3 01001111 0x4F
- 01000000 0x40
S 01101101 0x6D
P 01110011 0x73
d 01011110 0x5E
- 01000000 0x40
0 00111111 0x3F
7 00000111 0x07
Code:
#include <xc.h>
void main(void) {
int i;
TRISB = 0; // Set PORTB as output
while (1) {
PORTB = 0x5B; // Display 2
for (i = 0; i < 3000; i++); // Delay
PORTB = 0x4F; // Display 3
for (i = 0; i < 3000; i++); // Delay
PORTB = 0x40; // Display -
for (i = 0; i < 3000; i++); // Delay
PORTB = 0x6D; // Display S
for (i = 0; i < 3000; i++); // Delay
PORTB = 0x73; // Display P
for (i = 0; i < 3000; i++); // Delay
PORTB = 0x5E; // Display D
for (i = 0; i < 3000; i++); // Delay
PORTB = 0x40; // Display -
for (i = 0; i < 3000; i++); // Delay
PORTB = 0x3F; // Display 0
for (i = 0; i < 3000; i++); // Delay
PORTB = 0x07; // Display 7
for (i = 0; i < 3000; i++); // Delay
}
return;
18
Simulation Results:
Results: Using PIC16F84A Microcontroller and MPLAB Software, Roll no. has been
displayed successfully.
19
Experiment 7
Aim: Write a C program in assembly to blink LED in a 4-way traffic light controller with
a timer counter on a 7-segment display.
Tools used: MPLAB x IDE v6.15 and Proteus 8 Professional.
Theory: An LED is a two-lead semiconductor light source. It is a p-n junction diode, which
emits light when activated. When a suitable voltage is applied to the leads, electrons can
recombine with electron holes within the device, releasing energy in the form of photons.
The color of the light (corresponding to the energy of the photon) is determined by the
energy band gap of the semiconductor.
4-Way Traffic Light Controller: Several decades back, when people used to travel on foot,
there were, of course, no proper roads, and as vehicles got invented, the roads also got
constructed. And, as technology increases, the construction of roads also gets more
innovative. Today, there is not just a one or two-way route at one place, but also a 4-way
road with 4-way traffic lights. As time passes, the population of the world is increasing, and
not just the population, but also the automotive industry is growing. Thus, we need proper
traffic management without that there would be chaos. Therefore, traffic signal lights are
very Important to regulate vehicles and traffic on roads.
For our experiment, we would use a counter and blink LED along a path for a certain period
of time.
20
Code:
#include <xc.h> //Timer Counter Code
void main(void) {
int i;
TRISB = 0;
while (1) {
//0
PORTB = 0x3F;
for (i = 0; i < 3000; i++);
//1
PORTB = 0x06;
for (i = 0; i < 3000; i++);
//2
PORTB = 0x5B;
for (i = 0; i < 3000; i++);
//3
PORTB = 0x4F;
for (i = 0; i < 3000; i++);
//4
PORTB = 0x66;
for (i = 0; i < 3000; i++);
//5
PORTB = 0x6D;
for (i = 0; i < 3000; i++);
//6
PORTB = 0x7d;
for (i = 0; i < 3000; i++);
//7
PORTB = 0x07;
for (i = 0; i < 3000; i++);
//8
PORTB = 0x7f;
for (i = 0; i < 3000; i++);
//9
PORTB = 0x6f;
for (i = 0; i < 3000; i++);
}
return;
}
21
Simulation Results:
Results: Using PIC16F84A Microcontroller and MPLAB Software, a 4-way traffic light
controller with LEDs & a timer counter on a 7 Segment display has been designed
successfully.
22
Experiment 8
The stepper motor working principle is Electro-Magnetism. It includes a rotor which is made
with a permanent magnet whereas a stator is with electromagnets. Once the supply is
provided to the winding of the stator then the magnetic field will be developed within the
stator. Now rotor in the motor will start to move with the rotating magnetic field of the
stator. So, this is the fundamental working principle of this motor.
In this motor, there is a soft iron that is enclosed through the electromagnetic stators. The
poles of the stator as well as the rotor don’t depend on the kind of stepper. Once the stators
of this motor are energized then the rotor will rotate to line up itself with the stator otherwise
turns to have the least gap through the stator. In this way, the stators are activated in a
series to revolve the stepper motor.
23
Code:
#include <xc.h>
void main(void) {
int i;
TRISB = 0;
while (1) {
//Clockwise
PORTB = 0x99;
for (i = 0; i < 1000; i++);
PORTB = 0x0C;
for (i = 0; i < 1000; i++);
PORTB = 0x06;
for (i = 0; i < 1000; i++);
PORTB = 0x03;
for (i = 0; i < 1000; i++);
}
return;
}
#include <xc.h>
void main(void) {
int i;
TRISB=0;
while(1){
//Counter-Clockwise
PORTB=0x03;
for(i=0;i<1000;i++);
PORTB=0x06;
for(i=0;i<1000;i++);
PORTB=0x0C;
for(i=0;i<1000;i++);
PORTB=0x99;
for(i=0;i<1000;i++);
}
return;
}
24
Simulation Results:
Results: Using PIC16F84A Microcontroller and MPLAB Software, the stepper motor has
been run in both, clockwise and anticlockwise directions successfully.
25