libpic170x  0.2
Ease of use library for PIC16(L)1705/1709 chips
Classes | Functions | Variables
timer0.h File Reference

Coarse timing library for measuring times in the background. More...

#include <stdlib.h>
#include <stdint.h>
Include dependency graph for timer0.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  Timer0
 

Functions

void timer0_init (Timer0 *timer0)
 
void timer0_ih (Timer0 *timer0)
 

Variables

Timer0 pic170x_timer0
 

Detailed Description

Coarse timing library for measuring times in the background.

Timer0 configures timer0 of a PIC16(L)F170x chip as continuous ms counter. The values of the continuous counter are stored in the global structure pic170x_timer0.

The counter requires the function timer0_ih to be called in the PIC's interrupt handler. The timer0_ih function will take care of updating the counter values according to the used _XTAL_FREQ settings. Please note that this library assumes that the configured frequency of the PIC does not change over time and remains constant while the program runs.

The timer is configured with a 256 prescaler, which leads to very high increments of the counter values (for a 8 MHz-configured chip it will be around 32-33 ms). This makes the timer values suitable for rough timing keeping only.

Definition in file timer0.h.

Function Documentation

◆ timer0_ih()

void timer0_ih ( Timer0 timer0)

Interrupt handler. Increment the counter of the given structure as a reaction to a timer0 event.

The function resets TMR0IF.

Parameters
timer0The structure for which to increment the timer value. If NULL this defaults to pic170x_timer0.

Definition at line 40 of file timer0.c.

◆ timer0_init()

void timer0_init ( Timer0 timer0)

Initializes timer0 and the given timer0 structure. This function reconfigures the PIC registers:

  • TMR0CS
  • OPTION_REG
  • TMR0IE
Parameters
timer0The timer0 structure that should be initialized. If NULL, it will default to use the pic170x_timer0.

Definition at line 24 of file timer0.c.

Variable Documentation

◆ pic170x_timer0

Timer0 pic170x_timer0

Internal default pic170x_timer0 structure that will be used by the functions timer0_init() and timer0_ih() if no alternative is specified.

Definition at line 22 of file timer0.c.