SlideShare a Scribd company logo
1 of 29
WEL-COME
PIC Timer Programming
BY AKASH PURI
Objective
• List the Timers of PIC18 and their associated registers
• Describe the various modes of the PIC18 timers
• Program the PIC18 timers in Assembly to generate time delays
Outlines
• Programming timers 0
• Programming timers 1
Introduction
• What is MICROCONTROLLER??????
• It is device which has its own:-
CPU (microprocessor)
RAM
ROM
I/O ports
Timer
ADC and other peripherals
• PIC18 has two to five timers
• Depending on the family number
• These timers can be used as
• Timers to generate a time delay
• Counters to count events happening outside the uC
Section 1.1: Programming timers
0 and 1
• Every timer needs a clock pulse to tick
• Clock source can be
• Internal  1/4th of the frequency of the crystal oscillator on OSC1 and
OSC2 pins (Fosc/4) is fed into timer
• External: pulses are fed through one of the PIC18’s pins  Counter
• Timers are 16-bit wide
• Can be accessed as two separate reg. (TMRxL & TMRxH)
• Each timer has TCON (timer Control) reg.
Timer0 registers and
programming
• TMR0L & TMR0H are 8-bit Reg.
• MOVWF TMR0L
• MOVFF TMR0L, PORTB
TMR0IF flag bit
• Part of INTCON
Figure 1-3. INTCON (Interrupt Control
Figure 1-4. Timer0 Overflow
Flag
Characteristics and operations
of 16-bit mode
1. 16-bit timer, 0000 to FFFFH.
2. After loading TMR0H and TMR0L, the timer must be started.
3. Count up, till it reaches FFFFH, then it rolls over to 0000 and
activate TMR0IF bit.
4. Then TMR0H and TMR0L must be reloaded with the original
value and deactivate TMR0IF bit.
Steps to program Timer0 in 16-bit
mode to generate time delay
1. Load the value into the T0CON register
2. Load reg. TMR0H followed by reg. TMR0L with initial value
3. Start the timer with instruction
BSF T0CON, TMR0ON
4. Keep monitoring the timer flag (TMR0IF) to see if it is raised.
5. Stop the timer
6. Clear the TMR0IF flag 3
7. Go Back to step 2
Figure 1-5. Timer0 16-bit Block
Diagram
Example 1-3-Write a subroutine to create a time
delay
void delay (char cx)
{
int i;
T0CON = 0x83; /* enable TMR0, select instruction clock, prescaler set
to 16 */
for (i = 0; i < cx; i++)
{
TMR0 = 15535; /* load 15535 into TMR0 so that it rolls over in 50000
clock cycles */
INTCONbits.TMR0IF = 0;
while(!(INTCONbits.TMR0IF)); /* wait until TMR0 rolls over */
}
return;
}
Figure 1-6. Timer Delay Calculation for XTAL =
10 MHz with No Prescaler
• General formula for delay calculation
• T = 4/(10MHz) = 0.4 usecond
Write an 8051 C program to toggle all the bits of
port P1 continuously with some delay in
between. Use Timer 0, 16-bit mode to generate
the delay.
• Solution:
#include <reg51.h>
void T0Delay(void);
void main(void)
{
while (1)
{
P1=0x55;
T0Delay();
P1=0xAA;
T0Delay();
}
}
void T0Delay()
{
TMOD=0x01; TL0=0x00;
TH0=0x35;
TR0=1;
while (TF0==0); TR0=0;
TF0=0;
}
Prescaler and generating larger
delay
• The size of delay depend on
• The Crystal frequency
• The timer’s 16-bit register.
• The largest timer happens when TMR0L=TMR0H=0
• Prescaler option is used to duplicate the delay by dividing the
clock by a factor of 2,4, 8,16, 32,64 ,128,256
• If T0CON=0000 0101, then T = 4*64/f
XTAL Osc ÷ 4 ÷ 64 TMRx
Figure 1-7. Timer0 8-bit Block
Diagram
Figure 1-8. Timer1 High and Low
Registers
• Can be programmed in 16-bit mode only
• It has 2 bytes named as TMR1L and RMR1H
• It has also T1CON and TMR1IF
• The module incorporates its own low-power oscillator to provide an
additional clocking option.
• Used as a low-power clock source for the microcontroller in power-
managed operation.
Figure 1-9. Timer1 Block
Diagram
Figure 1-
10. T1CON
(Timer 1
Control )
Register
Figure 1-11. PIR1 (Interrupt
Control Register 1) Contains the
TMR1IF Flag
Write an 8051 C program to toggle all bits of P2
continuously every 500 ms. Use Timer 1, mode 1 to
create the delay.
• Solution:
#include <reg51.h>
void T1M1Delay(void);
void main(void)
{
unsigned char x;
P2=0x55;
while (1)
{
P2=~P2;
for (x=0;x<20;x++)
T1M1Delay();
}
}
void T1M1Delay(void)
{
TMOD=0x10;
TL1=0xFE;
TH1=0xA5;
TR1=1;
while (TF1==0);
TR1=0; TF1=0;
}
Summary
• The PIC18 can have up to four or more
timers/counters. Depending on the family member
• Timers: Generate Time Delays (using Crystal)
• Timers are accessed as two 8-bit registers, TMRLx and
TMRHx
• Can be used either 8-bit or 16-bit
• Each timer has its own Timer Control register
REFERENCES
• WIKIPEDIA
• http://www.extreamelectronics.org//
• http://www.google.com/search
• The 8051 Microcontroller and Embedded Systems Using
Assembly and C
THANK YOU!!!!!!
Any Questions ..?
MADE BY :- AKASH PURI
(T.Y. B. Tech. VIT , Pune)
THANK
YOU!!!!! AGAIN

More Related Content

What's hot

Pic microcontroller architecture
Pic microcontroller architecturePic microcontroller architecture
Pic microcontroller architectureJamia Hamdard
 
Timer And Counter in 8051 Microcontroller
Timer And Counter in 8051 MicrocontrollerTimer And Counter in 8051 Microcontroller
Timer And Counter in 8051 MicrocontrollerJay Makwana
 
Microcontroller 8051
Microcontroller 8051Microcontroller 8051
Microcontroller 8051Sadiq Rahim
 
Introduction to ARM LPC2148
Introduction to ARM LPC2148Introduction to ARM LPC2148
Introduction to ARM LPC2148Veera Kumar
 
Interrupts for PIC18
Interrupts for PIC18Interrupts for PIC18
Interrupts for PIC18raosandy11
 
Timer counter in arm7(lpc2148)
Timer counter in arm7(lpc2148)Timer counter in arm7(lpc2148)
Timer counter in arm7(lpc2148)Aarav Soni
 
8051 architecture
8051 architecture8051 architecture
8051 architecturesb108ec
 
8086 modes
8086 modes8086 modes
8086 modesPDFSHARE
 
8051 Microcontroller ppt
8051 Microcontroller ppt8051 Microcontroller ppt
8051 Microcontroller pptRahul Kumar
 
Sensor interfacing in 8051
Sensor interfacing in 8051Sensor interfacing in 8051
Sensor interfacing in 8051Irfan Ahmad
 
Architecture of 8086 Microprocessor
Architecture of 8086 Microprocessor  Architecture of 8086 Microprocessor
Architecture of 8086 Microprocessor Mustapha Fatty
 
Pic16cxx instruction set
Pic16cxx instruction setPic16cxx instruction set
Pic16cxx instruction setv Kalairajan
 
AVR Microcontroller
AVR MicrocontrollerAVR Microcontroller
AVR MicrocontrollerÖzcan Acar
 

What's hot (20)

8051 timer counter
8051 timer counter8051 timer counter
8051 timer counter
 
Pic microcontroller architecture
Pic microcontroller architecturePic microcontroller architecture
Pic microcontroller architecture
 
Timer And Counter in 8051 Microcontroller
Timer And Counter in 8051 MicrocontrollerTimer And Counter in 8051 Microcontroller
Timer And Counter in 8051 Microcontroller
 
PIC Microcontrollers
PIC MicrocontrollersPIC Microcontrollers
PIC Microcontrollers
 
8086 micro processor
8086 micro processor8086 micro processor
8086 micro processor
 
8051 interfacing
8051 interfacing8051 interfacing
8051 interfacing
 
Microcontroller 8051
Microcontroller 8051Microcontroller 8051
Microcontroller 8051
 
ARM Processors
ARM ProcessorsARM Processors
ARM Processors
 
Introduction to ARM LPC2148
Introduction to ARM LPC2148Introduction to ARM LPC2148
Introduction to ARM LPC2148
 
Interrupts for PIC18
Interrupts for PIC18Interrupts for PIC18
Interrupts for PIC18
 
Avr timers
Avr timersAvr timers
Avr timers
 
Timer counter in arm7(lpc2148)
Timer counter in arm7(lpc2148)Timer counter in arm7(lpc2148)
Timer counter in arm7(lpc2148)
 
8051 architecture
8051 architecture8051 architecture
8051 architecture
 
8086 modes
8086 modes8086 modes
8086 modes
 
8051 Microcontroller ppt
8051 Microcontroller ppt8051 Microcontroller ppt
8051 Microcontroller ppt
 
Sensor interfacing in 8051
Sensor interfacing in 8051Sensor interfacing in 8051
Sensor interfacing in 8051
 
Architecture of 8086 Microprocessor
Architecture of 8086 Microprocessor  Architecture of 8086 Microprocessor
Architecture of 8086 Microprocessor
 
Pic16cxx instruction set
Pic16cxx instruction setPic16cxx instruction set
Pic16cxx instruction set
 
Interfacing Stepper motor with 8051
Interfacing Stepper motor with 8051Interfacing Stepper motor with 8051
Interfacing Stepper motor with 8051
 
AVR Microcontroller
AVR MicrocontrollerAVR Microcontroller
AVR Microcontroller
 

Viewers also liked

Using Timers in PIC18F Microcontrollers
Using Timers in PIC18F MicrocontrollersUsing Timers in PIC18F Microcontrollers
Using Timers in PIC18F MicrocontrollersCorrado Santoro
 
Autocad Electrical 2011 Overview Brochure
Autocad Electrical 2011 Overview BrochureAutocad Electrical 2011 Overview Brochure
Autocad Electrical 2011 Overview BrochureApplied Engineering
 
I2C programming with C and Arduino
I2C programming with C and ArduinoI2C programming with C and Arduino
I2C programming with C and Arduinosato262
 
8051 programming skills using EMBEDDED C
8051 programming skills using EMBEDDED C8051 programming skills using EMBEDDED C
8051 programming skills using EMBEDDED CAman Sharma
 
Electrical Drawings and Schematics
Electrical Drawings and SchematicsElectrical Drawings and Schematics
Electrical Drawings and SchematicsLiving Online
 
AutoCad Electrical
AutoCad ElectricalAutoCad Electrical
AutoCad Electricalrahul_9463
 
Routing and OSPF
Routing and OSPFRouting and OSPF
Routing and OSPFarpit
 
INTERRUPTS OF 8086 MICROPROCESSOR
INTERRUPTS OF 8086 MICROPROCESSORINTERRUPTS OF 8086 MICROPROCESSOR
INTERRUPTS OF 8086 MICROPROCESSORGurudev joshi
 
PLC and SCADA training.
PLC and SCADA training.PLC and SCADA training.
PLC and SCADA training.Ishank Ranjan
 

Viewers also liked (15)

Pic18f4550
Pic18f4550Pic18f4550
Pic18f4550
 
Using Timers in PIC18F Microcontrollers
Using Timers in PIC18F MicrocontrollersUsing Timers in PIC18F Microcontrollers
Using Timers in PIC18F Microcontrollers
 
Mikroc gps
Mikroc gpsMikroc gps
Mikroc gps
 
I2C Protocol
I2C ProtocolI2C Protocol
I2C Protocol
 
Autocad Electrical 2011 Overview Brochure
Autocad Electrical 2011 Overview BrochureAutocad Electrical 2011 Overview Brochure
Autocad Electrical 2011 Overview Brochure
 
Read and Understand The Electrical Diagram
Read and Understand The Electrical DiagramRead and Understand The Electrical Diagram
Read and Understand The Electrical Diagram
 
I2C programming with C and Arduino
I2C programming with C and ArduinoI2C programming with C and Arduino
I2C programming with C and Arduino
 
8051 programming skills using EMBEDDED C
8051 programming skills using EMBEDDED C8051 programming skills using EMBEDDED C
8051 programming skills using EMBEDDED C
 
Electrical Drawings and Schematics
Electrical Drawings and SchematicsElectrical Drawings and Schematics
Electrical Drawings and Schematics
 
AutoCad Electrical
AutoCad ElectricalAutoCad Electrical
AutoCad Electrical
 
Routing and OSPF
Routing and OSPFRouting and OSPF
Routing and OSPF
 
INTERRUPTS OF 8086 MICROPROCESSOR
INTERRUPTS OF 8086 MICROPROCESSORINTERRUPTS OF 8086 MICROPROCESSOR
INTERRUPTS OF 8086 MICROPROCESSOR
 
PLC and SCADA training.
PLC and SCADA training.PLC and SCADA training.
PLC and SCADA training.
 
PLC Basic
PLC BasicPLC Basic
PLC Basic
 
I2C
I2CI2C
I2C
 

Similar to PIC timer programming

Microcontrollers-MODULE4.pptx
Microcontrollers-MODULE4.pptxMicrocontrollers-MODULE4.pptx
Microcontrollers-MODULE4.pptxAmoghR3
 
Timers done by Priyanga KR
Timers done by Priyanga KRTimers done by Priyanga KR
Timers done by Priyanga KRPriyangaKR1
 
lecture 12 counter_microcontroller2.ppt
lecture 12 counter_microcontroller2.pptlecture 12 counter_microcontroller2.ppt
lecture 12 counter_microcontroller2.pptHebaEng
 
timer counter (1).pptx
timer counter (1).pptxtimer counter (1).pptx
timer counter (1).pptxSujalKumar73
 
PIC-Chapter_10.pptx
PIC-Chapter_10.pptxPIC-Chapter_10.pptx
PIC-Chapter_10.pptxAliBzeih7
 
Advanced Embedded Automatic Car Parking System
	Advanced Embedded Automatic Car Parking System	Advanced Embedded Automatic Car Parking System
Advanced Embedded Automatic Car Parking Systemtheijes
 
Micro c lab7(timers)
Micro c lab7(timers)Micro c lab7(timers)
Micro c lab7(timers)Mashood
 
moving message display of lcd
 moving message display of lcd moving message display of lcd
moving message display of lcdabhishek upadhyay
 
8051 Timers / Counters
8051 Timers / Counters8051 Timers / Counters
8051 Timers / CountersPatricio Lima
 
MICROCONTROLLER TIMERS.ppt
MICROCONTROLLER TIMERS.pptMICROCONTROLLER TIMERS.ppt
MICROCONTROLLER TIMERS.pptreemasajin1
 

Similar to PIC timer programming (20)

8051 ch9
8051 ch98051 ch9
8051 ch9
 
AVRTIMER.pptx
AVRTIMER.pptxAVRTIMER.pptx
AVRTIMER.pptx
 
Microcontrollers-MODULE4.pptx
Microcontrollers-MODULE4.pptxMicrocontrollers-MODULE4.pptx
Microcontrollers-MODULE4.pptx
 
Timers
TimersTimers
Timers
 
Timers done by Priyanga KR
Timers done by Priyanga KRTimers done by Priyanga KR
Timers done by Priyanga KR
 
UNIT-5.ppt
UNIT-5.pptUNIT-5.ppt
UNIT-5.ppt
 
lecture 12 counter_microcontroller2.ppt
lecture 12 counter_microcontroller2.pptlecture 12 counter_microcontroller2.ppt
lecture 12 counter_microcontroller2.ppt
 
timer counter (1).pptx
timer counter (1).pptxtimer counter (1).pptx
timer counter (1).pptx
 
PIC-Chapter_10.pptx
PIC-Chapter_10.pptxPIC-Chapter_10.pptx
PIC-Chapter_10.pptx
 
8051e
8051e8051e
8051e
 
12 mt06ped007
12 mt06ped007 12 mt06ped007
12 mt06ped007
 
8051 ch9-950217
8051 ch9-9502178051 ch9-950217
8051 ch9-950217
 
Advanced Embedded Automatic Car Parking System
	Advanced Embedded Automatic Car Parking System	Advanced Embedded Automatic Car Parking System
Advanced Embedded Automatic Car Parking System
 
8051 timers--2
   8051 timers--2   8051 timers--2
8051 timers--2
 
Micro c lab7(timers)
Micro c lab7(timers)Micro c lab7(timers)
Micro c lab7(timers)
 
moving message display of lcd
 moving message display of lcd moving message display of lcd
moving message display of lcd
 
4.Timer_1.ppt
4.Timer_1.ppt4.Timer_1.ppt
4.Timer_1.ppt
 
8051 Timers / Counters
8051 Timers / Counters8051 Timers / Counters
8051 Timers / Counters
 
MICROCONTROLLER TIMERS.ppt
MICROCONTROLLER TIMERS.pptMICROCONTROLLER TIMERS.ppt
MICROCONTROLLER TIMERS.ppt
 
TIMERS.pptx
TIMERS.pptxTIMERS.pptx
TIMERS.pptx
 

Recently uploaded

IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024Mark Billinghurst
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130Suhani Kapoor
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...Soham Mondal
 
HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2RajaP95
 
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)dollysharma2066
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile servicerehmti665
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerAnamika Sarkar
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoão Esperancinha
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSKurinjimalarL3
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfAsst.prof M.Gokilavani
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...VICTOR MAESTRE RAMIREZ
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSCAESB
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidNikhilNagaraju
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionDr.Costas Sachpazis
 

Recently uploaded (20)

IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
 
HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2
 
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile service
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
 
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
 
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
 
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptxExploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentation
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfid
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
 
POWER SYSTEMS-1 Complete notes examples
POWER SYSTEMS-1 Complete notes  examplesPOWER SYSTEMS-1 Complete notes  examples
POWER SYSTEMS-1 Complete notes examples
 

PIC timer programming

  • 3. Objective • List the Timers of PIC18 and their associated registers • Describe the various modes of the PIC18 timers • Program the PIC18 timers in Assembly to generate time delays
  • 4. Outlines • Programming timers 0 • Programming timers 1
  • 5. Introduction • What is MICROCONTROLLER?????? • It is device which has its own:- CPU (microprocessor) RAM ROM I/O ports Timer ADC and other peripherals
  • 6.
  • 7. • PIC18 has two to five timers • Depending on the family number • These timers can be used as • Timers to generate a time delay • Counters to count events happening outside the uC
  • 8. Section 1.1: Programming timers 0 and 1 • Every timer needs a clock pulse to tick • Clock source can be • Internal  1/4th of the frequency of the crystal oscillator on OSC1 and OSC2 pins (Fosc/4) is fed into timer • External: pulses are fed through one of the PIC18’s pins  Counter • Timers are 16-bit wide • Can be accessed as two separate reg. (TMRxL & TMRxH) • Each timer has TCON (timer Control) reg.
  • 9. Timer0 registers and programming • TMR0L & TMR0H are 8-bit Reg. • MOVWF TMR0L • MOVFF TMR0L, PORTB
  • 10. TMR0IF flag bit • Part of INTCON Figure 1-3. INTCON (Interrupt Control
  • 11. Figure 1-4. Timer0 Overflow Flag
  • 12. Characteristics and operations of 16-bit mode 1. 16-bit timer, 0000 to FFFFH. 2. After loading TMR0H and TMR0L, the timer must be started. 3. Count up, till it reaches FFFFH, then it rolls over to 0000 and activate TMR0IF bit. 4. Then TMR0H and TMR0L must be reloaded with the original value and deactivate TMR0IF bit.
  • 13. Steps to program Timer0 in 16-bit mode to generate time delay 1. Load the value into the T0CON register 2. Load reg. TMR0H followed by reg. TMR0L with initial value 3. Start the timer with instruction BSF T0CON, TMR0ON 4. Keep monitoring the timer flag (TMR0IF) to see if it is raised. 5. Stop the timer 6. Clear the TMR0IF flag 3 7. Go Back to step 2
  • 14. Figure 1-5. Timer0 16-bit Block Diagram
  • 15. Example 1-3-Write a subroutine to create a time delay void delay (char cx) { int i; T0CON = 0x83; /* enable TMR0, select instruction clock, prescaler set to 16 */ for (i = 0; i < cx; i++) { TMR0 = 15535; /* load 15535 into TMR0 so that it rolls over in 50000 clock cycles */ INTCONbits.TMR0IF = 0; while(!(INTCONbits.TMR0IF)); /* wait until TMR0 rolls over */ } return; }
  • 16. Figure 1-6. Timer Delay Calculation for XTAL = 10 MHz with No Prescaler • General formula for delay calculation • T = 4/(10MHz) = 0.4 usecond
  • 17. Write an 8051 C program to toggle all the bits of port P1 continuously with some delay in between. Use Timer 0, 16-bit mode to generate the delay. • Solution: #include <reg51.h> void T0Delay(void); void main(void) { while (1) { P1=0x55; T0Delay(); P1=0xAA; T0Delay(); } } void T0Delay() { TMOD=0x01; TL0=0x00; TH0=0x35; TR0=1; while (TF0==0); TR0=0; TF0=0; }
  • 18. Prescaler and generating larger delay • The size of delay depend on • The Crystal frequency • The timer’s 16-bit register. • The largest timer happens when TMR0L=TMR0H=0 • Prescaler option is used to duplicate the delay by dividing the clock by a factor of 2,4, 8,16, 32,64 ,128,256 • If T0CON=0000 0101, then T = 4*64/f XTAL Osc ÷ 4 ÷ 64 TMRx
  • 19. Figure 1-7. Timer0 8-bit Block Diagram
  • 20. Figure 1-8. Timer1 High and Low Registers • Can be programmed in 16-bit mode only • It has 2 bytes named as TMR1L and RMR1H • It has also T1CON and TMR1IF • The module incorporates its own low-power oscillator to provide an additional clocking option. • Used as a low-power clock source for the microcontroller in power- managed operation.
  • 21. Figure 1-9. Timer1 Block Diagram
  • 22. Figure 1- 10. T1CON (Timer 1 Control ) Register
  • 23. Figure 1-11. PIR1 (Interrupt Control Register 1) Contains the TMR1IF Flag
  • 24. Write an 8051 C program to toggle all bits of P2 continuously every 500 ms. Use Timer 1, mode 1 to create the delay. • Solution: #include <reg51.h> void T1M1Delay(void); void main(void) { unsigned char x; P2=0x55; while (1) { P2=~P2; for (x=0;x<20;x++) T1M1Delay(); } } void T1M1Delay(void) { TMOD=0x10; TL1=0xFE; TH1=0xA5; TR1=1; while (TF1==0); TR1=0; TF1=0; }
  • 25. Summary • The PIC18 can have up to four or more timers/counters. Depending on the family member • Timers: Generate Time Delays (using Crystal) • Timers are accessed as two 8-bit registers, TMRLx and TMRHx • Can be used either 8-bit or 16-bit • Each timer has its own Timer Control register
  • 26. REFERENCES • WIKIPEDIA • http://www.extreamelectronics.org// • http://www.google.com/search • The 8051 Microcontroller and Embedded Systems Using Assembly and C
  • 29. MADE BY :- AKASH PURI (T.Y. B. Tech. VIT , Pune) THANK YOU!!!!! AGAIN