while (1) // infinite loop which handles ncoming data as they arrive
{
UART_putc(cUART_char);
if (cUART_data_flg==1)// if new data available, send it back through USART tx line (echo it)
{
UART_putc(cUART_char);
cUART_data_flg=0; // clear new data flag so one charactor will echoed once
}
}
}
#pragma code
#pragma interrupt InterruptHandlerLow
void InterruptHandlerLow ()
{
if (RCIF==1)
{
if(RCSTA&0x06)
{
CREN=0; //Overrun error (can be cleared by clearing bit CREN)
cUART_char=RCREG; //clear Framing error
CREN=1;
}
else
{
cUART_char = RCREG; // read new data into variable
cUART_data_flg = 1; // new data received. so enable flg
}
}
}
void init_uart(void)
{
TRISC7=1; //Make UART RX pin input
TRISC6=0; //Make UART TX pin output
SYNC = 0; // enables for asynchronous EUART
SPEN = 1; // enables EUSART and sets TX (RC6) as output; ANSEL must be cleared if shared with analog I/O
CREN = 1;
TX9 = 0; // 8bit mode RX9 = 0;
TXEN = 1; // enables Transmitter
BRGH = 1; // baud rate select BRG16 = 0;
SPBRG = 25; //baud rate select 9600@4Mhz SPBRGH = 0;
RCIE=1; // receive interrupt enable
GIE=1; // global interrupt enable
PEIE=1 ; // Peripheral Interrupt Enable bit
}
void UART_putc(unsigned char c)
{
TXEN=0;// disable transmission
TXREG=0x61; // load txreg with data
TXEN=1; // enable transmission
while(TRMT==0) // wait here till transmit complete
{
}
}
alan
Joined: 12 Nov 2012 Posts: 357 Location: South Africa
Posted: Sun Sep 29, 2013 11:33 pm
You will have to ask on the HiTech forum as this forum are for PICC users.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum