Professional Documents
Culture Documents
PIC Lab Manual PDF
PIC Lab Manual PDF
PIC Lab
Manual
2010/2011
1
Include CD-ROM
Table Of Contents
Experiment #1
Experiment #2
Introduction to PIC16F84A
Experiment #3
Experiment #4
12
Experiment #5
15
Experiment #6
18
Experiment #7
22
Experiment #8
26
Experiment #9
30
Experiment #10
33
Experiment #11
39
Experiment #12
44
Lab 1
Introduction to Software Tools
MPLAB, PROTEUS, and QL-2006 programmer
Objectives
1. To be familiar with some software tools like MPLAB, PROTEUS, and ICPROG.
2. To know how to make a project using MPLAB and then get the hex file of
the software program of the project.
3. How to simulate the hex file using PROTEUS.
Introduction
These programs are the backbone of the microprocessor and microcontroller based
systems; since using MPLAB 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 ICPROG.
So this experiment includes all the knowledge the student will need to get started to these
programs.
1. MPLAB Program
What is MPLAB?
MPLAB is a software program that runs on your PC to provide a development
environment for your embedded system design.
In other words it is a Windows program package that makes writing and developing
a program easier. It could best be described as developing environment for a
standard program language that is intended for programming microcontrollers.
Get started to MPLAB
1.
2.
3.
4.
5.
6.
2. 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.
How to setup PROTEUS?
1. Start-up the Microsoft Windows.
2. Place the ECOM 4315 CD into CD ROM drive.
3. Double click on the software tools folder and then choose Proteus Simulator after
that double click Proteus 7.1 folder and run the setup.
4. Press next until you reach the window which ask for the key.
5. From browse for key; browse until you reach the same folder where the setup
exists, and then open the second folder and chose the MAXIM_LICENCE folder.
6. Then click on the top icon which is MAXIM and then press install.
7. Then choose yes and then close the window, after that browse and install the
program.
8. After that run the patch which exist in the same folder where the
MAXIM_LICENCE exists.
9. Then browse for c:\Program files\Labcenter electronics \Proteus.
10. Finally chose next, and then finish.
Get started to PROTEUS
1.
2.
3.
4.
5.
From start menu chose the PROTEUS, and then chose ISIS(blue).
To get a part click on Devices ( P ).
Write the name of the PIC16F84A.
To get LED write led then chose green led.
To get a resistor write 1k and chose the first part.
3. QL-2006 programmer
QL-2006 programmer is the high-speed programmer designed specially for
development and production programming of PIC single chip
microcomputer (SCM) by Shenzhen Qianlongsheng Electronic Technology
Co., Ltd. The product is featured with small volume, low power
consumption, high reliability as well as easy and convenient operation.
QL-2006 is applicable for almost all PIC10/12/16/18 series SCMs except
16C5X. It also supports memories in 24XX series and 93XX series.
Hardware Installation
There is no special requirement for installation of this programmer. Connect
programmer to PC through serial port cable or USB cable and power up,
then the programmer works. (This programmer supports direct USB power
supply. If USB cable is connected, you may not connect external power.
However, if current through USB interface is very low less than 200MA
and insufficient to drive programmer, connection to external power is
required to enable the programmer to work regularly.)
Software Installation
Find file QL-PROGvXXen.EXE under root directory of CD, double click
this file to access installation interface of application software, and operate
according to prompts to finish the installation. Its shortcut will appear on
desktop automatically after installation.
Running of Software
After proper installation, shortcut of this software will appear on desktop.
We can double click it to run the software.
Lab 2
Introduction to PIC16F84A
Objective
To get familiar with programming and using PIC16F84 microcontroller.
Tools
PIC16F84 Microcontroller, IC programmer, MPLAB software.
Theory
A microcontroller (or MCU) is a computer-on-a-chip. It is a type of
microprocessor emphasizing self-sufficiency and cost-effectiveness, in contrast
to a general-purpose microprocessor (the kind used in a PC).
A microcontroller is a single integrated circuit, commonly with the following
features:
central processing unit - ranging from small and simple 4-bit
processors to sophisticated 32- or 64-bit processors
input/output interfaces such as serial ports (UARTs)
Other serial communications interfaces like IC, Serial Peripheral
Interface and Controller Area Network for system interconnect
Peripherals such as timers and watchdog
RAM for data storage
ROM, EPROM, EEPROM or Flash memory for program storage
clock generator - often an oscillator for a quartz timing crystal, resonator
or RC circuit
many include analog-to-digital converters
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.
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.
Procedure
Part 1
Connect the circuit shown in the figure
Write an assembly language program that send 0x8a to port B
Load the program to the microcontroller
Part 2
Part 3
Present your results in a lab report including a copy of the source codes.
Lab 3
Some Logic Functions Design
Objectives
1. To know how to design some logic functions like Addition, Subtraction, and
Multiplication using the microcontroller 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.
Tools
PIC16F84A microcontroller.
MPLAB software.
PROTEUS software.
QL2006 USB Programmer.
Theory
In this experiment we will implement the Addition and Subtraction Functions
Using PIC16F84A microcontroller.
1. We use the method of masking to separate the two numbers, since the first
number is in the LSB of PORTB and the second number is in the MSB, we
separate the first number using the instruction ANDLW 0X0F, and the second
number using the instruction ANDLW 0XF0.
2. After that before we add the two numbers, the first number is ready for
addition but the second number needs to be swapped, so we use the instruction
SWAPF F,d to swap it (swapping means F(0:3) = F(4:7), F(4:7) = F(0:3)).
3. After that we add the two numbers using the instruction ADDWF F,d and then
we display the result on PORTA.
The subtraction function is the same as the addition function except you will
subtract the two numbers instead of adding them. To avoid negative answer the
first number must be greater than the second .
Procedure
Part 1: Addition Function
10
Part 3
Present your results in a lab report including a copy of the source codes.
11
Lab 4
Delay Loops Applications
Flasher & Counter
Objectives
4. To know how to make a delay loop with a certain value.
5. To realize how PIC16F84A microcontroller deals with timing issues.
6. To get familiar with interfacing 7-Seg display to PIC16F84A and make a
counter.
7. To get familiar with interfacing LED display to PIC16F84A and make a
flasher.
Tools
PIC16F84A microcontroller, MPLAB software, PROTEUS software, USB
Programmer.
Theory
There is two methods to generate Delay is PIC16F84A Microcontroller:
The first method is using TMR0, which is a built in timer in PIC16F84A
microcontroller.
The second method is using Delay Loops Technique.
In this experiment we will know how to 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.
The Ordinary Instructions need 1 cycle to be executed, but the cycles which cause
the program counter (PC) to be changed need 2 cycles.
Examples
Movlw .100 needs 1 cycle.
Movwf portb needs 1 cycle.
Call delay needs 2 cycles.
Goto loop
needs 2 cycles. And so on.
12
Delay Subroutine
Consider the following delay subroutine:
DELAY
MOVLW .255
MOVWF 0CH
LOOP1
MOVLW .255
MOVWF 0DH
LOOP0
(1)NOP
.
.
(n)NOP
DECFSZ 0DH,F
GOTO LOOP0
DECFSZ 0CH,F
GOTO LOOP1
RETURN
END
How to calculate the value of the Delay for this subroutine?
1) Look for the inner Loop
13(# of NOPS) + 1(DECFSZ 0DH,F) + 2(GOTO LOOP0) = 16
2) Intermediate Loop
1(MOVLW .255) + 1(MOVWF 0DH) + 1(DECFSZ 0CH,F) + 2(GOTO
LOOP1) = 5
3) Outer Loop
1(MOVLW .255) + 1(MOVWF 0CH) + 2(RETURN) = 4
So the value of the delay is
(16*255*255 + 5*255 + 4)*(4/Osc Freq) = 1.04sec (if Osc Freq = 4MHz).
Note that this value of the delay is not precise 100%, since we ignore that the
instruction DECFSZ needs 2 cycles in the last turn, and hence this method
(Delay Loops Method) is not effective for precise and large values of Delay.
13
Procedure
Part 1: Flasher
Write an assembly program to make a Flasher on RB0 (Hint: Use the Delay
Subroutine).
Simulate the program using the circuit shown in figure via Proteus software.
Verify it operates properly when simulated
Program a PIC 16F84A using the QL2006 programmer.
Build the circuit using the programmed PIC 16F84A and then observe its
operation. Demonstrate the circuits operation to the instructor.
Part 2: Counter
Part 3
Present your results in a lab report including a copy of the source codes.
14
Lab 5
Interrupt Application
Controlling flashing speed of a flasher
Objectives
8. To know what is the interrupt, and how many sources of interrupt does the
PIC16f84A microcontroller have.
9. To know how to make interrupt on PORTB through (RB4 RB7).
10. To get familiar with interfacing LED display to PIC16F84A and make a
flasher.
11. To know how to change the flashing speed of this flasher using interrupts
method.
Tools
PIC16F84A microcontroller, MPLAB software, PROTEUS software, USB
Programmer.
Theory
Interrupts allow a microcontroller to respond to some events at the moment they
occur, regardless of what the microcontroller is doing at the time. This provides a
connection between a microcontroller and the external environment. Generally,
each interrupt changes the program flow, interrupts it and after executing an
interrupt service routine continues on from that same interrupt point. The
following figure illustrates this
15
In this experiment we will deal only with one of these sources, which is the interrupt
during alteration on (RB4 Rb7).
16
Procedure
Write an assembly program to make a Flasher on RA0; then use the interrupt
method to control the flashing speed of this flasher.
Hint// Use the interrupt on change (RB4 RB7)
Simulate the program using the circuit shown in figure via Proteus software.
Verify it operates properly when simulated
Program a PIC 16F84A using the QL2006 programmer.
Build the circuit using the programmed PIC 16F84A and then observe its
operation. Demonstrate the circuits operation to the instructor.
Part 2
Present your results in a lab report including a copy of the source codes.
17
Lab 6
TMR0 Application
Counter Using TMR0
Objectives
12. To know what is the free run timer TMR0; and the function of this timer.
13. To know how to make a counter using TMR0.
Tools
PIC16F84A microcontroller, MPLAB software, PROTEUS software, USB
Programmer.
Theory
Timers are usually most complicated parts of a microcontroller, so it is
necessary to set aside more time for their explaining. With their application it is
possible to create relations between a real dimension such as "time" and a variable
which represents status of a timer within a microcontroller. Physically, timer is a
register whose value is continually increasing to 255, and then it starts all over
again: 0, 1, 2, 3, 4...255....0, 1, 2, 3......etc. The following figure illustrates this.
18
If trigger TMR0 was enabled with impulses from a RA4/T0CKI pin, this bit would
determine whether it would be on the rising or falling edge of a signal.
1=falling edge
0=rising edge
bit 5 T0CS (TMR0 Clock Source Select bit)
This pin enables a free-run timer to increment its value either from an internal
oscillator, i.e. every 1/4 of oscillator clock, or via external impulses on RA4/T0CKI
pin.
1=external impulses
0=1/4 internal clock
bit 6 INTEDG (Interrupt Edge Select bit)
If occurrence of interrupts was enabled, this bit would determine at what edge
interrupt on RB0/INT pin would occur.
1= rising edge
0= falling edge
bit 7 RBPU (PORTB Pull-up Enable bit)
This bit turns internal pull-up resistors on port B on or off.
1='pull-up' resistors turned on
0='pull-up' resistors turned off
Procedure
Part1: TMR0
20
Part 2
Present your results in a lab report including a copy of the source codes.
21
Lab 7
EEPROM Memory Application
Objectives
14. To know what is the EEPROM Memory in Microcontroller PIC16F84A.
15. To know how to write to and how to read from this memory.
16. To know the advantages of this memory over other memories.
Tools
PIC16F84A microcontroller, MPLAB software, PROTEUS software, USB
Programmer.
Theory
PIC16F84 has 64 bytes of EEPROM memory locations on addresses from 00h to
63h those can be written to or read from. The most important characteristic of this
memory is that it does not lose its contents during power supply turned off. That
practically means that what was written to it will be remaining even if
microcontroller is turned off. Data can be retained in EEPROM without power
supply for up to 40 years (as manufacturer of PIC16F84 microcontroller states),
and
up
to
10000
cycles
of
writing
can
be
executed.
In practice, EEPROM memory is used for storing important data or some process
parameters.
One such parameter is a given temperature, assigned when setting up a
temperature regulator to some process. If that data wasn't retained, it would be
necessary to adjust a given temperature after each loss of supply. Since this is
very impractical (and even dangerous), manufacturers of microcontrollers have
began
installing
one
smaller
type
of
EEPROM
memory.
EEPROM memory is placed in a special memory space and can be accessed
through special registers. These registers are:
EEDATA at address 08h, which holds read data or that to be written.
EEADR at address 09h, which contains an address of EEPROM location
being accessed.
EECON1 at address 88h, which contains control bits.
EECON2 at address 89h. This register does not exist
physically and serves to protect EEPROM from accidental
writing.
EECON1 register at address 88h is a control register with five
implemented bits. Bits 5, 6 and 7 are not used, and by reading
always are zero. Interpretation of EECON1 register bits follows.
22
EECON1 Register
Procedure
Part1:
Write an assembly program to fill all the EEPROM Memory locations With
7.
Part2:
Write an assembly program to take the data existed on PORT A and display it
on PORT B; first, the data must be taken from PORT A and stored in the
EEPROM address location 0X10, and then be taken again from EEPROM
and be displayed on PORT B.
You should use the EEPROM_Writing Macro from the previous part for
writing operation, and also build a nother macro EEPROM_Reading for
reading operation.
Simulate your program using the software PIC Simulator IDE.
Simulate the program using the circuit shown in figure via Proteus software.
Verify it operates properly when simulated
Program a PIC 16F84A using the QL2006 programmer.
Build the circuit using the programmed PIC 16F84A and then observe its
operation. Demonstrate the circuits operation to the instructor
24
Part 3
Present your results in a lab report including a copy of the source codes.
25
Lab 8
Introduction to MikroC Language
Objectives
17. To know what is the MikroC Language.
18. To know how to write your first program in MikroC Language.
19. To know the advantages and disadvantages of this language over Assembly
Language.
Tools
PIC16F84A microcontroller, MikroC software, PROTEUS software, USB
Programmer.
Theory
MikroC is a powerful, feature rich development tool for PICmicros. It is designed
to provide the programmer with the easiest possible solution for developing
applications for embedded systems, without compromising performance or
control.
PIC and C fit together well: PIC is the most popular 8-bit chip in the world, used
in a wide variety of applications, and C, prized for its efficiency, is the natural
choice for developing embedded systems. MikroC provides a successful match
featuring highly advanced IDE, ANSI compliant compiler, broad set of hardware
libraries, comprehensive documentation, and plenty of ready-to-run examples.
Features of MikroC
MikroC allows you to quickly develop and deploy complex applications:
Write your C source code using the built-in Code Editor (Code and Parameter
Assistants, Syntax Highlighting, Auto Correct, Code Templates, and more)
Use the included MikroC libraries to dramatically speed up the development:
data acquisition, memory, displays, conversions, communications
Practically all P12, P16, and P18 chips are supported.
Monitor your program structure, variables, and functions in the Code
Explorer.
Generate commented, human-readable assembly, and standard HEX
compatible with all programmers.
Inspect program flow and debug executable logic with the integrated
Debugger.
Get detailed reports and graphs: RAM and ROM map, code statistics,
assembly listing, calling tree, and more
There are plenty of examples for you to expand, develop, and use as building
bricks in your projects. Copy them entirely if you deem fit thats why we
included them with the compiler.
26
As shown MikroC code needs two steps to be transformed to Machine code, the
first step is to transform the C code to Assembly code, which is called
Compilation.
The second step is to transform the Assembly code to Machine Code, and this
process is called Assembling.
So, In spite of being easy to write your code in C Language, MikroC Language is
slower than the Assembly language because it needs two steps to be transformed
to machine language.
b) In case of Interrupt
In MikroC language you don't need to be in bank0, or in bank1, you can deal
directly with Special Function Registers (SFR).
27
Or
Procedure
Part1:
28
Part2:
29
Lab 9
Application for Interrupt using MikroC
Iqama System
Objectives
20. To know how to make interrupt using MikroC language.
21. To know how to use the method of interrupt in Iqama system.
Tools
PIC16F84A microcontroller, MikroC software, PROTEUS software, USB
Programmer.
Theory
Iqama system is a system which can be used to display the time remaining to the
Iqama after each Athan of the Muslim's five pray times.
We know that for each of the five prays there is a recognized (familiar) time
between the Athan and Iqama.
For the Fajr
For the Zuhr and Assr
For the Maghreb and Isha
Note that these time periods (between Athan and Iqama) can differ in some
places, but these are the most familiar time periods.
Lab Work
In this lab we are going to build the Iqama system using MikroC language with
the method of interrupt. So that if the crier (Muezzen) after doing the Athan
pushes the button related to that Athan, two seven segments will decrease from
(20 or 15 or 10 minutes) according to the pray time, and when they reach zero
then the Iqama time comes. LED will flashing indicating that the crier (Muezzen)
must do the Iqama now. The buttons will be connected on bins (RB4, Rb5, and
Rb6) respectively, and will be accessed using interrupt method.
30
Procedure
Write a C code program to make the Iqama system described in Lab Work
Part.
Simulate the program using the circuit shown in figure via Proteus software.
Verify it operates properly when simulated.
Program a PIC 16F84A using the QL2006 programmer.
Build the circuit using the programmed PIC 16F84A and then observe its
operation. Demonstrate the circuits operation to the instructor
32
Lab 10
Application for Keypad and LCD
Security System
Objectives
22. To know what is the Keypad, and how to interface it to the Microcontroller.
23. To know what is the Liquid Crystal Display (LCD), and how to interface it to
the Microcontroller.
24. To know how to use Keypad and LCD to build a security system.
Tools
PIC16F84A microcontroller, MikroC software, PROTEUS software, USB
Programmer.
Theory
Keypad
Keypad is a commonly used input device when more than 8 keys
are necessary. It reduces the number of connections required by
arranging the keys in the form of a matrix which means that each
key could be referred to via its row and column indices.
Lets consider the case of a 12 keys matrix as the one shown
in the figure and we want to interface this keypad to PIC16F84A
microcontroller. In order to detect that one key is pressed we will
use the following strategy:
1. The 12 keys are arranged in 3 columns and 4 rows. Each
column and row is connected by a separated wire as shown in
the figure.
4. For each of the columns we output logic '1' holding other columns to logic '0'
and scan the values of the rows, if one of the rows is logic '1', this means that
the key located at the intersection of the current column and the current row is
pressed. If no row is one, the logic '1' should be moved to the next column
and the rows then rescanned.
5. The PIC should keep repeating this process every time it's required to detect a
key press.
6. This method of keeping searching is called piling Method, also we may use
the interrupt method for key press detection.
7. There are many types of keypads like Phone Keypad (the shown above),
Calculator Keypad, and also keyboard is a form of keypad.
8. Almost all these keypads follow the same way in key press detection.
9. So, for interfacing any keypad to the microcontroller we need number of bins
equal to the number of rows and columns of that keypad.
10. As shown above the rows must be specified as inputs, and columns must be
specified as outputs.
LCD
LCDs (liquid crystal display) are widely used devices that come in different
forms that differ in size and shapes and many other features. However almost all
LCDs conform to a standard interface specification. In our lab we will consider
LM016L LCD with size 2*16 (32 characters) that has a simple interface as
shown in the figure.
34
D0-D7 is the data bus and is used to pass commands and characters to the
LCD. Data can be transferred to and from the display either as a single 8-bit
byte or two 4-bit nibbles. In the later case only the upper four data lines
(D4-D7) are used. This 4-bit mode is beneficial when using a microcontroller
with few input/output pins available.
VSS = Ground (0V)
VDD= VCC (4.5 V 5V)
VEE= Used to alter the control contrast of the display. Ideally, it should be
connected to variable power supply.
RS (Register Select): when this line is low, data bytes transferred to the
display are treated as commands. By setting it to high data is treated as
characters.
E: Starts the transfer of data to or from the LCD on falling edge
R/W: This line is used to choose whether to write to or to read from the
LCD.
Since we will write to the LCD, and not read we will connect R/W to the
ground, and the above figure will be as shown
Lab Work
In this lab we are going to make a security system using password. The LCD
indicates to the user that he must enter the password so that he can access the
system.
If the password is correct a LED will be ON. Showing that the password is
correct, we know that the LED merely represents an electrical signal and can be
replaced by a door or any other 220 VAC applications through a relay.
35
Procedure
37
38
Lab 11
Analog Digital Conversion
Objectives
25. To know what do we mean by Analog Digital Conversion or simply ADC.
26. To know how to use the ADC module in microcontroller PIC16F877A.
Tools
PIC16F877A microcontroller, MikroC software, PROTEUS software, USB
Programmer.
Theory
In almost in all digital systems, there is a frequent need to convert analog
signals generated by peripheral devices such as microphones, analog cameras,
sensors, and etc. into digital values that can be stored and processed.
There are various types of analog to digital converters: high speed ones, precise
ones, and economical ones and so on. Most of them can be directly connected to
any processor as shown in the figure
39
Resolution
The resolution of the converter indicates the number of discrete values it can
produce over the range of analog values. The values are usually stored
electronically in binary form, so the resolution is usually expressed in bits. In
consequence, the number of discrete values available, or "levels", is usually a
power of two. For example, an ADC with a resolution of 8 bits can encode an
analog input to one in 256 different levels, since 28 = 256. The values can
represent the ranges from 0 to 255 (i.e. unsigned integer) or from -128 to 127
(i.e. signed integer), depending on the application.
Resolution can also be defined electrically, and expressed in volts. The voltage
resolution of an ADC is equal to its overall voltage measurement range divided
by the number of discrete intervals as in the formula:
Where:
Q
: is resolution in volts per step (volts per output code),
EFSR
: is the full scale voltage range = VRefHi VRefLow,
M
: is the ADC's resolution in bits.
N
: is the number of intervals, given by the number of available
levels (output codes), which is: N = 2^M
Example
Full scale measurement range = 0 to 10 volts
ADC resolution is 12 bits: 2^12 = 4096 quantization levels (codes)
ADC voltage resolution is: (10V - 0V) / 4096 codes = 10V / 4096 codes
0.00244 volts/code 2.44 mV/code
40
Example
If we make ADCON1 = 0x80, then we have 8 analog channels, and Vref+ =
VDD, and Vref- = Vss.
41
Digital Value
0000000001 = 0x001
2.5V
0111111111 = 0x1FF
5V
1111111110 = 0x3FE
Procedure
Write a C code program to take the analog value existed on channel 2, and
display the result on 3 seven segments.
Hint // Use the ADC built in module in Microcontroller PIC16F877A,
and
Also use DC voltmeter to see your analog value, before it is converted to
digital.
Simulate the program using the circuit shown in figure via Proteus software.
Verify it operates properly when simulated.
Program a PIC 16F84A using the QL2006 programmer.
Build the circuit using the programmed PIC 16F877AA and then observe its
operation. Demonstrate the circuits operation to the instructor
42
43
Lab 12
Pulse-width modulation (PWM)
Objectives
27. To know what do we mean by Analog Digital Conversion or simply ADC.
28. To know how to use the ADC module in microcontroller PIC16F877A.
Tools
PIC16F877A microcontroller, MikroC software, PROTEUS software, USB
Programmer.
Theory
Pulse-width modulation (PWM) is a very efficient way of providing
intermediate amounts of electrical power between fully on and fully off. A
simple power switch with a typical power source provides full power only, when
switched on. PWM is a comparatively-recent technique, made practical by
modern electronic power switches.
The term duty cycle describes the proportion of on time to off time, a low duty
cycle corresponds to low power, because the power is off for most of the time.
Duty cycle is expressed in percent, 100% being fully on. PWM works well with
digital controls, which, because of their on/off nature, can easily set the needed
duty cycle.
This latter expression can be fairly simplified in many cases where ymin = 0 as
44
.
From this, it is obvious that the average value of the signal ( ) is directly
dependent on the duty cycle D.
bit 7-6
bit 5-4
are
bit 3-0
Unimplemented: Read as 0
CCPxX:CCPxY: PWM Least Significant bits
Capture mode:
Unused.
Compare mode:
Unused.
PWM mode:
These bits are the two LSbs of the PWM duty cycle. The eight MSbs
found in CCPRxL.
CCPxM3:CCPxM0: CCPx Mode Select bits
0000 = Capture/Compare/PWM disabled (resets CCPx module)
0100 = Capture mode, every falling edge
0101 = Capture mode, every rising edge
0110 = Capture mode, every 4th rising edge
0111 = Capture mode, every 16th rising edge
45
and
46
Procedure
Write a C code program to changes PWM duty ratio on pin RC2 continually.
If LED is connected to RC2, you can observe the gradual change of emitted
light.
Simulate the program using the circuit shown in figure via Proteus software.
Verify it operates properly when simulated.
Program a PIC 16F84A using the QL2006 programmer.
Build the circuit using the programmed PIC 16F877AA and then observe its
operation. Demonstrate the circuits operation to the instructor
47