Advertisement
hidromotic

config_pic18f46k20.c

May 3rd, 2020
928
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.58 KB | None | 0 0
  1. /*
  2.  * File:   config.c
  3.  * Author: Alejo S. Giles
  4.  *
  5.  * Created on 3 de mayo de 2020, 21:17
  6.  *
  7.  * UNLPam - Fac. Ing - Computación II
  8.  *
  9.  * PIC18F46K20
  10.  *
  11.  * Compilador XC8 - Standard C 90
  12.  *
  13.  * Seleccionar Estandard C = C90 en las propiedades del proyecto:
  14.  * Files --> Projecto Properties --> XC8 Global Options --> C standard = C 90
  15.  */
  16.  
  17. #include "config.h"
  18.  
  19. unsigned long centiseg=0;   //Para el control de tiempos
  20.  
  21. void recargar_timer(void)
  22.     {
  23.     TMR0H = 0x3C;
  24.     TMR0L = 0xB0;
  25.     }
  26.  
  27. void timer0_config(void)
  28.     {
  29.     // Timer0 Registers:
  30.     // Prescaler=1:32; TMR0 Preset=128; Freq=976,5625Hz; Period=1.024,00 µs
  31.     //CONFIGURACION TIMER 0
  32.     T0CONbits.TMR0ON = 1;
  33.     T0CONbits.T08BIT = 0;
  34.     T0CONbits.T0CS   = 0;
  35.     T0CONbits.T0SE   = 0;
  36.     T0CONbits.PSA    = 0;
  37.     T0CONbits.T0PS = 1;
  38.     TMR0H = 0x3C;    
  39.     TMR0L = 0xB0;    
  40.     INTCON = 0;      
  41.     INTCONbits.TMR0IE = 1;        
  42.     INTCONbits.TMR0IF = 0;        
  43.    
  44.     TMR0IE = 1;
  45.     TMR0 = TMR0_PREVALUE; // preset for timer register
  46.     }
  47.  
  48. void setup(void)
  49.     {
  50.     OSCCON = 0b01101100;    //Configuración del oscilador
  51.     ANSEL=0;                //Deshabilitación de canales analógicos
  52.     ANSELH=0;               //Deshabilitación de canales analógicos
  53.    
  54.     timer0_config();
  55.     INTCONbits.GIE = 1;
  56.     }
  57.  
  58. //RUTINA DE INTERRUPCION
  59. void high_priority interrupt High_Priority_Interrupt(void)  //File-->Project Properties-->XC8 Global Options --> C Standard --> C 90
  60.     {
  61.     if (HAY_INTERRUPCION)
  62.         {
  63.         LIMPIAR_BANDERA_INTERRUPCION;
  64.         centiseg++;
  65.         recargar_timer();
  66.         }
  67.     return;
  68.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement