#include <htc.h>
__CONFIG(LVP_OFF & BOREN_OFF & PWRTE_ON & WDTE_OFF & FOSC_HS);
#define _XTAL_FREQ 20000000
unsigned char *c;
unsigned char HSerin(void);
void HSerout(unsigned char ch),
HSerinit(void);
void main(void) // program entry
{
TRISB=0x00;
unsigned char ch ; // <- LOOK HERE.
ADCON1 = 0x6; // Analogue off
HSerinit();
__delay_ms(1);
while(1) // endless Loop
{
ch='a';
char *temp; // Temporary pointer that we will use inside the loop.
temp = c; // Set the pointer at the beginning
HSerout(ch); //for testing UART initially
for(char t=0;t<5;t++){
*temp++= HSerin();
}
ch='b';//testing after saving...
HSerout(ch);
}
}
void HSerinit()
{
TRISC = 0b10000000; // should ideally be set
SPBRG = 129; // 20Mhz xtal 9600 BAUD
TXSTA = 0x24; // TXEN and BRGH
RCSTA = 0x90; // SPEN and CREN
}
void HSerout(unsigned char ch) {
while(!TXIF); // Wait for module to finish
TXREG = ch; // ready to send
}
unsigned char HSerin()
{ while(!RCIF); // Wait for a character
return RCREG; // return character
}