Hola buenos días;
Tengo un pequeño problemita, a ver si alguna alma generosa me podría ayudar.
Es la primera vez que toco los pics, es para un proyecto con el pic 18f4550, ya he conseguido hacer todo el programa, pero tengo un grave problema, cuando hago un reset externo el programa empieza a funcionar de manera diferente.
Es un programa que se comunica por RS-232, el programa está en un bucle do, guardando información de las entradas, y cuando se introduce un carácter en concreto por el ordenador este tiene que devolver otro carácter con el estado de las entradas, utilizo kbhit para la interrupción int_rda.
Todo funciona perfectamente, se queda en el bucle do hasta que se pulsa la tecla que hace la interrupción, lo que pasa es que cuando se pulsa el reset externo ya deja de funcionar de la misma manera, no se queda en el programa principal haciendo el bucle do. A ver si alguien sabe que está pasando? A lo mejor es que al hacer un reset mclr se cambia alguna bandera? O algún estado interno del PIC? Y hace que funcione diferente? O a lo mejor es el sitio donde activo o desactivo las interrupciones, no se.
A ver si me podéis ayudar! Muchas gracias. (Si se puede mejorar algo también agradecería que me lo dijerais).

Aquí os adjunto el programa:
#include <18F4550.h>
#use delay(clock=20000000)
#use standard_io(b)
#use standard_io(b)
#bit RB0=0XF81.0
#bit RB1=0XF81.1
#bit RB7=0XF81.7
#bit DB0=0XF83.0
#bit DB1=0XF83.1
#bit DB2=0XF83.2
#bit DB3=0XF83.3
#bit DB4=0XF83.4
#bit DB5=0XF83.5
#bit DB6=0XF83.6
#bit DB7=0XF83.7
#byte port_a=0XF80
#byte port_b=0XF81
#byte port_c=0XF82
#byte port_d=0XF83
#byte port_e=0XF84
#use RS232(BAUD=9600,BITS=8,PARITY=N,XMIT=PIN_C6,RCV=PIN_C7)
#fuses XT,NOWDT,PROTECT,NOLVP,PUT,BROWNOUT
#byte tris_a=0XF92
#byte tris_b=0XF93
#byte tris_c=0XF94
#byte tris_d=0XF95
char estado_sensores='0';
char Comando='0';
#int_rda
void serial_isr() {
if(kbhit()){
Comando=getchar();
if(Comando=='z'){
putc(estado_sensores);
}
if(Comando=='!'){
DB0=1;
DB1=0;
}
if(Comando=='"'){
DB0=0;
DB1=1;
}
if(Comando=='#'){
DB1=0;
DB0=0;
}
if(Comando=='%'){
DB2=1;
}
if(Comando=='&'){
DB2=0;
}
if(Comando=='/'){
DB3=1;
}
if(Comando=='('){
DB3=0;
}
disable_interrupts(int_rda);
disable_interrupts(GlOBAL);
}
}
void main(){
tris_a=0XFE;
tris_b=0X00;
tris_c=0X80;
tris_d=0X00;
port_d=0X00;
printf("\r\n\Eperando ordenes (Int)\r\n");
disable_interrupts(int_rda);
disable_interrupts(GlOBAL);
do{
if(!input(PIN_A0)&&!input(PIN_A1)&&!input(PIN_A2)&&!input(PIN_A3)&&!input(PIN_A4)){
estado_sensores='0';
}
else if(input(PIN_A0)&&!input(PIN_A1)&&!input(PIN_A2)&&!input(PIN_A3)&&!input(PIN_A4)){
estado_sensores='1';
}
else if(!input(PIN_A0)&&input(PIN_A1)&&!input(PIN_A2)&&!input(PIN_A3)&&!input(PIN_A4)){
estado_sensores='2';
}
else if(input(PIN_A0)&&input(PIN_A1)&&!input(PIN_A2)&&!input(PIN_A3)&&!input(PIN_A4)){
estado_sensores='3';
}
else if(!input(PIN_A0)&&!input(PIN_A1)&&input(PIN_A2)&&!input(PIN_A3)&&!input(PIN_A4)){
estado_sensores='4';
}
else if(input(PIN_A0)&&!input(PIN_A1)&&input(PIN_A2)&&!input(PIN_A3)&&!input(PIN_A4)){
estado_sensores='5';
}
else if(!input(PIN_A0)&&input(PIN_A1)&&input(PIN_A2)&&!input(PIN_A3)&&!input(PIN_A4)){
estado_sensores='6';
}
else if(input(PIN_A0)&&input(PIN_A1)&&input(PIN_A2)&&!input(PIN_A3)&&!input(PIN_A4)){
estado_sensores='7';
}
else if(!input(PIN_A0)&&!input(PIN_A1)&&!input(PIN_A2)&&input(PIN_A3)&&!input(PIN_A4)){
estado_sensores='8';
}
else if(input(PIN_A0)&&!input(PIN_A1)&&!input(PIN_A2)&&input(PIN_A3)&&!input(PIN_A4)){
estado_sensores='9';
}
else if(!input(PIN_A0)&&input(PIN_A1)&&!input(PIN_A2)&&input(PIN_A3)&&!input(PIN_A4)){
estado_sensores='a';
}
else if(!input(PIN_A0)&&input(PIN_A1)&&!input(PIN_A2)&&input(PIN_A3)&&!input(PIN_A4)){
estado_sensores='b';
}
else if(!input(PIN_A0)&&!input(PIN_A1)&&input(PIN_A2)&&input(PIN_A3)&&!input(PIN_A4)){
estado_sensores='c';
}
else if(input(PIN_A0)&&!input(PIN_A1)&&input(PIN_A2)&&input(PIN_A3)&&!input(PIN_A4)){
estado_sensores='d';
}
else if(!input(PIN_A0)&&input(PIN_A1)&&input(PIN_A2)&&input(PIN_A3)&&!input(PIN_A4)){
estado_sensores='e';
}
else if(input(PIN_A0)&&input(PIN_A1)&&input(PIN_A2)&&input(PIN_A3)&&!input(PIN_A4)){
estado_sensores='f';
}
else if(!input(PIN_A0)&&!input(PIN_A1)&&!input(PIN_A2)&&!input(PIN_A3)&&input(PIN_A4)){
estado_sensores='g';
}
else if(input(PIN_A0)&&!input(PIN_A1)&&!input(PIN_A2)&&!input(PIN_A3)&&input(PIN_A4)){
estado_sensores='h';
}
else if(!input(PIN_A0)&&input(PIN_A1)&&!input(PIN_A2)&&!input(PIN_A3)&&input(PIN_A4)){
estado_sensores='i';
}
else if(input(PIN_A0)&&input(PIN_A1)&&!input(PIN_A2)&&!input(PIN_A3)&&input(PIN_A4)){
estado_sensores='j';
}
else if(!input(PIN_A0)&&!input(PIN_A1)&&input(PIN_A2)&&!input(PIN_A3)&&input(PIN_A4)){
estado_sensores='k';
}
else if(input(PIN_A0)&&!input(PIN_A1)&&input(PIN_A2)&&!input(PIN_A3)&&input(PIN_A4)){
estado_sensores='l';
}
else if(!input(PIN_A0)&&input(PIN_A1)&&input(PIN_A2)&&!input(PIN_A3)&&input(PIN_A4)){
estado_sensores='m';
}
else if(input(PIN_A0)&&input(PIN_A1)&&input(PIN_A2)&&!input(PIN_A3)&&input(PIN_A4)){
estado_sensores='n';
}
else if(!input(PIN_A0)&&!input(PIN_A1)&&!input(PIN_A2)&&input(PIN_A3)&&input(PIN_A4)){
estado_sensores='o';
}
else if(input(PIN_A0)&&!input(PIN_A1)&&!input(PIN_A2)&&input(PIN_A3)&&input(PIN_A4)){
estado_sensores='p';
}
else if(!input(PIN_A0)&&input(PIN_A1)&&!input(PIN_A2)&&input(PIN_A3)&&input(PIN_A4)){
estado_sensores='q';
}
else if(input(PIN_A0)&&input(PIN_A1)&&!input(PIN_A2)&&input(PIN_A3)&&input(PIN_A4)){
estado_sensores='r';
}
else if(!input(PIN_A0)&&!input(PIN_A1)&&input(PIN_A2)&&input(PIN_A3)&&input(PIN_A4)){
estado_sensores='s';
}
else if(input(PIN_A0)&&!input(PIN_A1)&&input(PIN_A2)&&input(PIN_A3)&&input(PIN_A4)){
estado_sensores='t';
}
else if(!input(PIN_A0)&&input(PIN_A1)&&input(PIN_A2)&&input(PIN_A3)&&input(PIN_A4)){
estado_sensores='u';
}
else if(input(PIN_A0)&&input(PIN_A1)&&input(PIN_A2)&&input(PIN_A3)&&input(PIN_A4)){
estado_sensores='v';
}
enable_interrupts(GLOBAL);
enable_interrupts(int_rda);
}
while(true);
}
El carácter 'z' es el que te da el estado de las entradas, antes del reset pulsando una vez la 'z' era suficiente, después del reset al pulsar uan vez 'z' me da el estado anterior, y a la siguiente vez que pulso 'z' ya me da el estado correcto. Muchas gracias.