Advertisement
tmax

Untitled

May 28th, 2014
352
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.93 KB | None | 0 0
  1. #define _XTAL_FREQ 4000000
  2.  
  3. #include <pic16f873a.h>
  4. #include <xc.h>
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7.  
  8. void interrupt Interrupt_Handlers(void){
  9.     if(INTCONbits.T0IF == 1){
  10.         INTCONbits.T0IF = 0;
  11.     }
  12. }
  13.  
  14. int main(int argc, char** argv) {
  15.  
  16.     INTCONbits.GIE = 1;
  17.     INTCONbits.PEIE = 1;
  18.     INTCONbits.T0IE = 1;
  19.    
  20.     TRISCbits.TRISC2 = 0;
  21.  
  22.     // Modo comparacion
  23.     T1CONbits.T1CKPS = 0b11;        // Preescaler 1:8
  24.     T1CONbits.T1OSCEN = 0;          // No usamos el timer como oscilador
  25.     T1CONbits.TMR1CS = 0;           // Contamos con el clock interno
  26.     T1CONbits.TMR1ON = 1;           // Encendemos el timer
  27.  
  28.     CCP1CONbits.CCP1M = 0b1000;     // CCP1 como comparacion
  29.  
  30.     CCPR1 = 65535;
  31.     TMR1 = 0;
  32.  
  33.     while(1){
  34.         if(PIR1bits.CCP1IF == 1){
  35.             PIR1bits.CCP1IF = 0;
  36.             PORTCbits.RC2 = 0;
  37.             TMR1 = 0;
  38.         }
  39.     }
  40.  
  41.     return (EXIT_SUCCESS);
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement