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.
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);
}