Autor Tema: Interrupcion Externa B0  (Leído 3423 veces)

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

Desconectado andpic

  • PIC10
  • *
  • Mensajes: 30
Interrupcion Externa B0
« en: 26 de Febrero de 2005, 06:19:00 »
Hola amigos, tengo un pic16f819, el cual no tiene uart, lo que me impide usar las interrupciones internas del puerto serie. No me queda otra que recurrir a la interrupcion externa por b0. La pregunta es: Alguien tiene alguna rutinita de ejemplo de como se utiliza esta interrupcion?? Alguien que la alla usado, me podria dar una mano??

Gracias

Desconectado Nocturno

  • Administrador
  • DsPIC33
  • *******
  • Mensajes: 18286
    • MicroPIC
RE: Interrupcion Externa B0
« Respuesta #1 en: 27 de Febrero de 2005, 00:50:00 »
¿En qué lenguaje lo necesitas?

Desconectado andpic

  • PIC10
  • *
  • Mensajes: 30
RE: Interrupcion Externa B0
« Respuesta #2 en: 28 de Febrero de 2005, 10:55:00 »
en C.

Saludos

Gracias

Desconectado Nocturno

  • Administrador
  • DsPIC33
  • *******
  • Mensajes: 18286
    • MicroPIC
RE: Interrupcion Externa B0
« Respuesta #3 en: 28 de Febrero de 2005, 11:15:00 »
En CCS se hace así:
Codigo:
  enable_interrupts(INT_EXT);
   ext_int_edge(L_TO_H);

Con esto activas la interrupción en cada flanco de subida de la entrada (si pones H_TO_L la activas en cada flanco de bajada).

Sólo te falta poner la sentencia #INT_EXT antes de la función que quieres ejecutar y punto.

Desconectado fenix_jn

  • PIC18
  • ****
  • Mensajes: 418
RE: Interrupcion Externa B0
« Respuesta #4 en: 28 de Febrero de 2005, 14:48:00 »
Claro despues de poner la instruccion deberas crear la rutina para recibir en serial como si fuera ella la rutina de servicio para interrupciones.

Desconectado Falconhunter

  • PIC12
  • **
  • Mensajes: 60
RE: Interrupcion Externa B0
« Respuesta #5 en: 28 de Febrero de 2005, 17:19:00 »
Tambien estoy ahora con un 16F819 programando en C con el PICC y en el wizard se me planteaba la opcion de usar una uart. Lo que no se si es que se creaban rutinas para llegar y usar. Creo que por ahi van los tiros. Corregidme si me equivoco....

Desconectado Falconhunter

  • PIC12
  • **
  • Mensajes: 60
RE: Interrupcion Externa B0
« Respuesta #6 en: 28 de Febrero de 2005, 17:26:00 »
Acabo de mirar lo del PIC C y si que añade codigo. En el archivo header se añade la siguiente linea:

#use rs232(baud=9600,parity=N,xmit=PIN_B0,rcv=PIN_B1,bits=9)

donde se configura el tipo de comunicacion y los pines. Lo unico es que creo que no se puede tratar como interrupcion. Esto ultimo no lo he probado.

Un saludo

Desconectado fenix_jn

  • PIC18
  • ****
  • Mensajes: 418
RE: Interrupcion Externa B0
« Respuesta #7 en: 28 de Febrero de 2005, 18:03:00 »
No estoy seguro pero creo q eso agrega las rutinas para el uso del RS232 en el programa, la idea seria usar INT como entrada de datos y al ejecutarse esta interrupcion usar getc() para leer el byte en el puerto correspondiente, asi ya tendria capacidad para recibir datos usando interrupciones.

Desconectado Nocturno

  • Administrador
  • DsPIC33
  • *******
  • Mensajes: 18286
    • MicroPIC
RE: Interrupcion Externa B0
« Respuesta #8 en: 01 de Marzo de 2005, 00:40:00 »
Un momento, un momento. Si lo que queréis es usar la interrupción externa para recibir datos sin usar la usart perfecto; pero si lo que queréis es leer el puerto serie con interrupciones no es ese el mejor camino.

Hay una interrupción que se lanza cada vez que el micro ha recibido un carácter vía usart y lo tiene disponible para su lectura. Esta interrupción se llama #INT_RDA

Fijáos cómo la utiliza este ejemplo de CCS:
Codigo:
/////////////////////////////////////////////////////////////////////////
////                          EX_SISR.C                              ////
////                                                                 ////
////  This program shows how to implement an interrupt service       ////
////  routine to buffer up incomming serial data.                    ////
////                                                                 ////
////  If the PIC does not have an RDA interrupt pin, B0 may be used  ////
////  with the INT_EXT.                                              ////
////                                                                 ////
////  Configure the CCS prototype card as described below.           ////
////                                                                 ////
////  This example will work with the PCM and PCH compilers.  The    ////
////  following conditional compilation lines are used to include a  ////
////  valid device for each compiler.  Change the device, clock and  ////
////  RS232 pins for your hardware if needed.                        ////
/////////////////////////////////////////////////////////////////////////
////        (C) Copyright 1996,2003 Custom Computer Services         ////
//// This source code may only be used by licensed users of the CCS  ////
//// C compiler.  This source code may only be distributed to other  ////
//// licensed users of the CCS C compiler.  No other use,            ////
//// reproduction or distribution is permitted without written       ////
//// permission.  Derivative programs created using this software    ////
//// in object code form are not restricted in any way.              ////
/////////////////////////////////////////////////////////////////////////


#if defined(__PCM__)
#include <16F877.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)  // Jumpers: 8 to 11, 7 to 12

#elif defined(__PCH__)
#include <18F452.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)  // Jumpers: 8 to 11, 7 to 12
#endif


#define BUFFER_SIZE 32
BYTE buffer[BUFFER_SIZE];
BYTE next_in = 0;
BYTE next_out = 0;


#int_rda
void serial_isr() {
   int t;

   buffer[next_in]=getc();
   t=next_in;
   next_in=(next_in+1) % BUFFER_SIZE;
   if(next_in==next_out)
     next_in=t;           // Buffer full !!
}

#define bkbhit (next_in!=next_out)

BYTE bgetc() {
   BYTE c;

   while(!bkbhit) ;
   c=buffer[next_out];
   next_out=(next_out+1) % BUFFER_SIZE;
   return(c);
}



void main() {

   enable_interrupts(global);
   enable_interrupts(int_rda);

   printf("
Running...
");

               // The program will delay for 10 seconds and then display
               // any data that came in during the 10 second delay

   do {
      delay_ms(10000);
      printf("
Buffered data => ");
      while(bkbhit)
        putc( bgetc() );
   } while (TRUE);
}


Desconectado andpic

  • PIC10
  • *
  • Mensajes: 30
RE: Interrupcion Externa B0
« Respuesta #9 en: 01 de Marzo de 2005, 10:22:00 »
Amigos...Gracias por sus respuestas. Ya encontre la solucion a mi problema, la cual se las dejo despues de explicarle porque tuve que hacerlo asi. El pic con el que estoy trabajando es el 16F819, el cual no puedo usar las interrupciones internas al puerto serie, (que era lo que queria), por la sencilla razon de que este pic no maneja interrupciones internas al puerto seria, no posee usart. Por lo que para poder usar una interrupcion cuando ingresa un dato por el puerto serie, no queda otra que hacerlo con una interrupcion externa. Lo que hice fue puentear la rx del pic a RB0, poner RB0 como entrada y listo. Prueben con este ejemplo del CCs que a mi me anduvo de maravilla. Desde Mendoza, Argentina..Gracias Totales. Cualquier duda pregunten
/////////////////////////////////////////////////////////////////////////
////                          EX_WAKUP.C                             ////
////                                                                 ////
////  This example shows how to use the sleep function.  When the    ////
////  button is pushed, the processor goes into sleep mode.  When    ////
////  the button is released, the processor wakes up and continues   ////
////  counting.                                                      ////
////                                                                 ////
////  Configure the CCS prototype card as follows:                   ////
////     Jumper from pin 40 to 47.                                   ////
////     See additional connections below.                           ////
////                                                                 ////
////  This example will work with the PCM and PCH compilers.  The    ////
////  following conditional compilation lines are used to include a  ////
////  valid device for each compiler.  Change the device, clock and  ////
////  RS232 pins for your hardware if needed.                        ////
/////////////////////////////////////////////////////////////////////////
////        (C) Copyright 1996,2003 Custom Computer Services         ////
//// This source code may only be used by licensed users of the CCS  ////
//// C compiler.  This source code may only be distributed to other  ////
//// licensed users of the CCS C compiler.  No other use,            ////
//// reproduction or distribution is permitted without written       ////
//// permission.  Derivative programs created using this software    ////
//// in object code form are not restricted in any way.              ////
/////////////////////////////////////////////////////////////////////////


#if defined(__PCM__)
#include <16F877.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)  // Jumpers: 8 to 11, 7 to 12

#elif defined(__PCH__)
#include <18F452.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)  // Jumpers: 8 to 11, 7 to 12
#endif

// global flag to send processor into sleep mode
short sleep_mode;

// external interrupt when button pushed and released
#INT_EXT
void ext_isr() {
static short button_pressed=FALSE;

   if(!button_pressed)        // if button action and was not pressed
   {
      button_pressed=TRUE;    // the button is now down
      sleep_mode=TRUE;        // activate sleep
      printf("The processor is now sleeping.
"Giño;
      ext_int_edge(L_TO_H);   // change so interrupts on release
   }
   else                       // if button action and was pressed
   {
      button_pressed=FALSE;   // the button is now up
      sleep_mode=FALSE;       // reset sleep flag
      ext_int_edge(H_TO_L);   // change so interrupts on press
   }
   if(!input(PIN_B0))         // keep button action sychronized wth button flag
      button_pressed=TRUE;
   delay_ms(100);             // debounce button
}

// main program that increments counter every second unless sleeping
void main()   {
   long counter;

   sleep_mode=FALSE;          // init sleep flag

   ext_int_edge(H_TO_L);      // init interrupt triggering for button press
   enable_interrupts(INT_EXT);// turn on interrupts
   enable_interrupts(GLOBAL);

   printf("

"Giño;

   counter=0;                 // reset the counter
   while(TRUE)
   {
      if(sleep_mode)          // if sleep flag set
         sleep();             // make processor sleep
      printf("The count value is:  %5ld    
",counter);
      counter++;              // display count value and increment
      delay_ms(1000);         // every second
   }
}


 

anything