Estoy haciendo un código que es bastante sencillo, para probar la comunicación serial del PIC 16F1827 con interrupciones
Antes de explicar el problema, este es el esquema:
El código para el PIC de arriba:
El código del PIC de abajo:
Una explicación rápida del funcionamiento:
Para ambos PIC funciona bien tanto el led ROJO (sin interrupciones) y el led correspondiente a la activación de la interrupción externa. El problema es que o bien el PIC 2 no envía o el PIC 1 no recibe o ninguno de los dos hace nada
Antes de explicar el problema, este es el esquema:

El código para el PIC de arriba:
Código:
#include <16f1827.h>
#fuses XT,NOWDT,NOPROTECT,PUT,NOLVP //ordenes para el programador
#use delay (clock=32M) // Fosc=32Mhz
#use RS232(BAUD=9600, XMIT=PIN_B2, RCV=PIN_B1, stream=com,errors)
#define NO_INTERRUPCION PIN_B3
#define SERIAL PIN_B4
#define EXTERNO PIN_B5
int FLAG_EXT=0;
#INT_EXT
void ext_int(){
disable_interrupts(GLOBAL);
FLAG_EXT=1;
enable_interrupts(GLOBAL);
}
int FLAG_SERIAL=0;
#int_RDA
void RDA_isr(void){
disable_interrupts(GLOBAL);
FLAG_SERIAL=1;
enable_interrupts(GLOBAL);
}
void main(void){
int ce;
int cs;
RESTART_WDT();
enable_interrupts(int_ext);
enable_interrupts(int_rda);
ext_int_edge(L_TO_H);
enable_interrupts(GLOBAL);
while(TRUE){
if(FLAG_SERIAL==1){
output_low (NO_INTERRUPCION);
output_low (EXTERNO);
output_high (SERIAL);
delay_ms(1000);
output_low (SERIAL);
FLAG_SERIAL=0;
cs++;
}
else if(FLAG_EXT==1){
output_low (NO_INTERRUPCION);
output_low (SERIAL);
FLAG_EXT=0;
output_high (EXTERNO);
delay_ms(1000);
output_low (EXTERNO);
ce++;
}
else if(FLAG_SERIAL==0 && FLAG_EXT==0){
output_high (NO_INTERRUPCION);
output_low (EXTERNO);
output_low (SERIAL);
}
}
}
El código del PIC de abajo:
Código:
#include <16f1827.h>
#fuses XT,NOWDT,NOPROTECT,PUT,NOLVP //ordenes para el programador
#use delay (clock=32M) // Fosc=32Mhz
#use RS232(BAUD=9600, XMIT=PIN_B2, RCV=PIN_B1, stream=com,errors)
#define NO_INTERRUPCION PIN_B3
#define SERIAL PIN_B4
int FLAG_EXT=0;
#INT_EXT
void intrb0()
{
FLAG_EXT=1;
}
void main(void)
{
int c;
RESTART_WDT();
enable_interrupts(int_ext);
ext_int_edge(L_TO_H);
enable_interrupts(GLOBAL);
output_low (NO_INTERRUPCION);
output_low (SERIAL);
port_b_pullups(0b00000110);
while(TRUE){
if(FLAG_EXT==1){
output_low (NO_INTERRUPCION);
FLAG_EXT=0;
char x="HOLA";
putc(x,com);
output_high (SERIAL);
delay_ms(1000);
output_low (SERIAL);
c++;
}
do{
output_high (NO_INTERRUPCION);
}while(FLAG_EXT==0);
}
}
Una explicación rápida del funcionamiento:
- PIC 1:
Si no está activa ninguna interrupción, el led ROJO está encendido. Si se activa la interrupción externa (por interruptor), se enciende el led VERDE. Si se activa la interrupción por comunicación serial (por el otro PIC) se enciende el led AZUL - PIC 2:
Si no está activa la interrupción, el led ROJO está encendido. Si se activa la interrupción externa (por interruptor), se enciende el led AZUL y se envía un número por puerto serial al otro PIC
Para ambos PIC funciona bien tanto el led ROJO (sin interrupciones) y el led correspondiente a la activación de la interrupción externa. El problema es que o bien el PIC 2 no envía o el PIC 1 no recibe o ninguno de los dos hace nada