Professional Documents
Culture Documents
Microprocessors and Microcontrollers Lab: Title: Components
Microprocessors and Microcontrollers Lab: Title: Components
Components:
Microcontroller PIC16F877A
Crystal – 20MHz
Capacitor – 22uF
Push Button
Resistor – 1K
Resistor – 470 ohms
Transistor (BC547)
Software:
MPLABX IDE
Proteus
Introduction:
. Timers ,
The Timer is used to measure the time or generate an accurate time delay. It is an important
application in an embedded system. It maintains the timing of operation in sync with a system
clock or an external clock. The timer is used to count cycles and perform a particular action at a
specified moment or optionally start an interrupt cycle. The digital cycles counted by the timer
can be supplied internally through the peripheral clock or externally through a crystal.
The timer is nothing but a simple binary counter that can be configured to count clock
pulses(Internal/External). Once it reaches the max value, it will roll back to zero setting up an
Overflow flag and generates the interrupt if enabled.
Prescaler: Prescaler is a block that presents inside the timer module and it is used to divide the
clock frequency by a constant. It allows the timer to be clocked at the rate a user desires.
. TIMER 0 .
Timer 0 Registers
Timer 0 has a register called TMR0 Register, which is 8 bits of size. The below table shows the
registers associated with PIC16f877A Timer 0 module.
Register Description
OPTION_RE This registers is used to configure the TIMER0 Prescalar, Clock Source etc
G
TMR0 This register will hold the count value.When this register overflows (FF to 00)
then an interrupt will be generated.
INTCON This register contains the Timer0 overflow flag(TMR0IF) and corresponding
Interrupt Enable flag(TMR0IE).
Structure of OPTION_REG :
Structure of INTCON :
. Delay Calculation .
It is important to learn how time delay is calculated by the timer since the exact delay generation
is the most common application of timer.
= 256-((Delay * Fosc)/(Prescalar4))
= 256-((1ms * 20Mhz)/(32*4))
= 256-156=100
Procedure:
I. Open the MPLAB X IDE and create a new project by clicking the file option on the upward left
corner and selecting new project.
II. Then select the XC 8 compiler and write the project name and create your object.
III. Select the source file and create the extension file for the project to write your code.
IV. Design the circuit on proteus using PIC16F877A.
V. Then choose the hex file by clicking on microcontroller component on proteus.
VI. You will get the result of integration between software.
MP Lab Code:
Code:
#include <xc.h>
#include <stdio.h>
#include <stdlib.h>
#define _XTAL_FREQ 20000000 //define crystal frequency to 20MHz
__PROG_CONFIG(1,0x3F32);
Output:
Hardware:
Conclusion:
The purpose of this lab is to learn about the timer0, that Timer is used to measure the time or
generate an accurate time delay. It is an important application in an embedded system. its
working and specifications of timers. Also study about the how to use timers. We successfully
implemented our code onto MP-lab for the timer0 as a counter with pic16f877a and make two
digit counter in proteus using two seven segments.