Advertisement
Guest User

Untitled

a guest
Aug 18th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.92 KB | None | 0 0
  1.  
  2. #include <p18f2550.h>
  3. #include <timers.h>
  4.  
  5.  
  6.  
  7. /** CONFIGURATION **************************************************/
  8.    
  9.     #pragma config PLLDIV   = 1         // (20 MHz crystal on PICDEM FS USB board)
  10.     #pragma config CPUDIV   = OSC1_PLL2  
  11.     #pragma config USBDIV   = 1       // Clock source from 96MHz PLL/2
  12.     #pragma config FOSC     = HSPLL_HS
  13.     #pragma config FCMEN    = OFF
  14.     #pragma config IESO     = OFF
  15.     #pragma config PWRT     = OFF
  16.     #pragma config BOR      = ON
  17.     #pragma config BORV     = 3
  18.     #pragma config VREGEN   = ON      //USB Voltage Regulator
  19.     #pragma config WDT      = OFF
  20.     #pragma config WDTPS    = 32768
  21.     #pragma config MCLRE    = OFF
  22.     #pragma config LPT1OSC  = OFF
  23.     #pragma config PBADEN   = OFF
  24.     //      #pragma config CCP2MX   = ON
  25.     #pragma config STVREN   = ON
  26.     #pragma config LVP      = OFF
  27.     //      #pragma config ICPRT    = OFF       // Dedicated In-Circuit Debug/Programming
  28.     #pragma config XINST    = OFF       // Extended Instruction Set
  29.     #pragma config CP0      = OFF
  30.     #pragma config CP1      = OFF
  31.     //      #pragma config CP2      = OFF
  32.     //      #pragma config CP3      = OFF
  33.     #pragma config CPB      = OFF
  34.     //      #pragma config CPD      = OFF
  35.     #pragma config WRT0     = OFF
  36.     #pragma config WRT1     = OFF
  37.     //      #pragma config WRT2     = OFF
  38.     //      #pragma config WRT3     = OFF
  39.     #pragma config WRTB     = OFF       // Boot Block Write Protection
  40.     #pragma config WRTC     = OFF
  41.     //      #pragma config WRTD     = OFF
  42.     #pragma config EBTR0    = OFF
  43.     #pragma config EBTR1    = OFF
  44.     //      #pragma config EBTR2    = OFF
  45.     //      #pragma config EBTR3    = OFF
  46.     #pragma config EBTRB    = OFF
  47.  
  48. int a;
  49.  
  50.  
  51. /*############### V E C T O R  R E M A P P I N G #####################*/
  52. #pragma code
  53.        
  54. //These are your actual interrupt handling routines.
  55. #pragma interrupt HighPriorityISRCode
  56. void HighPriorityISRCode()
  57. {
  58.     // check here for High Priority interrupts (PIR1bits, INTCON, etc)
  59.     if(a==0)
  60.     {
  61.         a = 1 ;
  62.         PORTB = 0xff;
  63.     }
  64.     else
  65.     {
  66.         a = 0;
  67.         PORTB = 0x00;
  68.     }
  69.     WriteTimer0(61629);
  70.     PORTA = a;
  71. }
  72.  
  73. #pragma interruptlow LowPriorityISRCode
  74. void LowPriorityISRCode()
  75. {  
  76. }
  77.  
  78. #pragma code HIGH_INTERRUPT_VECTOR = 0x08
  79. void Remapped_High_ISR (void)
  80. {
  81.      _asm goto HighPriorityISRCode _endasm
  82. }
  83. #pragma code LOW_INTERRUPT_VECTOR = 0x18
  84. void Remapped_Low_ISR (void)
  85. {
  86.          _asm goto LowPriorityISRCode _endasm
  87. }
  88.  
  89. /*#D E C L A R A T I O N S ###################################*/
  90.  
  91. #pragma code
  92.  
  93. void main(void)
  94. {
  95.     ADCON1=0x0F;//Todos entrada/salida digitales.
  96.     TRISA=0x00; //Todos como salida.
  97.  
  98.     TRISB=0X00;
  99.     //Todos como salida.
  100.     PORTB=0x00; //Leds apagados.
  101.  
  102.     a=0;
  103.  
  104.     INTCONbits.PEIE=1;      // Habilitamos interrupcion de perifericos.
  105.     INTCONbits.GIE=1;       // Habilitamos interrupcion Global.
  106.  
  107.     // Timer0, PS: 1:256, 16 bit, INTSRC, INT ON
  108.     OpenTimer0(TIMER_INT_ON & T0_16BIT & T0_SOURCE_INT & T0_PS_1_256);
  109.     WriteTimer0(61629);
  110.  
  111.     while(1);
  112.  
  113. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement