#ifndef _UART0_H_ #define _UART0_H_ void uart0_bauding(unsigned long baudrate); void uart0_init(); #define UART0_TX_BUFFER_SIZE 32 #define UART0_RX_BUFFER_SIZE (0x100 - 32) #include "c8051f580.h" #include "fifo.h" FIFO_SIZE_T uart0_write(char *buf, FIFO_SIZE_T size); FIFO_SIZE_T uart0_read(char *buf, FIFO_SIZE_T size); FIFO_SIZE_T uart0_tx_size(); FIFO_SIZE_T uart0_rx_size(); #ifdef MAIN_C extern __xdata fifo_char_t fifo_tx0; extern __xdata fifo_char_t fifo_rx0; /* Interrupt(TI0 / RI0) */ void interrupt_uart0 () __interrupt(INTERRUPT_UART0) { unsigned char c; if(RI0){ RI0 = 0; /* リングバッファに1バイト書き出し */ c = SBUF0; if(fifo_char_put2(&fifo_rx0, c)){ //P4 &= ~0x02; }else{/*P4 ^= 0x02;*/} } if(TI0){ TI0 = 0; /* 書き込むデータがあるか確認 */ if(fifo_char_size(&fifo_tx0) > 0){ c = fifo_char_get2(&fifo_tx0); TB80 = 1; // TB80は書込み中フラグとして使う、1(書込み中)に SBUF0 = c; }else{ TB80 = 0; // TB80は書込み中フラグとして使う、0(書込みしていない)に } } } #endif /** * For stdio.h */ char getchar(); void putchar(char c); #endif