Autor Tema: Error de INT_ext y print  (Leído 1858 veces)

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

Desconectado pajaro

  • PIC24H
  • ******
  • Mensajes: 1121
Error de INT_ext y print
« en: 02 de Febrero de 2011, 21:28:42 »
Hola amigos,
Estoy con un problema enfrascado con la int_ext , CCS y proteus.
La cosa es que cuando uso la interrupción y hay algun printf("\r ...");
Se me queja me da un error raro, relacionado con la interupcion a alguien le ha pasado?   :?

Un Saludo.

Desconectado Suky

  • Moderador Local
  • DsPIC33
  • *****
  • Mensajes: 6758
Re: Error de INT_ext y print
« Respuesta #1 en: 02 de Febrero de 2011, 21:47:52 »
Más detalles, que no se entiende. Tienes un printf dentro de la interrupción?  :shock:
No contesto mensajes privados, las consultas en el foro

Desconectado ppyote

  • Colaborador
  • PIC24F
  • *****
  • Mensajes: 929
Re: Error de INT_ext y print
« Respuesta #2 en: 02 de Febrero de 2011, 22:47:20 »
avisos como estos?

>>>Warning 216 "Frontal PC.c" Line 91(0,1): Interrupts disabled during call to prevent re-entrancy:  (@delay_ms1)
>>> Warning 216 "Frontal PC.c" Line 91(0,1): Interrupts disabled during call to prevent re-entrancy:  (lcd_send_nibble)
>>> Warning 216 "Frontal PC.c" Line 91(0,1): Interrupts disabled during call to prevent re-entrancy:  (lcd_send_byte)

si es iguales de los que te da a ti.... lee a continuacion
la funcion printf demora mucho tiempo, en las interrupciones, muchisimas veces es vital que se lleve a cabo lo antes posible y en el mas corto periodo de tiempo, el ccs lo que te avisa es que dentro de esa interrupcion van a haber retrasos de tiempo... que estes alerta.. pero es solo un aviso...
un saludo
PPyote... siempre estareis en mi corazon.... Te quiero Hermano...

Desconectado pajaro

  • PIC24H
  • ******
  • Mensajes: 1121
Re: Error de INT_ext y print
« Respuesta #3 en: 03 de Febrero de 2011, 22:42:47 »
Hola compañeros,

Si es como dice, el amigo ppyote pero cambia  lo del final.
Hay alguna forma de cambiar el codigo o de mejorarlo, para que no haga eso?

pongo el codigo

main .c
Código: C
  1. #include <16F877A.h>
  2. #device adc=8
  3.  
  4. #FUSES NOWDT                    //No Watch Dog Timer
  5. #FUSES HS                       //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
  6. #FUSES NOPUT                    //No Power Up Timer
  7. #FUSES NOPROTECT                //Code not protected from reading
  8. #FUSES NODEBUG                  //No Debug mode for ICD
  9. #FUSES NOBROWNOUT               //No brownout reset
  10. #FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
  11. #FUSES NOCPD                    //No EE protection
  12. #FUSES NOWRT                    //Program memory not write protected
  13. #FUSES RESERVED                 //Used to set the reserved FUSE bits
  14.  
  15. #use delay(clock=20000000)
  16. #use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)
  17. #use i2c(Master,Fast,sda=PIN_C4,scl=PIN_C3)
  18. #include "expan_i2c.c"
  19.  
  20.  
  21.  
  22. #int_EXT
  23. void  EXT_isr(void){
  24. // ----- primer aprueba interrupciones -----
  25.   output_low(PIN_D3);
  26.   output_high(PIN_D2);
  27.   delay_ms(2000);
  28.   output_low(PIN_D2);
  29.   output_high(PIN_D3);
  30. // ----- primer aprueba interrupciones -----
  31.  escanea_tecla();
  32. }
  33.  
  34.  
  35.  
  36. void main()
  37. {
  38. /*
  39.    setup_adc_ports(NO_ANALOGS);
  40.    setup_adc(ADC_CLOCK_DIV_2);
  41.    setup_psp(PSP_DISABLED);
  42.    setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
  43.    setup_timer_1(T1_DISABLED);
  44.    setup_timer_2(T2_DISABLED,0,1);
  45.    setup_comparator(NC_NC_NC_NC);
  46.    setup_vref(FALSE);
  47.  */  
  48.    set_tris_b(0b00000001);
  49.    //port_b_pullups (0b00000001);
  50.  
  51.    output_high(PIN_D3);
  52.    enable_interrupts(INT_EXT);
  53.    enable_interrupts(GLOBAL);
  54.    
  55.    printf("\r hola");  
  56.  
  57.  
  58.    // TODO: USER CODE!!
  59.    //Teclado_ini();
  60.    expan_bus_rw(0b11110000); // configuro puerto
  61.    //expan_bus_rw(0b00001111);
  62.    while(true){
  63.    printf("\r tecla fue: %c",tecla_c(lee_teclado()));
  64.    }
  65.  
  66. }


LA libreria para el tecladoo y el expansor i2c


Código: C
  1. /*////////////////////////////////////////////////////////////////////////////
  2. //   Libreria Teclado Matriz 4x4                       EXPAN_I2C.C         //
  3. //   con expansor I2C    y int_ext                                                //
  4. //   Adaptacion: 01/01/2011                                                        //
  5. ///////////////////////////////////////////////////////////////////////////////
  6.  
  7.  
  8. CHIP - BUS     Resistencias     TECLADO 4x4        IN(1)/OUT(0)
  9. ------------  ----------------  ------------    --------------
  10.     P0 ---------- R 330 -------- Fila 1            0
  11.     P1 ---------- R 330 -------- Fila 2            0
  12.     P2 ---------- R 330 -------- Fila 3            0
  13.     P3 ---------- R 330 -------- Fila 4            0
  14.     P4 -------------------------- Col 1            1
  15.     P5 -------------------------- Col 2            1
  16.     P6 -------------------------- Col 3            1
  17.     P7 -------------------------- Col 4            1
  18.    
  19. /////////////////////////////////////////////////////////////////////////////
  20.  
  21.  
  22. teclado usado
  23.    
  24. CHIP - BUS              PIC
  25. -----------          ---------
  26.                              
  27.    INT -------------  RB0/INT
  28.  
  29. TIPOS DE CHIP BUS          ADDR + A2|A1|A0 + RW/R
  30. ====================
  31. PCF8574                    0100     XXX       0/1
  32. PCF8574A                   0111     XXX       0/1
  33. PCA9554                    0100     XXX       0/1
  34. PCA9554A                   0111     XXX       0/1
  35.  
  36.  
  37. PARA CONFIGURAR:  A0,A1,A2 conectar a masa(0) o a Vcc(1).
  38. EJEMPLO: PCF8574           0100     001        x
  39.          PCF8574A          0111     001        x
  40.  
  41. '===================================================
  42. Teclado_Inicializa
  43. Teclado_DejaDePulsar
  44. Teclado_LeeOrdenTecla
  45. Teclado_LeeHex
  46.  
  47. orden tecla
  48. ============
  49. 0  1  2  3
  50. 4  5  6  7
  51. 8  9  A  B
  52. C  D  E  F
  53.  
  54. teclado hex usado
  55. ==================
  56. 1  2  3  F
  57. 4  5  6  E
  58. 7  8  9  D
  59. A  0  B  C
  60.  
  61.  
  62.  
  63. === DEFINICIONES ===
  64.  
  65.    P_BUS          //COMFIGURA PUERTO DEL EXPANSOR BUS I2C
  66.    ADDR_EXPAN     //DIRECCION DEL ESCLAVO DEL EXPANSIONADOR DEL BUS I2C
  67.    M_BUS_R        //MODO LECTURA DEL BUS
  68.    M_BUS_RW       //MODO ESCRITURA DEL BUS
  69.  
  70. ///////////////////////////////////////////////////////////////////////////*/
  71.  
  72. #DEFINE P_BUS 0b11110000
  73. //#DEFINE ADDR_EXPAN   0b011101
  74. #DEFINE M_BUS_R      0b01110011   //0x73
  75. #DEFINE M_BUS_RW     0b01110010   //0x72
  76.  
  77. int8 expan_bus_r(){
  78.       int8 dato;
  79.       i2c_start();                 // inicia bus i2c
  80.       i2c_write(M_BUS_R);          // direccion dispositivo esclavo + lectura
  81.       dato = i2c_read();           // lee del bus i2c el dato
  82.       i2c_stop();                  // Stop condition
  83.       //printf("\r LEE bus");        // add debug
  84.       //printf("\r Dato: %d",dato);  // add debug
  85.       return dato;                 // retorna dato
  86. }
  87.  
  88. void expan_bus_rw(int8 dato){
  89.       i2c_start();                 // inicia bus i2c
  90.       i2c_write(M_BUS_RW);         // direccion dispositivo esclavo + escritura
  91.       i2c_write(dato);             // escribe en bus i2c el dato
  92.       i2c_stop();                  // para bus i2c
  93.       //printf("\r Se EJECUTO PCF8574_RW ");//add debug
  94. }
  95.  
  96. int8 escanea_tecla(void){
  97.    //printf("\r Escanea tecla() ");
  98.    int8 f,c;
  99.    signed int8 dato=-1;   // da -1 si no se pulso tecla
  100.    int8 fila=0b11111110;  // primera fila
  101.    
  102.    //printf("\r fila: %d",fila);//add
  103.  
  104.  
  105.    for (f=0; f<=3; f++)  // Recorre las 4 filas
  106.    {
  107.       //printf("\r fila for: %d",fila);//add
  108.       expan_bus_rw(fila);
  109.       rotate_left(&fila, 1);  // siguientes filas, va desplazando el 0 hacia la izquierda
  110.       //fila = fila >> 1;
  111.       //printf("\r rota fila: %d",fila);//add
  112.       delay_ms(20); // necesario antes de leer 20
  113.       dato=expan_bus_r();
  114.       c=0;
  115.            if (!bit_test(dato,4)) c=1;     //Col 1  4
  116.       else if (!bit_test(dato,5)) c=2;     //Col 2  5
  117.       else if (!bit_test(dato,6)) c=3;     //Col 3  6
  118.       else if (!bit_test(dato,7)) c=4;     //Col 4  7
  119.       if(c) break;     // Si c es distinto de 0 sale del for
  120.    }
  121.  
  122.  
  123.    if(c){
  124.       //printf("\r f:%d  c:%d  dato: %d",f,c,dato);   //add debug
  125.       dato=(f*4)+c;
  126.       }
  127.    else{
  128.       dato=-1;       //Ninguna tecla pulsada
  129.       expan_bus_rw(P_BUS);  //Vuelve a poner las lineas como salida (0) y
  130.                             //como entrada (1) las Columnas
  131.                                  
  132.      //expan_bus_rw(0b00001111);  //add debug change                            
  133.      //printf("\r Se reinicio el PCF"); //add debug
  134.      //printf("\r dato: %d",dato); //add debug
  135.    }
  136.    return dato;
  137.  
  138. }
  139. //converion de teclado hex a nuestro teclado
  140. char tecla_c(int8 codigo)
  141. {
  142.    char tabla_tecla[17]={'1','2','3','F','4','5','6','E','7','8','9','D','A','0','B','C','Z'};
  143.    return tabla_tecla[codigo-1];
  144. }
  145.  
  146. int8 lee_teclado(void)
  147. {
  148. printf("\r Lee teclado");
  149.    int8 tecla_hex;
  150.    tecla_hex=escanea_tecla();
  151.    return tecla_hex;
  152. }
  153.  
  154. void Teclado_ini(void){
  155.    //port_b_pullups (0b00000001);    // Activa la resitencia pull-up interna del pin RB0/INT
  156.  
  157.    ext_int_edge( H_TO_L );         // La int. se activara por flanco de bajada
  158.    expan_bus_rw(0b11110000);       // Pone como salida (0) las Lineas  y como entrada (1) las Columnas
  159.    //PCF8574_Escribe(0b00001111);  //add cambio puerto
  160.    delay_ms(50);
  161.    //printf("\r\n SE inicializo el teclado");
  162. }




Desconectado ppyote

  • Colaborador
  • PIC24F
  • *****
  • Mensajes: 929
Re: Error de INT_ext y print
« Respuesta #4 en: 03 de Febrero de 2011, 23:30:36 »
elimina la linea delay_ms(2000); de la interrupcion
lo mejor para hacer lo que deseas hacer es habilitar un timer y que a traves de un flag habilitado desde la int_ext y una variable, hagan esperar al pin d2 y d3 a cambiar de estado...
despues cuando lo hayan echo... retornas el valor del flag al valor de reposo...

ejemplo....

int flag=0x00;
int cuenta=0x00;

#int_ext
void EXT_isr(void)
{
    flag=0xFF
}

#int_timer1
void TIMER!_isr(void)
{
     if(flag==0xFF){
        ++cuenta;
        output_low(PIN_D3);
        output_high(PIN_D2);
     }
     if(cuenta==0x03){
          cuenta=0x00;
          flag=0x00;
          output_low(PIN_D2);
          output_high(PIN_D3);
     }
}   
     
PPyote... siempre estareis en mi corazon.... Te quiero Hermano...

Desconectado MLO__

  • Colaborador
  • DsPIC33
  • *****
  • Mensajes: 4581
Re: Error de INT_ext y print
« Respuesta #5 en: 04 de Febrero de 2011, 23:08:26 »
Hola.

Si necesitas el antirrebotes, puedes "engañar" al compilador con un delay_us dentro de un for. De esa manera te evitas los warnings  :mrgreen:

Saludos
El papel lo aguanta todo