Este es el código
// PIC12F1822 Configuration Bit Settings
// 'C' source line config statements
#include <xc.h>
#include <string.h>
#include <stdlib.h>
// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.
// CONFIG1
#pragma config FOSC = INTOSC // Oscillator Selection (INTOSC oscillator: I/O function on CLKIN pin)
#pragma config WDTE = OFF // (WDT disabled)
#pragma config PWRTE = OFF // Power-up Timer Enable (PWRT disabled)
#pragma config MCLRE = ON // MCLR Pin Function Select (MCLR/VPP pin function is MCLR)
#pragma config CP = OFF // Flash Program Memory Code Protection (Program memory code protection is disabled)
#pragma config CPD = OFF // Data Memory Code Protection (Data memory code protection is disabled)
#pragma config BOREN = ON // Brown-out Reset Enable (Brown-out Reset enabled)
#pragma config CLKOUTEN = OFF // Clock Out Enable (CLKOUT function is disabled. I/O or oscillator function on the CLKOUT pin)
#pragma config IESO = ON // Internal/External Switchover (Internal/External Switchover mode is enabled)
#pragma config FCMEN = ON // Fail-Safe Clock Monitor Enable (Fail-Safe Clock Monitor is enabled)
// CONFIG2
#pragma config WRT = OFF // Flash Memory Self-Write Protection (Write protection off)
#pragma config PLLEN = OFF // PLL Enable (4x PLL enabled)
#pragma config STVREN = ON // Stack Overflow/Underflow Reset Enable (Stack Overflow or Underflow will cause a Reset)
#pragma config BORV = LO // Brown-out Reset Voltage Selection (Brown-out Reset Voltage (Vbor), low trip point selected.)
#pragma config LVP = ON // Low-Voltage Programming Enable (Low-voltage programming enabled)
char blink = 0;
void delay()
{
int i,j;
for(i=0;i<10;i++)
{
for(j=0;j<1000;j++);
}
}
void init()
{
OSCCON=0xF0; //32 Mhz
ANSELA=0x00; // All pins digital
BAUDCONbits.ABDOVF = 0;
BAUDCONbits.RCIDL=0;
BAUDCONbits.BRG16= 0;
BAUDCONbits.ABDEN = 0;
BAUDCONbits.SCKP = 0;
BAUDCONbits.WUE=0;
APFCONbits.RXDTSEL=0;
APFCONbits.TXCKSEL=0;
SPBRGL = 51;//Baud =9600
RCSTAbits.CREN=1;
RCSTAbits.SPEN =1; //Reciever enabled
INTCONbits.GIE = 1;
INTCONbits.PEIE = 1;
PIE1bits.RCIE = 1;
TXSTAbits.SYNC = 0;
TXSTAbits.TXEN = 1;
TXSTAbits.BRGH = 0;
TXSTAbits.TX9 = 0;
TRISAbits.TRISA0 = 0;
TRISAbits.TRISA1 = 1;
TRISAbits.TRISA2 = 0;
TRISAbits.TRISA4 = 0;
}
void interrupt ISR()
{
if(PIR1bits.RCIF)
PIR1bits.RCIF = 0;
blink=RCREG;
PORTAbits.RA2 = 1;
delay();
PORTAbits.RA2 = 0;
delay();
}
void send_data(char a[])
{
int i;
for(i=0;i<strlen(a);i++)
{
TXREG = a[i];
while(!TXSTAbits.TRMT);
}
}
int main()
{
init();
while(1)
{
if(blink != 0)
{
delay();
send_data(blink);
delay();
blink = 0;
send_data("Dennis");
}
PORTAbits.RA4 = 1;
delay();
PORTAbits.RA4 = 1;
delay();
}
}
Estoy enviando datos desde la UART de arduino. los pines Ra2 se supone que debe hacerlo y parpadea cuando entra en la interrupción. Los datos de Dennis se muestran correctamente. Pero los datos recibidos por el PIC no se devuelven correctamente y estoy obteniendo basura en la salida del puerto serie.