Buen día,
He estado intentado realizar la comunicación serial (nunca antes lo había intentado) con el módulo UART del PIC 18F4550 con un programa bastante sencillo el cual solo prende o apaga un led dependiendo de si recibe una "a" o una "b" desde la pc mientras otro led se mantiene prendiendo y apagando cada cierto tiempo. El micro lo estoy programando en C18 y simulado en proteus funciona correctamente pero al momento de programar el micro y probarlo con el UART Tool del Pickit 2 el micro parece que no recibe nada de la pc.
El micro lo tengo programado para que trabaje en modo asíncrono a 9600 bauds y así tambien están configurados el virtual terminal de proteus y el UART Tool del Pickit 2.
Dejo mi código a ver si alguien encuentra algo mal configurado o algo.
Saludos!Código:#define USE_OR_MASKS #include <p18F4550.h> #include <timers.h> #include <usart.h> #pragma config PLLDIV = 5 // (20 MHz crystal on PICDEM FS USB board) #pragma config CPUDIV = OSC1_PLL2 #pragma config USBDIV = 2 // Clock source from 96MHz PLL/2 #pragma config FOSC = HSPLL_HS #pragma config FCMEN = OFF #pragma config IESO = OFF #pragma config PWRT = OFF #pragma config BOR = ON #pragma config BORV = 3 #pragma config VREGEN = ON //USB Voltage Regulator #pragma config WDT = OFF #pragma config WDTPS = 32768 #pragma config MCLRE = ON #pragma config LPT1OSC = OFF #pragma config PBADEN = OFF // #pragma config CCP2MX = ON #pragma config STVREN = ON #pragma config LVP = OFF // #pragma config ICPRT = OFF // Dedicated In-Circuit Debug/Programming #pragma config XINST = OFF // Extended Instruction Set #pragma config CP0 = OFF #pragma config CP1 = OFF // #pragma config CP2 = OFF // #pragma config CP3 = OFF #pragma config CPB = OFF // #pragma config CPD = OFF #pragma config WRT0 = OFF #pragma config WRT1 = OFF // #pragma config WRT2 = OFF // #pragma config WRT3 = OFF #pragma config WRTB = OFF // Boot Block Write Protection #pragma config WRTC = OFF // #pragma config WRTD = OFF #pragma config EBTR0 = OFF #pragma config EBTR1 = OFF // #pragma config EBTR2 = OFF // #pragma config EBTR3 = OFF #pragma config EBTRB = OFF void ISRRecepcion(void); volatile char Data,Kbhit; #define REMAPPED_RESET_VECTOR_ADDRESS 0x1000 #define REMAPPED_HIGH_INTERRUPT_VECTOR_ADDRESS 0x1008 #define REMAPPED_LOW_INTERRUPT_VECTOR_ADDRESS 0x1018 void YourHighPriorityISRCode(); void YourLowPriorityISRCode(); extern void _startup (void); // See c018i.c in your C18 compiler dir #pragma code REMAPPED_RESET_VECTOR = REMAPPED_RESET_VECTOR_ADDRESS void _reset (void){ _asm goto _startup _endasm } #pragma code REMAPPED_HIGH_INTERRUPT_VECTOR = REMAPPED_HIGH_INTERRUPT_VECTOR_ADDRESS void Remapped_High_ISR (void) { _asm goto YourHighPriorityISRCode _endasm } #pragma code REMAPPED_LOW_INTERRUPT_VECTOR = REMAPPED_LOW_INTERRUPT_VECTOR_ADDRESS void Remapped_Low_ISR (void){ _asm goto YourLowPriorityISRCode _endasm } #pragma code HIGH_INTERRUPT_VECTOR = 0x08 void High_ISR (void) { _asm goto REMAPPED_HIGH_INTERRUPT_VECTOR_ADDRESS _endasm } #pragma code LOW_INTERRUPT_VECTOR = 0x18 void Low_ISR (void){ _asm goto REMAPPED_LOW_INTERRUPT_VECTOR_ADDRESS _endasm } #pragma code #pragma interrupt YourHighPriorityISRCode void YourHighPriorityISRCode() { if (PIR1bits.RCIF==1){ Data=getcUSART(); PIR1bits.RCIF=0; switch(Data){ case 0x61: putrsUSART("Led apagado\r"); PORTDbits.RD7=0; break; case 0x62: putrsUSART("Led prendido\r"); PORTDbits.RD7=1; break; } } } //This return will be a "retfie fast", since this is in a #pragma interrupt section #pragma interruptlow YourLowPriorityISRCode void YourLowPriorityISRCode() { } //This return will be a "retfie", since this is in a #pragma interruptlow section /** DECLARATIONS ***************************************************/ #pragma code char k; void main (void) { unsigned char config=0,spbrg=0,baudconfig=0,i=0; TRISD=0X00; LATD=0XFF; CloseUSART(); //turn off usart if was previously on //-----configure USART ----- config = USART_TX_INT_OFF | USART_RX_INT_ON| USART_ASYNCH_MODE | USART_EIGHT_BIT | USART_CONT_RX | USART_BRGH_LOW; //-----SPBRG needs to be changed depending upon oscillator frequency------- spbrg = 129; //At 20Mhz of oscillator frequency & baud rate of 9600. OpenUSART(config, spbrg); //API configures USART for desired parameters baudconfig = BAUD_16_BIT_RATE | BAUD_AUTO_OFF; baudUSART (baudconfig); RCONbits.IPEN=0; INTCONbits.PEIE=1; INTCONbits.GIE=1; putrsUSART("Prueba Comunicacion Serial \r"); while(1){ for(k=0;k<2;k++) { Delay10KTCYx(130); } PORTDbits.RD6=1; for(k=0;k<2;k++) { Delay10KTCYx(130); } PORTDbits.RD6=0; } }


LinkBack URL
About LinkBacks
Citar

