Problema con la #INT_RDA

Hola como estan, tengo varios dias tratando de transmitir y recibir datos por el UART del PIC 18F4550. Cuando envio un string del PIC hacia la PC lo hace correctamente, sin embargo cuando envio un caracter de la PC al PIC no pasa nada, el dato se llega a la patilla del PIC pues lo he corroborado con un osciloscopio, les dejo el codigo para que me indiquen que tengo mal....:

#include <18F4550.h>

#FUSES NOWDT //No Watch Dog Timer
#FUSES WDT128 //Watch Dog Timer uses 1:128 Postscale
#FUSES XT //Crystal osc <= 4mhz for PCM/PCH , 3mhz to 10 mhz for PCD
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOBROWNOUT //No brownout reset
#FUSES BORV20 //Brownout reset at 2.0V
#FUSES NOPUT //No Power Up Timer
#FUSES NOCPD //No EE protection
#FUSES STVREN //Stack full/underflow will cause reset
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOWRT //Program memory not write protected
#FUSES NOWRTD //Data EEPROM not write protected
#FUSES IESO //Internal External Switch Over mode enabled
#FUSES FCMEN //Fail-safe clock monitor enabled
#FUSES PBADEN //PORTB pins are configured as analog input channels on RESET
#FUSES NOWRTC //configuration not registers write protected
#FUSES NOWRTB //Boot block not write protected
#FUSES NOEBTR //Memory not protected from table reads
#FUSES NOEBTRB //Boot block not protected from table reads
#FUSES NOCPB //No Boot Block code protection
#FUSES MCLR //Master Clear pin enabled
#FUSES LPT1OSC //Timer1 configured for low-power operation
#FUSES NOXINST //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#FUSES PLL12 //Divide By 12(48MHz oscillator input)
#FUSES CPUDIV4 //System Clock by 4
#FUSES USBDIV //USB clock source comes from PLL divide by 2
#FUSES VREGEN //USB voltage regulator enabled
#FUSES ICPRT //ICPRT enabled

#use delay(clock=8000000)
#use rs232(baud=9600, parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8) //manejo del RS2326.

char rcvchar = 0x00;

#int_RDA
void RDA_isr(void)
{
disable_interrupts(GLOBAL);
rcvchar = 0x00;
if(kbhit()){
rcvchar = getc();

if (rcvchar == 0x61){
OUTPUT_HIGH(PIN_D1);
}

else{
OUTPUT_LOW(PIN_D1);
}
}
enable_interrupts(GLOBAL);
}

void main(void){

disable_interrupts(GLOBAL);
disable_interrupts(INT_RDA);

setup_psp(PSP_DISABLED);
setup_wdt(WDT_OFF);
setup_timer_0(RTCC_INTERNAL);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_timer_3(T3_DISABLED);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
setup_oscillator(OSC_8MHZ|OSC_TIMER1|OSC_31250|OSC_PLL_OFF);
setup_adc_ports(NO_ANALOGS);

OUTPUT_LOW(PIN_D1);
delay_ms(5000);

while(1){

if (!input(PIN_D4)){

delay_ms(5000);
printf("\n\rPassword: ");
enable_interrupts(GLOBAL);
enable_interrupts(INT_RDA);

}

}
}
 

Adjuntos

  • Proyecto_09_03_2U.txt
    3.1 KB · Visitas: 8
Hola, tenes el oscilador del micro a 8Mhz como dice la rutina.
Agrega putc(rcvchar); despues de rcvchar = getc(); y fijate si te devuelve el mismo caracter.

Hola, con estas midificaciones funciona.
#include <18F4550.h>

#FUSES NOWDT //No Watch Dog Timer
#FUSES WDT128 //Watch Dog Timer uses 1:128 Postscale
#FUSES XT //Crystal osc <= 4mhz for PCM/PCH , 3mhz to 10 mhz for PCD
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOBROWNOUT //No brownout reset
#FUSES BORV20 //Brownout reset at 2.0V
#FUSES NOPUT //No Power Up Timer
#FUSES NOCPD //No EE protection
#FUSES STVREN //Stack full/underflow will cause reset
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOWRT //Program memory not write protected
#FUSES NOWRTD //Data EEPROM not write protected
#FUSES IESO //Internal External Switch Over mode enabled
#FUSES FCMEN //Fail-safe clock monitor enabled
#FUSES PBADEN //PORTB pins are configured as analog input channels on RESET
#FUSES NOWRTC //configuration not registers write protected
#FUSES NOWRTB //Boot block not write protected
#FUSES NOEBTR //Memory not protected from table reads
#FUSES NOEBTRB //Boot block not protected from table reads
#FUSES NOCPB //No Boot Block code protection
#FUSES MCLR //Master Clear pin enabled
#FUSES LPT1OSC //Timer1 configured for low-power operation
#FUSES NOXINST //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#FUSES PLL12 //Divide By 12(48MHz oscillator input)
#FUSES CPUDIV4 //System Clock by 4
#FUSES USBDIV //USB clock source comes from PLL divide by 2
#FUSES VREGEN //USB voltage regulator enabled
#FUSES ICPRT //ICPRT enabled

#use delay(clock=8000000)
#use rs232(baud=9600, parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8) //manejo del RS2326.

char rcvchar = 0x00;
char dato = 0;

#int_RDA
void RDA_isr(void)
{
disable_interrupts(GLOBAL);
rcvchar = 0x00;
if(kbhit()){
rcvchar = getc();
putc(rcvchar);
}
if (rcvchar=='5'){
OUTPUT_HIGH(PIN_D1);
}

else{
OUTPUT_LOW(PIN_D1);
}

enable_interrupts(GLOBAL);
}

void main(void){

disable_interrupts(GLOBAL);
disable_interrupts(INT_RDA);

setup_psp(PSP_DISABLED);
setup_wdt(WDT_OFF);
setup_timer_0(RTCC_INTERNAL);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_timer_3(T3_DISABLED);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
setup_oscillator(OSC_8MHZ|OSC_TIMER1|OSC_31250|OSC_PLL_OFF);
setup_adc_ports(NO_ANALOGS);

OUTPUT_low(PIN_D1);
delay_ms(5000);

while(1){

if (!input(PIN_D4)){

delay_ms(5000);
printf("\n\rPassword: ");
enable_interrupts(GLOBAL);
enable_interrupts(INT_RDA);

}

}
}
Fijate que la comparacion la hago con un solo caracter, en este caso el 5, y puedes escribir varios, pero siempre toma el ultimo.
para ingresar un numero como 0x61, la rutina debe ser otra, donde vaya juntando los caracteres escritos y forme el string con el que queres comparar.
 
Última edición:
Atrás
Arriba