Vous êtes sur la page 1sur 3

#include <p30f4011.

h>
#include <stdlib.h>
#include <string.h>
#define t PORTBbits.RB0
#define e PORTBbits.RB1
#define l PORTBbits.RB2
//Prototipos de
Funciones--------------------------------------------------------------------------
-----------------------------------------------------------------
void ports(void);

void timer2(void);
void timer1(void);
void timer5(void);
void oc1(void);
void pwm1(void);

//Funcion
Principal--------------------------------------------------------------------------
----------------------------------------------------------------------------
void main(void)
{
ports();

timer2();
timer1();
timer5();
oc1();
pwm1();

while(1)
{
}
}
//Implementacion de
funciones--------------------------------------------------------------------------
-----------------------------------------------------------
void ports (void)
{
ADPCFG=509;
TRISB=0;
TRISBbits.TRISB1=1;
}
void timer2 (void)
{
T2CON=0;
T2CONbits.TCKPS=1;
TMR2=0;
IEC0bits.T2IE=1;
IPC1bits.T2IP=4;
IFS0bits.T2IF=0;
T2CONbits.TON=1;
}
void oc1(void)
{
OC1CON=0;
OC1CONbits.OCM=6;
OC1R=0;
PR2=12600;
TMR2=0;
IEC0bits.OC1IE=1;
IPC0bits.OC1IP=3;
IFS0bits.OC1IF=0;
}
void pwm1(void)
{

PWMCON1 = 0x00FF; // Enable all PWM pairs in complementary mode


PTCONbits.PTCKPS = 3; // prescale=1:64 (0=1:1, 1=1:4, 2=1:16, 3=1:64)
PTPER = 9375; // 20ms PWM period (15-bit period value)
PDC1 = 1406; // 1.5ms pulse width on PWM channel 1
PTCONbits.PTEN = 1; // Enable PWM time base
}
void timer1(void)
{
T1CON=0;
T1CONbits.TCKPS=0;
TMR1=0;
PR1=65535;
TRISCbits.TRISC14=1;
T1CONbits.TGATE=1;
IEC0bits.T1IE=1;
IFS0bits.T1IF=0;
IPC0bits.T1IP=5;
T1CONbits.TON=1;
}
void timer5(void)
{
T5CON=0;
T5CONbits.TCKPS=0;
TMR5=0;
PR5=50;
IEC1bits.T5IE=1;
IPC5bits.T5IP=6;
IFS1bits.T5IF=0;
T5CONbits.TON=1;
}
//Interrupciones-------------------------------------------------------------------
-----------------------------------------------------------------------------------
---------
void __attribute__((interrupt, no_auto_pvs)) _T2Interrupt(void)
{
IFS0bits.T2IF=0;
}
void __attribute__((interrupt, no_auto_pvs)) _OC1Interrupt(void)
{
IFS0bits.OC1IF=0;
}

void __attribute__((interrupt, no_auto_pvs)) _T1Interrupt(void)


{

int n;
n=(TMR1/58);
if(n>=120)
{
l=1;
PDC1 =848;
}
else
{
if(n<60 )
{
PDC1 =84;
l=0;

}
else
{
if(n<800)
{
l=0;

}
else
{
if(n<100)
{
l=0;

}
}
}
}
TMR1=0;
IFS0bits.T1IF=0;
}

void __attribute__((interrupt, no_auto_pvs)) _T5Interrupt(void)


{
t= !t;
TMR5=0;
IFS1bits.T5IF=0;
}
//Finish---------

Vous aimerez peut-être aussi