Documente Academic
Documente Profesional
Documente Cultură
h>
#include <plib.h>
/*
*
*/
int b=0; int puls=0;
int a=0;
int desbord=0;
#pragma config POSCMOD = HS // modo de alta velocidad cristal
#pragma config FNOSC = PRIPLL // Uso oscilador principal con PLL (XT, SA, o EC)
#pragma config FPLLIDIV = DIV_1 // Dividir 12MHz a entre 4-5MHz antes de PLL (ahora
4 MHz)
#pragma config FPLLMUL = MUL_20 // Multiplicar con PLL (ahora 80 MHz)
#pragma config FPLLODIV= DIV_2 // Dividir Despu�s de PLL (ahora 40 MHz)
// see figure 8.1 in datasheet for more info
#pragma config FWDTEN = OFF // Watchdog Timer Disabled
#pragma config ICESEL = ICS_PGx1 // ICE/ICD Comm Channel Select
#pragma config JTAGEN = OFF // Disable JTAG
#pragma config FSOSCEN = OFF // Disable Secondary Oscillator
float valor=0;
int k=0, i;
// Defines
#define SYSCLK 40000000L // System Clock Frequency
// Macros
#define setPR2(seconds) (seconds * SYSCLK / 256)
TMR1 = 0;
while( TMR1 < SYSCLK/100000000);
}
// Configure Interrupts
// In datasheet: TABLE 7-1: INTERRUPT IRQ, VECTOR AND BIT LOCATION
IEC0CLR = 0x0200; // disable Timer2 int, IEC0<9>
IFS0CLR = 0x0200; // clear Timer2 int flag, IFS0<9>
IPC2CLR = 0x001f; // clear Timer2 priority/subpriority fields IPC2<4:0>
IPC2SET = 0x0010; // set Timer2 int priority = 4, IPC2<4:2>
IPC2SET = 0x0000; // set Timer2 int subpriority = 0, IPC2<1:0>
IEC0SET = 0x0200; // enable Timer2 int, IEC0<9>
// Now we just wait in an infinite loop while interrupts do their thing!
while( 1){
if (PORTBbits.RB2==1){
a=0;
if(PORTBbits.RB4==1){
LATBbits.LATB5=0;
LATBbits.LATB3=0;
} if(PORTBbits.RB4==0){
LATBbits.LATB3=1;
LATBbits.LATB5=0;
}
}else{
if(desbord==1){
delay_us(1);
LATBINV = 0x0008;
desbord=0;}
}};
}
if(a<puls){
if(desbord==0){
desbord=1;
}p
// note that iplx (interrupt priority level) must match the timers interrupt
priority level
LATBINV = 0x0020;
}else{desbord=0;
LATBbits.LATB5=0;
LATBbits.LATB3=0;
}} else{a=0; puls=leeADC(3)*16384/1023;//an3
if(PORTBbits.RB4==1){
LATBbits.LATB5=0;
LATBbits.LATB3=0;
} if(PORTBbits.RB4==0){
LATBbits.LATB3=1;
LATBbits.LATB5=0;
}
}