//main.c
#include "libpin.c"
//everything in libpin.c
fifobuffer txbuf,rxbuf;
void send_out(uchar input);
void check_rx();
//life of printf
int putchar(int c)
{
send_out(c);
return (c);
}
pin out;
#define high(whatever) pinhigh(&whatever)
#define low(whatever) pinlow(&whatever)
#define flip(whatever) pinflip(&whatever)
void init()
{
delay(60000);//stable
CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV1);
pininit(&out,'D',7,'p');
fifobufferinit(&txbuf);
fifobufferinit(&rxbuf);
UART2_Init(9600,UART2_WORDLENGTH_8D,UART2_STOPBITS_1,UART2_PARITY_NO,
UART2_SYNCMODE_CLOCK_DISABLE ,UART2_MODE_TXRX_ENABLE);
UART2_ITConfig(UART2_IT_TXE, ENABLE);
UART2_ITConfig(UART2_IT_RXNE, ENABLE);
UART2_Cmd(ENABLE);
}
void main()
{
init();
enableInterrupts();
while(1){
flip(out);
check_rx();
}
}
#pragma vector = 22
__interrupt void txe()
{
if(fifobufferremain(&txbuf)!=0){
UART2_SendData8(fifobufferout(&txbuf));
}else{
UART2_ITConfig(UART2_IT_TXE, DISABLE);
}
}
#pragma vector = 23
__interrupt void rxne()
{
fifobufferin(&rxbuf,UART2_ReceiveData8());
}
void check_rx(){
if(fifobufferremain(&rxbuf)!=0){
uchar a=fifobufferout(&rxbuf);
printf("recv ascii %d\\x0d\\x0a",a);
}
}
inline void send_out(uchar input)
{
fifobufferin(&txbuf,input);
UART2_ITConfig(UART2_IT_TXE, ENABLE);
}