Académique Documents
Professionnel Documents
Culture Documents
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)
{
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;
}