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 1 .
TIMER 1 REGISTERS
Timer 1 has a register called TMR1 register, which is 16 bits of size. The below table shows the
registers associated with PIC16f877A Timer 1 module.
Structure of T1CON :
. Delay Calculation .
Example: Given that a time delay of 100 ms is to be generated and a 20MHz crystal
oscillator is connected with PIC.
The timer is related to the internal frequency which is always Fosc/4.
= 65536-((Delay * Fosc)/(Prescalar4))
= 65536-((100ms * 20Mhz)/(8*4))
= 3036
PROCEDURE:
1. Open the MPLAB X IDE and create a new project by clicking the file option on the upward left
corner and selecting new project.
2. Then select the XC 8 compiler and write the project name and create your object.
3. Select the source file and create the extension file for the project to write your code.
4. Design the circuit on proteus using PIC16F877A.
5. Then choose the hex file by clicking on microcontroller component on proteus.
6. You will get the result of integration between software.
Task:
Write a code to make a counter with timer 0 using pic16F877A.
Code:
#include <xc.h>
#include <stdio.h>
#include <stdlib.h>
__PROG_CONFIG(1,0x3F32);
char value = 0;
#define SBIT_PS1 5
#define SBIT_PS0 4
if(TMR1IF==1)
TMR1L=0xDC;
void main()
TMR1L=0xDC;
while(1)
PORTD = value;
Output:
Hardware:
Conclusion:
The purpose of this lab is to learn about the timer1, 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 timer with pic16f877a and make a circuit on the proteus to blink a led with a delay.
.END.