Full Lab Manuals Updated On 11 July 2024
Full Lab Manuals Updated On 11 July 2024
Contents
MICROCONTROLLER - 1
Lab Manuals
Preface:
This manual has been developed for the introductory courses on microcontrollers taught by myself at the
Akademi Laut Malaysia (ALAM).It introduces students to the field of microcontrollers – what they are, how they
work, how they interface with their I/O components, and what considerations the programmer has to observe
in hardware-based and embedded programming. This text is intended to teach one particular controller
architecture which is PIC16F84A,
We concentrate, however, on small 8-bit controllers and their most basic features, since they already offer
enough variety to achieve our goals.
Since one of our courses is a lab and uses the PIC16F84A, we tend to use this microcontroller
in our examples.
Please help me further improve this text by notifying me any errors. If you have any suggestions or
wishes like better and/or more thorough explanations, proposals for additional topics, feel free to email me at
Ramesh_amathalai@yahoo.com
MICROCONTROLLER - 2
Lab Manuals
Introduction These programs are the backbone of the microprocessor and microcontroller based
systems; since using CCS C we can build the software of the project using C or Assembly
language, and then we can simulate the project virtually using PROTEUS, finally we can
download the program on the microcontroller and see the results practically using PIC Kit 2.
So this experiment includes all the knowledge the student will need to get started to these
programs.
MICROCONTROLLER - 3
Lab Manuals
1. C Compiler Program
CCS C?
Benefits of a C Compiler
CCS provides a complete integrated tool suite for developing and debugging embedded applications running on Microchip PIC®
MCUs and dsPIC® DSCs. The heart of this development tools suite is the CCS intelligent code optimizing Microchip PIC® C
compiler which frees developers to concentrate on design functionality instead of having to become an MCU architecture
expert.
• Maximize code reuse by easily porting from one MCU to another. Devices Supported
• Minimize lines of new code with CCS provided peripheral drivers, built-in functions and standard C
operators
• Built-in functions are specific to PIC® MCU registers, allowing access to hardware features directly from C
• Project manager
• C-Aware text editor
• Compilation control to completely or partially build projects
• Utilities for file comparison, numeric conversion, disassembly, parametric device selection and more
• C-Source code level in-circuit debugger
• Output file viewers for list files, symbol maps, call trees, etc.
• Documentation creation tools
MICROCONTROLLER - 4
Lab Manuals
The CCS Microchip PIC® C Compiler has complementary development tools that work seamlessly with the compiler. Program,
debug, and data stream from one environment that may be used for development and production.
A. PROTEUS Program
What is PROTEUS?
Proteus contains everything you need to develop, test and virtually prototype your embedded system designs
based around the Microchip Technologies™ PIC16 series of microcontrollers. The unique nature of schematic
based microcontroller simulation with Proteus facilitates rapid, flexible and parallel development of both the
system hardware and the system firmware. This design synergy allows engineers to evolve their projects more
quickly, empowering them with the flexibility to make hardware or firmware changes at will and reducing the
time to market.
Proteus VSM models will fundamentally work with the exact same HEX file as you would program the physical
device with, binary files (i.e. Intel or Motorola Hex files) produced by any assembler or compiler.
1. From start menu chose the PROTEUS, and then chose ISIS(blue).
2. To get a part click on Devices ( P ).
3. Write the name of the PIC16F84A.
4. To get LED write led then chose green led.
5. To get a resistor write 1k and chose the first part.
MICROCONTROLLER - 5
Lab Manuals
The PICkit 2 — introduced in May 2005[3] — replaced the PICkit 1. The most
notable difference between the two is that the PICkit 2 has a separate
programmer/debugger unit which plugs into the board carrying the chip to be
programmed, whereas the PICkit 1 was a single unit. This makes it possible to
use the programmer with a custom circuit board via an In Circuit Serial
Programming (ICSP) header. This feature is not intended[3] for so-called
"production" programming, however.
The PICkit 2 uses an internal PIC18F2550 with FullSpeed USB. The latest
PICkit 2 firmware allows the user to program and debug
most of the 8 and 16 bit PICmicro and dsPIC members
of the Microchip product line.
The Microchip version of PICkit 2 has a standard 128K byte memory. 256K byte memory can be achieved by
modifying the hardware or from third party.
Additionally, a 500 kHz three-channel logic analyser and a UART tool are built into the PICKit 2. These features
are missing from the PICkit 3.
MICROCONTROLLER - 6
Lab Manuals
Since release of V2.61, PICkit 2 PC software now support maximum 4M bytes of memory for programmer-to-go
feature. This modification makes the PICKit 2 support 8x more memory than the PICKit 3. This enhancement
has been contributed by Au Group Electronics and the PICkit 2 firmware is also reported to be submitted to
Microchip PICkit 2 team in the middle of March 2009. Hopefully this enhancement will be integrated into future
firmware releases too.
MICROCONTROLLER - 7
Lab Manuals
MICROCONTROLLER - 8
Lab Manuals
PIC16F84 microcontroller PIC16F84 belongs to a class of 8-bit microcontrollers of RISC architecture. Its
general structure is shown on the following map representing basic blocks. PIC16F84 has a total of 18 pins. It is
most frequently found in a DIP18 type of case but can also be found in SMD case which is smaller from a DIP.
DIP is an abbreviation for Dual In Package. SMD is an abbreviation for Surface Mount Devices suggesting that
holes for pins to go through when mounting aren't necessary in soldering this type of a component.
MICROCONTROLLER - 9
Lab Manuals
Procedure
Ramesh Babu
In this figure, first thing to note is that there is a crystal of 20MHz used with PIC16F84A. You can use any crystal from
0 to 20MHz with PIC16F84A.
MCLR master reset pin is pulled high to keep PIC16F84A out of reset. RA0 pin is being light up permanently in the
code.
MICROCONTROLLER - 10
Lab Manuals
Code :
With proper
definitions
MICROCONTROLLER - 11
Lab Manuals
Objectives : 1. To know how to include some looping structure in C using the MCU PIC16F84A.
2. To know how to simulate these functions using PROTEUS program.
3. To know how to program the microcontroller PIC16F84A and then simulate
these Logic Functions using hardware..
Theory : This provides the code to make an LED blink using PIC16F84A microcontroller. This code is
written in C language using CSC C Compiler. This code is intended to be the first step in
learning how to use PIC16F84A microcontroller in your projects.
Procedure
Ramesh Babu
2. Write C program that send High to RA0 port and Low to RA0 in Port A continuously.
MICROCONTROLLER - 12
Lab Manuals
In this figure, first thing to note is that there is a crystal of 20MHz used with PIC16F84A. You can use any crystal from
0 to 20MHz with PIC16F84A.
MCLR master reset pin is pulled high to keep PIC16F84A out of reset. RA0 pin is being light up permanently in the
code.
Whenever you are writing code for PIC microcontrollers, then you have to include " #include <16F84A.h>" file in the
code. After including " #include <16F84A.h>" file, configuration bits are being set in the code shown above. To
understand the details of how these configuration bits are being programmed please clarify with your instructor.
After the configuration bits, LED pin is being defined as the RA0 pin. You can replace RA0 with any other pin name if
you want (e-g RB0 etc). After LED pin definition, CPU frequency is being defined. You have to define “ #use
delay(clock=4000000) “ macro, if you want to use built in delay functions like delay_us() and delay_ms().
Here CPU frequency is defined to be 20MHz, which is the crystal oscillator frequency attached with PIC16F84A in
the circuit.
In the main function, firstly RA0 pin direction is set to be an output pin using PortA = 0; statement. we can set the
direction of any pin i-e if it is an input or output. Then LED pin is made low using output_low(Pin_A0) and
output_high(Pin_A0) statement.
LED pin is being toggled in the while loop after every half second. In this way you can easily make LED blink using
PIC16F84A microcontroller.
MICROCONTROLLER - 13
Lab Manuals
MICROCONTROLLER - 14
Lab Manuals
Objectives : 1. To know how to include some looping structure in C using the MCU PIC16F84A.
2. To know how to simulate these functions using PROTEUS program.
3. To know how to program the microcontroller PIC16F84A and then simulate
these Logic Functions using hardware..
Theory : This provides the code to make an LED blink using PIC16F84A microcontroller. This code is
written in C language using CSC C Compiler. This code is intended to show on how to
connect at least 2 LEDs and blink continuously & Simultaneously
MICROCONTROLLER - 15
Lab Manuals
MICROCONTROLLER - 16
Lab Manuals
Objectives : 1. To know how to include some looping structure in C using the MCU PIC16F84A.
2. To know how to simulate these functions using PROTEUS program.
3. To know how to program the microcontroller PIC16F84A and then simulate
these Logic Functions using hardware..
Theory : This provides the code to make an LED blink using PIC16F84A microcontroller alternatively.
MICROCONTROLLER - 17
Lab Manuals
Objectives : 1. To know how to include some looping structure in C using the MCU PIC16F84A.
2. To know how to simulate these functions using PROTEUS program.
3. To know how to program the microcontroller PIC16F84A and then simulate
these Logic Functions using hardware..
Theory : This provides the code to make an LED blink using PIC16F84A microcontroller for only 5
times.
MICROCONTROLLER - 18
Lab Manuals
MICROCONTROLLER - 19
Lab Manuals
Tools : PIC16F84 Microcontroller, Proteus, CSC C software PicKit 2 programmer, Switch, LED,
Resistor, capacitors, Crystal
Theory : This provides the code to make an LED on using PIC16F84A microcontroller after a Switch is
pressed. This code is written in C language using CSC C Compiler. This code is to show how
input and output pins are used in PIC16F84A microcontroller.
MICROCONTROLLER - 20
Lab Manuals
Procedure
Ramesh Babu
2. Write C program that send High to RB0 if the RA0 is On (Switch is pressed )
In this figure, first thing to note is that there is a crystal of 20MHz used with PIC16F84A. You can use any crystal from
0 to 20MHz with PIC16F84A.
MCLR master reset pin is pulled high to keep PIC16F84A out of reset. RA0 pin is being light up permanently in the
code.
MICROCONTROLLER - 21
Lab Manuals
PIC16F84A is running on external crystal of 20MHz. RA0 pin is being used as the input pin. When the push button is
in the pushed state then, RA0 pin is high, otherwise RA0 pin is low. Whenever RA0 pin is high, then RB0 pin
(Attached with the LED) is also made high just to indicate correct reading of RA0 pin status in the micro-controller.
In the main function, firstly RA0 pin is made an input and RB0 is made an output. Using Set_Tris_X, we can set the
direction of any pin i-e if it is an input or output. So, Set_Tris_A = 1; makes RA0 pin an input pin. And Set_Tris_B = 0;
makes RB0 pin an output pin. Also, using the statement output_low(pin_b0); RB0 pin is made low.
In the while(1) loop, status of RA0 pin is constantly being checked, if it becomes high then RB0 is also made high. If
RA0 is low, then RB0 is also made low as well.
MICROCONTROLLER - 22
Lab Manuals
Codes :
MICROCONTROLLER - 23
Lab Manuals
Tools : PIC16F84 Microcontroller, Proteus, CSC C software PicKit 2 programmer, Switch, LED,
Resistor, capacitors, Crystal
Theory : This provides the code to make an LED blink 3 times on using PIC16F84A microcontroller
after a Switch is pressed. This code is written in C language using CSC C Compiler. This code
is to show how input and output pins are used in PIC16F84A microcontroller. Using control
loop.
MICROCONTROLLER - 24
Lab Manuals
MICROCONTROLLER - 25
Lab Manuals
MICROCONTROLLER - 26
Lab Manuals
Tools : PIC16F84 Microcontroller, Proteus, CSC C software PicKit 2 programmer, Switch, LED,
Resistor, capacitors, Crystal
Theory : This provides the code to make an LED blink 3 times on using PIC16F84A microcontroller
after a Switch is pressed. This code is written in C language using CSC C Compiler. This code
is to show how input and output pins are used in PIC16F84A microcontroller. Using control
loop.
MICROCONTROLLER - 27
Lab Manuals
Procedure
Ramesh Babu
2. Write C program that send High to RB0 3 times if the RA0 is On (Switch is pressed )
In this figure, first thing to note is that there is a crystal of 20MHz used with PIC16F84A. You can use any crystal from
0 to 20MHz with PIC16F84A.
MCLR master reset pin is pulled high to keep PIC16F84A out of reset. RA0 pin is being light up permanently in the
code.
MICROCONTROLLER - 28
Lab Manuals
Codes :
MICROCONTROLLER - 29
Lab Manuals
Tools : PIC16F84 Microcontroller, Proteus, CSC C software PicKit 2 programmer, Switch, LED,
Resistor, capacitors, Crystal
Theory : This provides the code to make an LED ON after a switched is pressed using PIC16F84A
microcontroller. This code is written in C language using CSC C Compiler. This code is to
show how input and output pins are used in PIC16F84A microcontroller.
Procedure
MICROCONTROLLER - 30
Lab Manuals
Ramesh Babu
MICROCONTROLLER - 31
Lab Manuals
Codes :
MICROCONTROLLER - 32
Lab Manuals
Tools : PIC16F84 Microcontroller, Proteus, CSC C software PicKit 2 programmer, 8 LEDs, Resistor,
capacitors, Crystal
Theory : This provides the code to make many LEDs blink simultaneously using PIC16F84A
microcontroller. This code is written in C language using CSC C Compiler. This code is to
show how output pins are used in PIC16F84A microcontroller.
MICROCONTROLLER - 33
Lab Manuals
Procedure
Ramesh Babu
MICROCONTROLLER - 34
Lab Manuals
Codes :
MICROCONTROLLER - 35
Lab Manuals
Tools : PIC16F84 Microcontroller, Proteus, CSC C software PicKit 2 programmer, 8 LEDs, Resistor,
capacitors, Crystal
Theory : This provides the code to make many LEDs blink simultaneously alternate toggling using
PIC16F84A microcontroller. This code is written in C language using CSC C Compiler. This
code is to show how output pins are used in PIC16F84A microcontroller.
MICROCONTROLLER - 36
Lab Manuals
Procedure
Ramesh Babu
2. Write C program that send High all the pins in Port B, alternating toggling the pins in a
row.
MICROCONTROLLER - 37
Lab Manuals
Codes :
Lab 9
MICROCONTROLLER - 38
Lab Manuals
Tools : PIC16F84 Microcontroller, Proteus, CSC C software PicKit 2 programmer, 2 LEDs, Resistor,
capacitors, Crystal
Theory : This provides the code to make 2 LEDs to toggled , lighting up ether one at a time using
PIC16F84A microcontroller. This code is written in C language using CSC C Compiler. This
code is to show how output pins are used in PIC16F84A microcontroller.
MICROCONTROLLER - 39
Lab Manuals
Procedure
Ramesh Babu
2. Write C program that send High to either RB4 or RB5 pins in Port B, alternating toggling
between these two pins in a row.
Codes :
MICROCONTROLLER - 40
Lab Manuals
MICROCONTROLLER - 41
Lab Manuals
Tools : 2 sets of : PIC16F84 Microcontroller, Resistor, capacitors, Crystal , 1 push button , Proteus,
CSC C software PicKit 2 programmer
Procedure
MICROCONTROLLER - 42
Lab Manuals
Ramesh Babu
2. MCU 1 : Write a C program that send a signal high to RB0 & RB1if the input A0 = 1.
3. MCU 2 : Write a C program that send a signal high to RB0 if the input A0 = 1.
MICROCONTROLLER - 43
Lab Manuals
Tools : PIC16F84 Microcontroller, Proteus, CSC C software PicKit 2 programmer, 1 - 7 Segment LED,
Resistor, capacitors, Crystal
Theory : Generate a Delay with a certain value using the Delay Loops Technique; after that we will
use this delay to make some applications like Flasher and Counter.
MICROCONTROLLER - 44
Lab Manuals
Procedure
Ramesh Babu
MICROCONTROLLER - 45
Lab Manuals
Codes :
MICROCONTROLLER - 46
Lab Manuals
Basically, an LED display is nothing more than several LEDs molded in the same plastic
case. There are many types of displays and some of them are composed of several dozens
built-in diodes which can display different symbols. Nevertheless, the most commonly used
display is a 7-segment display. It is composed of 8 LEDs. Seven segments of a digit are
arranged as a rectangle to display symbols, whereas the additional segment is used to
display a decimal point. In order to simplify connection, anodes or cathodes of all diodes
are connected to one single pin so that there are common anode displays and common
cathode displays, respectively. Segments are marked with letters from a to g, plus dp, as
shown in figure below. When connecting an LED display, each diode is treated separately,
which means that each one must have its own current limiting resistor.
Here are a few things that you should pay attention to when buying LED displays:
• As mentioned above, depending on whether anodes or cathodes are connected to the common pin, there
are common anode displays and common cathode displays. There is no difference between them at all in
their appearance so you are advised to double check which one is to be used prior to installing it.
• Maximum current that each microcontroller pin can receive or give is limited. Therefore, if several
displays are connected to the microcontroller then so called Low current LEDs limited to only 2mA
should be used.
• Display segments are usually marked with letters from a to g, but there is no fast rule indicating display
pins they are connected to. For this reason, it is very important to check connection prior to start writing a
program or designing a device.
LED displays connected to the microcontroller usually occupy a large number of valuable I/O pins, which can be
troublesome especially when it is necessary to display multi digit numbers. It is even more complicated if, for
example, it is necessary to display two 6-digit numbers. A simple calculation shows that 96 output pins are
needed in this case. The solution to this issue is called multiplexing.
Here is how an optical illusion based on the same operating principle as a film camera is made. Only one digit is
active at a time, but they change their on/off conditions so quickly creting the impression that all digits of a
number are simultaneously active.
MICROCONTROLLER - 47
Lab Manuals
If the microcontroller port is connected to a display so as that bit 0 activates segment ‘a’, bit 1 activates segment
‘b’, bit 2 segment ‘c’ etc., then table below shows appropriate binary mask for each digit.
MICROCONTROLLER - 48
Lab Manuals
In addition to digits (0-9), there are some letters of alphabet - A, C, E, J, F, U, H, L, b, c, d, o, r, t- that can also
be displayed by masking.
In case that common anode displays are used, all ones contained in the table above should be replaced with zeros
and vice versa. Additionally, PNP transistors should be used as drivers.
MICROCONTROLLER - 49
Lab Manuals
An LCD display is specifically manufactured for the use with microcontrollers, which means that it cannot be
activated by standard IC circuits. It is used to display different messages on a miniature liquid crystal display.
The LCD display described here is for its low price and great capabilities most frequently used in practice.
An LCD screen is an electronic display module that uses liquid crystal to produce a visible image. The 16×2
LCD display is a very basic module commonly used in DIYs and circuits. The 16×2 translates a display of 16
characters per line in 2 such lines. In this LCD, each character is displayed in a 5×7 pixel matrix.
MICROCONTROLLER - 50
Lab Manuals
MICROCONTROLLER - 51
Lab Manuals
LCD Screen
If there are no characters displayed or if they are dimmed when the display is switched on, the first thing that should be
done is to check the potentiometer for contrast adjustment. Is it properly adjusted? The same applies if the operating
mode of display has been changed (write in one or two lines).
MICROCONTROLLER - 52
Lab Manuals
Tools : PIC16F84 Microcontroller, Proteus, CSC C software PicKit 2 programmer, 1 LCD Display,
Resistor, capacitors, Crystal
Procedure
Ramesh Babu
MICROCONTROLLER - 53
Lab Manuals
Codes :
MICROCONTROLLER - 54
Lab Manuals
Tools : PIC16F84 Microcontroller, Proteus, CSC C software PicKit 2 programmer, 1 LCD Display,
Resistor, capacitors, Crystal
Procedure
Ramesh Babu
MICROCONTROLLER - 55
Lab Manuals
• Build the circuit using the programmed PIC 16F84A and then observe its operation.
• Demonstrate the circuits operation to the instructor.
Codes :
MICROCONTROLLER - 56
Lab Manuals
MICROCONTROLLER - 57
Lab Manuals
LAB17 : Buzzer
Tools : PIC16F84 Microcontroller, Proteus, CSC C software PicKit 2 programmer, 1 buzzer, switch,
Resistor, capacitors, Crystal
MICROCONTROLLER - 58
Lab Manuals
Procedure
Ramesh Babu
MICROCONTROLLER - 59
Lab Manuals
Codes :
MICROCONTROLLER - 60
Lab Manuals
Main References:
http://microchip.com
http://o.mneina.googlepages.com/what_is_microcontroller.htm
http://en.wikibooks.org/wiki/Embedded_Systems/PIC_Microcontroller
http://en.wikipedia.org/wiki/PIC_microcontroller
MICROCONTROLLER - 61