Tools & Downloads   /   Programmers & ICSP

PIC micro Timer Code

Here's the minimal code to make timer 1 (a 16 bit timer) work using PICBasic. General descriptions of PIC timer variables used to control the timer: (you...

Published
Updated

At a glance

CategoryProgrammers & ICSP
Reading time~2 min

Summary of PIC micro Timer Code

This article explains configuring PIC Timer 1 (16-bit) in PICBasic. It details control bits for T1CON to start/stop the timer and describes reading/writing the high (TMR1H) and low (TMR1L) bytes. Crucially, it emphasizes the specific order required for data access: read Low then High, but write High then Low to ensure accurate operation.

Parts used in the PIC Timer 1 Project:

  • PIC microcontroller
  • PICBasic programming language
  • T1CON register
  • TMR1H register
  • TMR1L register
  • MyTime variable

Here's the minimal code to make timer 1 (a 16 bit timer) work using PICBasic. General descriptions of PIC timer variables used to control the timer: (you should be able to use these no matter what programming language you use): T1CON.0 is the first bit of the timer configuration byte, this bit is used to start and stop the timer. PIC micro Timer Code --so-- T1CON.0=1, starts the timer T1CON.0=0, stops the timer TMR1H is the timer value's high byte (bits 8-15) TMR1L is the timer value's low byte (bits 0-7) --so-- TMR1H = 0 'resets the timer value's high byte TMR1L = 0 'resets the timer value's low byte --and-- MyTime.Lowbyte = TMR1L 'puts the timer's low byte in MyTime's lower 8 bits MyTime.Highbyte = TMR1H 'puts the timer's high byte in MyTime's upper 8 bits NOTE: the MyTime should be declared as a word, not a byte since it has to be 16 bits long to hold the whole 16 bit timer1 value NOTE: When writing to or reading from the timer, it is very important in which order it is done. When reading the timer values you have to read first the LOW then the HIGH byte. When writing the timer values write first the HIGH then the LOW, this is due to complications in how the timer works.   For more detail: PIC micro Timer Code

  • How do I start Timer 1?
    Set T1CON.0 to 1.
  • How do I stop Timer 1?
    Set T1CON.0 to 0.
  • What is the correct order to read the timer values?
    You must read the LOW byte first, then the HIGH byte.
  • What is the correct order to write the timer values?
    You must write the HIGH byte first, then the LOW byte.
  • How do you reset the timer value's high byte?
    Assign 0 to TMR1H.
  • How do you reset the timer value's low byte?
    Assign 0 to TMR1L.
  • What type should the MyTime variable be declared as?
    It must be declared as a word because it holds a 16-bit value.
  • Why is the order of reading and writing important?
    The order is critical due to complications in how the timer works internally.
Programmers & ICSP

Calculator Test using PIC24FJ64GA006 with Proteus Simulation

Introduction The Calculator Test using EASYHDL is a practical microcontroller project built on the PIC24FJ64GA006 and simulated in Proteus. This project demonstrates...

Programmers & ICSP

PID Controlled Oven using TMS320F28027PT with Proteus Simulation

IntroductionThis project demonstrates a PID controlled oven implemented using a PICCOLO TMS320F28027PT microcontroller and verified through Proteus simulation.It is a practical microcontroller...

Programmers & ICSP

PICCOLO Motor Controller Sample Design using TMS320F28023PT with Proteus Simulation

IntroductionThis project demonstrates a PICCOLO motor controller sample design implemented using the TMS320F28023PT Piccolo microcontroller and tested through Proteus simulation. It focuses...

Programmers & ICSP · PIC16F84A

PIC Musical Doorbell using PIC16F84A with Proteus Simulation

IntroductionThis microcontroller project demonstrates a musical doorbell built around a PIC16F84A and a simple piezo sounder.Using two push buttons, the system allows...

Programmers & ICSP · PIC16F877A

EPE PIC/LCD Demo using PIC16F877 with Proteus Simulation

IntroductionThe EPE PIC/LCD Demo is a classic microcontroller project that demonstrates how a PIC16F877 can fully control a PG12864F graphical LCD.Designed as...

Programmers & ICSP · PIC16F628A

DHT11 Low Cost Humidity Sensor using PIC16F628A with Proteus Simulation

IntroductionThis microcontroller project demonstrates how to interface a low-cost DHT11 temperature and humidity sensor with a PIC16F628A using a Proteus simulation environment.The...

Ibrar Ayyub

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough...