Advertisement
Adytzu04

pns lab int2

Apr 1st, 2014
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.76 KB | None | 0 0
  1. #if defined(__dsPIC33F__)
  2. #include "p33Fxxxx.h"
  3. #elif defined(__PIC24H__)
  4. #include "p24Hxxxx.h"
  5. #endif
  6. // Select Internal FRC at POR
  7. _FOSCSEL(FNOSC_FRC);
  8. // Enable Clock Switching and Configure
  9. _FOSC(FCKSM_CSECMD & OSCIOFNC_OFF); // FRC + PLL
  10. //_FOSC(FCKSM_CSECMD & OSCIOFNC_OFF & POSCMD_XT);
  11. // XT + PLL
  12. _FWDT(FWDTEN_OFF);
  13. // Watchdog Timer Enabled/disabled by user software
  14. int activ=0;
  15. void __attribute__ ((interrupt, no_auto_psv)) _INT2Interrupt(void)
  16. {
  17. activ = 1;
  18. IFS1bits.INT2IF = 0;
  19. // Resetam flagul corespunzator intreruperii
  20. // INT0 pentru a nu se reapela rutina de intrerupere
  21. }
  22.  void delay()
  23. {
  24.     int i;
  25.     for(i = 0; i<200; i++);
  26. }
  27. void initPLL(void)
  28. {
  29. // Configure PLL prescaler, PLL postscaler, PLL divisor
  30. PLLFBD = 41;
  31. // M = 43 FRC
  32. //PLLFBD = 30; // M = 32 XT
  33. CLKDIVbits.PLLPOST=0;
  34. // N1 = 2
  35. CLKDIVbits.PLLPRE=0;
  36. // N2 = 2
  37. // Initiate Clock Switch to Internal FRC with PLL (NOSC = 0b001)
  38. __builtin_write_OSCCONH(0x01);
  39. // FRC
  40. //__builtin_write_OSCCONH(0x03); // XT
  41. __builtin_write_OSCCONL(0x01);
  42. // Wait for Clock switch to occur
  43. while (OSCCONbits.COSC != 0b001);
  44. // FRC
  45. //while (OSCCONbits.COSC != 0b011); // XT
  46. // Wait for PLL to lock
  47. while(OSCCONbits.LOCK!=1) {};
  48. }
  49. int main(void)
  50. {
  51. RCONbits.SWDTEN = 0;
  52. initPLL();
  53. TRISB = 0x00FF;
  54. LATB = 0x0E000;
  55.  
  56. _RB15=1;
  57. _RB14=1;
  58. _RB13=0;
  59. _RB12=0;
  60.  
  61. RPINR1=0x0007;
  62.  
  63.  
  64. IFS1bits.INT2IF = 0;
  65. // Resetem flagul coresp. intreruperii INT0
  66. IEC1bits.INT2IE = 1;
  67. // Se permite lucrul cu întreruperea INT0
  68. INTCON2 = 0x0004;
  69. // Se stabileşte pe ce front se generează INT0
  70. delay();
  71.  
  72. while(1)
  73. {
  74.     if(activ)
  75.     {
  76.         if(_RB14 ==1)
  77.         {
  78.             _RB14=0;
  79.         }
  80.         else
  81.         {
  82.             _RB14=1;
  83.         }
  84.  
  85.         if(_RB11 ==1)
  86.         {
  87.             _RB11=0;
  88.         }
  89.         else
  90.         {
  91.             _RB11=1;
  92.         }
  93.         delay();
  94.         activ=0;
  95.     }
  96. }
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement