Autor Tema: problema interrupcion externa con CCS  (Leído 1333 veces)

0 Usuarios y 1 Visitante están viendo este tema.

Desconectado FAGUIRRE1315

  • PIC10
  • *
  • Mensajes: 1
problema interrupcion externa con CCS
« en: 27 de Septiembre de 2013, 11:08:33 »
buen dia, quisiera saber si por favor me pueden colaborar con un problema que tengo con las interrupciones en pic, es que quiero que el programa me genere la rutina del conversor adc pero no he podido y pues no tengo muy claro para que son las interrupciones

#include <18F4550.h>
#device adc=10
#include <math.h>
#FUSES NOWDT                    //No Watch Dog Timer
#FUSES WDT128                   //Watch Dog Timer uses 1:128 Postscale
#FUSES PLL1                     //No PLL PreScaler
#FUSES CPUDIV1                  //No System Clock Postscaler
#FUSES NOUSBDIV                 //USB clock source comes from primary oscillator
#FUSES INTRC_IO                 //Internal Clock, EC used by USB, I/O on RA6
#FUSES NOFCMEN                  //Fail-safe clock monitor disabled
#FUSES NOIESO                   //Internal External SWITCH Over mode disabled
#FUSES NOBROWNOUT               //No brownout reset
#FUSES NOVREGEN                 //USB voltage regulator disabled
#FUSES NOPBADEN                 //PORTB pins are configured as digital I/O on RESET
#FUSES NOLPT1OSC                //Timer1 configured FOR higher power operation
#FUSES NOSTVREN                 //Stack full/underflow will not cause reset
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used FOR I/O
#FUSES NOXINST                  //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#use DELAY(clock=8M)             //frecuencia del oscilador en Hz
#use standard_io (b)
#BYTE PORTB= 0XF81
#BYTE TRISB= 0XF93


INT FLAG_INT_EXT=0;
 #INT_EXT



 void EXT_isr(){
 
 FLAG_INT_EXT=1;
   
  }
   
 
 
   VOID main ()
   {
   
     int16 valor, cero;
     
         
 //CONFIGURACION INTERRUPCIONES
 
 TRISB= 0B00000001;
 ENABLE_INTERRUPTS(GLOBAL);
 ENABLE_INTERRUPTS(INT_EXT);
 EXT_INT_EDGE(h_TO_l);
 
 
  //CONFIGURACION COONVERSOR
      setup_adc_ports (ALL_ANALOG);
      setup_adc (ADC_CLOCK_INTERNAL);
      set_adc_channel (0);   
     
      //CONFIGURACION PWM
      //T = [ (PR2 + 1) * 4] * Tosc * Prescaler TMR2
      //T = [ (248 + 1) * 4] * 0, 00000025 * 16
      setup_ccp1 (ccp_pwm);
      setup_timer_2 (T2_DIV_BY_16, 199, 1);
      setup_ccp2 (ccp_pwm);
      setup_timer_2 (T2_DIV_BY_16, 199, 1);
     
 
 WHILE(1){
 
 IF (FLAG_INT_EXT==1){
 
 FLAG_INT_EXT=0;
 
 int16 valor1, cero;
 
      valor1 = read_adc ();
      cero=0;
     
      IF (valor1< 512)
   {
      set_pwm2_duty (cero);
      set_pwm1_duty (valor1 - 512) ;
      output_high (pin_b7);
   }

   
   ELSE
   {
     
      set_pwm1_duty (cero);
      set_pwm2_duty (512 - valor1);
      output_low (pin_b7);
   }
 }
     
 
 
 
 }
 
             
       }