Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #if defined(__dsPIC33F__)
- #include "p33Fxxxx.h"
- #elif defined(__PIC24H__)
- #include "p24Hxxxx.h"
- #endif
- // Select Internal FRC at POR
- _FOSCSEL(FNOSC_FRC);
- // Enable Clock Switching and Configure
- _FOSC(FCKSM_CSECMD & OSCIOFNC_OFF); // FRC + PLL
- //_FOSC(FCKSM_CSECMD & OSCIOFNC_OFF & POSCMD_XT);
- // XT + PLL
- _FWDT(FWDTEN_OFF);
- // Watchdog Timer Enabled/disabled by user software
- int activ=0;
- void __attribute__ ((interrupt, no_auto_psv)) _INT2Interrupt(void)
- {
- activ = 1;
- IFS1bits.INT2IF = 0;
- // Resetam flagul corespunzator intreruperii
- // INT0 pentru a nu se reapela rutina de intrerupere
- }
- void delay()
- {
- int i;
- for(i = 0; i<200; i++);
- }
- void initPLL(void)
- {
- // Configure PLL prescaler, PLL postscaler, PLL divisor
- PLLFBD = 41;
- // M = 43 FRC
- //PLLFBD = 30; // M = 32 XT
- CLKDIVbits.PLLPOST=0;
- // N1 = 2
- CLKDIVbits.PLLPRE=0;
- // N2 = 2
- // Initiate Clock Switch to Internal FRC with PLL (NOSC = 0b001)
- __builtin_write_OSCCONH(0x01);
- // FRC
- //__builtin_write_OSCCONH(0x03); // XT
- __builtin_write_OSCCONL(0x01);
- // Wait for Clock switch to occur
- while (OSCCONbits.COSC != 0b001);
- // FRC
- //while (OSCCONbits.COSC != 0b011); // XT
- // Wait for PLL to lock
- while(OSCCONbits.LOCK!=1) {};
- }
- int main(void)
- {
- RCONbits.SWDTEN = 0;
- initPLL();
- TRISB = 0x00FF;
- LATB = 0x0E000;
- _RB15=1;
- _RB14=1;
- _RB13=0;
- _RB12=0;
- RPINR1=0x0007;
- IFS1bits.INT2IF = 0;
- // Resetem flagul coresp. intreruperii INT0
- IEC1bits.INT2IE = 1;
- // Se permite lucrul cu întreruperea INT0
- INTCON2 = 0x0004;
- // Se stabileĹźte pe ce front se genereazÄ INT0
- delay();
- while(1)
- {
- if(activ)
- {
- if(_RB14 ==1)
- {
- _RB14=0;
- }
- else
- {
- _RB14=1;
- }
- if(_RB11 ==1)
- {
- _RB11=0;
- }
- else
- {
- _RB11=1;
- }
- delay();
- activ=0;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement