You are on page 1of 6

Interrupción interna

timer32 bits
sesion5
INTERRUPCION INTERNA DEL dsPIC33FJ32MC202: TIMER1

SE CONTROLA UN PROCESO DE ENCENDIDO Y APAGADO DE UN LED UBICADO EN EL PIN RB0 , MEDIANTE UNA RUTINA
CON RETARDO ( DELAY  1seg. ).
LUEGO UN LED UBICADO EN EL PIN RB1 , LED D2 , SE REALIZA EL ENCENDIDO Y APAGADO , MEDIANTE LA INTERRUPCION
DEL TIMER1 CADA 0.5 seg en modo de 32 bits

U1
R1 1
MCLR RB0/CN4/RP0/C2IN-/AN2/EMUD1/PGD1
4
A
10k 20 5
VCAP/VDDCORE RB1/CN5/RP1/C2IN+/AN3/EMUC1/PGC1
6
RB2/CN6/RP2/AN4 B
2 7
RA0/CN2/VREF+/AN0 RB3/CN7/RP3/AN5
3 11
RA1/CN3/VREF-/AN1 RB4/CN1/RP4/SOSCI C
9
RA2/CN30/CLKI/OSCI RB5/CN27/RP5/ASDA1/EMUD3/PGD3
14 D2 D1
10 15 . .
RA3/CN29/CLKO/OSCO RB6/CN24/RP6/ASCL1/EMUC3/PGC3 D
12 16
RA4/CN0/T1CK/SOSCO RB7/CN23/RP7/INT0
17
RB8/CN22/RP8/SCL1/PW M2H1/TCK
18
RB9/CN21/RP9/SDA1/PW M2L1/TDO
21
RB10/CN16/RP10/PW M1H3/TDI/EMUD2/PGD2
22
RB11/CN15/RP11/PW M1L3/TMS/EMUC2/PGC2
23
RB12/CN14/RP12/PW M1H2
24
RB13/CN13/RP13/PW M1L2
28 25
AVDD RB14/CN12/RP14/PW M1H1
27 26
AVSS RB15/CN11/RP15/PW M1L1
DSPIC33FJ32MC202
PROGRAMA

#include <xc.h>
#include <libpic30.h>
#include <p33FJ32MC202.h>
#include <stdio.h>
#include <stdlib.h>
#include"config1.h"
// ********************Ajustes de configuración

#define FOS 8000000UL //4 MHz


#define FCY FOS/2 //velocidad 2MIPS
#define delay_ms(x)__delay32((FCY/1000)*x) //delay en milisegundos
#define delay_us(x)__delay32(MIPS*x) //delay en microsegundos
// ****** programa principal***************
int main(void)
{
AD1PCFGL=0xFFFF;
config_timer32();
_TRISB0=0;
_TRISB1=0;
TRISB = 0b0000000000000000; //Establecer todos los pines del puerto B como salidas
while(1)
{
_LATB0 = 1; // Establecer RB0 alto
delay_ms(1000); // 1000ms delay
_LATB0 = 0; // Establecer RB0 bajo
delay_ms(1000); // 1000ms delay
}
return 0;
}
void config_timer32(void)
{
T3CONbits.TON = 0;//Stop any 16-bit Timer3 operation
T2CONbits.TON = 0;// Stop any 16/32-bit Timer3 operation
T2CONbits.T32 = 1;// Enable 32-bit Timer mode
T2CONbits.TCS = 0;// Select internal instruction cycle clock
T2CONbits.TGATE =0;//Disable Gated Timer mode
T2CONbits.TCKPS =0b10;//Select 1:1 Prescaler Precontador (0 = 01:01, 1 = 01:08, 2 = 1:64, 3 = 1:256)
TMR3 = 0x00;//Clear 32-bit Timer (msw)
TMR2 = 0x00;//Clear 32-bit Timer (lsw)
PR3 = 0;//Load 32-bit period value (msw)
PR2 = 0x7A12;//Load 32-bit period value (lsw)
_T3IP = 0x01;//Set Timer Interrupt Priority Level - 7(highest) to 1(lowest) 
_T3IF = 0;//Clear Timer Interrupt Flag
_T3IE = 1;//Enable Timer interrupt
T2CONbits.TON =1;//Start 32-bit Time
}
// Rutina de Interrupcion del timer32.
void __attribute__((interrupt, auto_psv)) _T3Interrupt(void)
{
    _LATA0 = ~_LATA0;
    _T3IF = 0; //Clear interrupt flag
}

U1
R1 1
MCLR RB0/CN4/RP0/C2IN-/AN2/EMUD1/PGD1
4
A
10k 20 5
VCAP/VDDCORE RB1/CN5/RP1/C2IN+/AN3/EMUC1/PGC1
6
RB2/CN6/RP2/AN4 B
2 7
RA0/CN2/VREF+/AN0 RB3/CN7/RP3/AN5
3 11
RA1/CN3/VREF-/AN1 RB4/CN1/RP4/SOSCI C
9
RA2/CN30/CLKI/OSCI RB5/CN27/RP5/ASDA1/EMUD3/PGD3
14 D2 D1
10 15 . .
RA3/CN29/CLKO/OSCO RB6/CN24/RP6/ASCL1/EMUC3/PGC3 D
12 16
RA4/CN0/T1CK/SOSCO RB7/CN23/RP7/INT0
17
RB8/CN22/RP8/SCL1/PW M2H1/TCK
18
RB9/CN21/RP9/SDA1/PW M2L1/TDO
21
RB10/CN16/RP10/PW M1H3/TDI/EMUD2/PGD2
22
RB11/CN15/RP11/PW M1L3/TMS/EMUC2/PGC2
23
RB12/CN14/RP12/PW M1H2
24
RB13/CN13/RP13/PW M1L2
28 25
AVDD RB14/CN12/RP14/PW M1H1
27 26
AVSS RB15/CN11/RP15/PW M1L1
DSPIC33FJ32MC202

You might also like