You are on page 1of 10

atea de Electronica Telecomunicatii si Tehnologia Informatiei - IASI

PIC16LF1937

2. Registrul TIMER
Aplicatii Practice ale Microcontrolerel

sl.dr.ing. Cristian Aghion


ing. Alin Burlaciuc
5/28/15

TIMER aplicatii

APM 2014
5/28/15

PIC16LF1937: Arhitectura
PIC Microcontroler

TMR 0
TMR 1
TMR 2/4/6

Structura interna

Diagrama bloc

APM 2014
5/28/15

TMR1: Registrii de configurare


Proprietati:
registru pe 16-bit (TMR1H:TMR1L)
clock intern/extern programabil
prescaler
intrerupere la supraincarcare
oscillator LP dedicat
functie de comparare/captura

TMR1 Diagrama bloc

TMR 1

APM 2014
5/28/15

TMR1 Control Register

TMR1 =

T1CON
T1GCON
INTCON

TMR 1

APM 2014
5/28/15

TMR1 Control Register


T1CON

TMR 1

APM 2014
5/28/15

TMR1 Control Register


T1GCON

OPTIONAL

TMR 1

APM 2014
5/28/15

TMR1 Calculator
Perioada de timp
dorita

1
TTIMER = ----------FTIMER

Frecventa necesara
FOSC
Frecventa Oscilator

FTIMER = ---------------------------------------------------------4 * Prescaler * (65536 TMR1) *Count


Variabila
Oscilator Intern

TMR1

T1IF = 1;

FOSC
Count = ---------------------------------------------------------4 * Prescaler * (65536 TMR1) * FTIMER
TMR 1

APM 2014
5/28/15

TMR1

#include <htc.h>
__CONFIG(FOSC_INTOSC & WDTE_OFF & PWRTE_OFF & MCLRE_OFF & CP_OFF & CPD_OFF & BOREN_ON & CLKOUTEN_OFF & IESO_ON & FCMEN_ON);
__CONFIG(WRT_OFF & PLLEN_OFF & STVREN_ON & BORV_LO & LVP_ON);
int Count = 0;
void TMR1_config()
{
OSCCON = 0b11101010;
ANSELD = 0x00;
TRISD = 0x00;
TMR1 = 0b00010001;
T1GCON = 0b00000000;
} //end TMR1_config
void main (void)
{
TMR1_config();
while(1)
{
while(!TMR1IF);
TMR1IF = 0;
Count ++;
If(Count == 15)
{
Count = 0;
RD1 ^= 1;
} //end if
}//end while
} //end main

TMR 1

APM 2014
5/28/15

TMR1 Interuperi

#include <htc.h>
__CONFIG(FOSC_INTOSC & WDTE_OFF & PWRTE_OFF & MCLRE_OFF & CP_OFF & CPD_OFF & BOREN_ON & CLKOUTEN_OFF & IESO_ON & FCMEN_ON);
__CONFIG(WRT_OFF & PLLEN_OFF & STVREN_ON & BORV_LO & LVP_ON);
int Count = 0;
void TMR1_config()
{
TMR1 = 0b00010001;
T1GCON = 0b00000000;
OSCCON = 0b00000000;
TMR1IE = 1;
PEIE = 1;
GIE = 1;
} //end TMR1_config
void main (void)
{
TMR1_config();
while(1)
{
// tai frunze la caini
}//end while
} //end main
void interrupt TMR ()
{
TMR1IF = 0;
TMR1H = 0x3C;
TMR1L = 0xAF;
} //end TMR1_config

TMR 1

APM 2014
5/28/15

10