Hey guys!
I am stuck with a little project of mine and I hope you can help me.
I'm quite new to PIC programming and i am trying to build a PIC to PIC serial communication. I already programmed the sender, but now i have problems with the receiver part. I want to make a LED flash on RC0 every time a receiving interrupt occurs to check if it works. I use the PICkit 2 UART tool to send to my PIC, but when I do, nothing happens. Is there somthing wrong in the code or am i missing something?
Thanks in advance!
I am stuck with a little project of mine and I hope you can help me.
I'm quite new to PIC programming and i am trying to build a PIC to PIC serial communication. I already programmed the sender, but now i have problems with the receiver part. I want to make a LED flash on RC0 every time a receiving interrupt occurs to check if it works. I use the PICkit 2 UART tool to send to my PIC, but when I do, nothing happens. Is there somthing wrong in the code or am i missing something?
Thanks in advance!
Rich (BB code):
#include <htc.h>
#include <pic16f690.h>
unsigned char counter=0;//Overflow counter
unsigned char counter2=0;//Overflow counter
void initTMR0 (void);
void initUART (void);
void main()
{
initTMR0(); //TMR0 init
initUART(); // UART init
ANSEL = 0;
TRISB5 = 1; //RX input
TRISB7 = 0;// TX output
TRISC=0; // PORTC = output
PORTC=0; // PORTC reset
while(1)
{
};
}
void initTMR0(void)
{
OPTION_REGbits.PS0=1; //Prescaler is divide by 256
OPTION_REGbits.PS1=1;
OPTION_REGbits.PS2=1;
OPTION_REGbits.PSA=0; //Timer Clock Source is from Prescaler
OPTION_REGbits.T0CS=0;//Prescaler gets clock from FCPU (1MHz)
INTCONbits.T0IE=1; //Enable TIMER0 Interrupt
INTCONbits.T0IF=0;
INTCONbits.PEIE=1; //Enable Peripheral Interrupt
INTCONbits.GIE=1; //Enable interrupts globally
PIR1bits.RCIF = 0; // make interrupt flag = 0
}
void initUART(void)
{
SPBRG = 25; //Fosch 4Mhz -> baudrate 2400
TXSTAbits.BRGH = 0; //Sets Low Baud Rate
TXSTAbits.SYNC = 0; //Sets Asynchronous mode
RCSTAbits.SPEN = 1; //Enables EUSART
// TXSTAbits.TXEN = 1; //Enables the EUSART transmiter
RCSTAbits.CREN = 1; //enable receive
PIE1bits.RCIE = 1; //enables receive interrupt flag
}
//Main Interrupt Service Routine (ISR)
void interrupt ISR ()
{
//unsigned char c;
if (PIR1bits.RCIF == 1) //check for recieve interrupt
{
counter ++;
if (counter == 15)
{
counter = 0;
PORTC=0b00000001;
}
else PORTC=0;
PIR1bits.RCIF=0; // interrupt flag off
}
}