Go to the source code of this file.
Data Structures | |
struct | UART1_BUFFER_CONTROL |
struct | UART1_CONTROL |
Defines | |
#define | UART_MASTER 0x80 |
#define | UART_NINEBIT 0x40 |
#define | UART_TXEN 0x20 |
#define | UART_SYNC 0x10 |
#define | UART_SENDB 0x08 |
#define | UART_BEGH 0x04 |
#define | UART_TRMT 0x02 |
#define | UART_TX9D 0x01 |
#define | UART_SPEN 0x80 |
#define | UART_RX9 0x40 |
#define | UART_SREN 0x20 |
#define | UART_CREN 0x10 |
#define | UART_ADDEN 0x08 |
#define | UART_FERR 0x04 |
#define | UART_OERR 0x02 |
#define | UART_RX9D 0x01 |
#define | UART_ABDOVF 0x80 |
#define | UART_RCIDL 0x40 |
#define | UART_SCKP 0x10 |
#define | UART_BRG16 0x08 |
#define | UART_WUE 0x02 |
#define | UART_ABDEN 0x01 |
#define | UART1_BAUDRATE_1 115200 |
#define | UART1_SPBREG1_DEF 86 |
#define | UART1_SPBREG1_HB (UART1_SPBREG1_DEF / 256) |
#define | UART1_SPBREG1_LB (UART1_SPBREG1_DEF % 256) |
#define | UART1_MAX_BUFFER_SIZE 200 |
Functions | |
void | Uart1Init (void) |
void | Uart1CharPut (char) |
void | Uart1RxIsr (void) |
void | Uart1TxIsr (void) |
void | Uart1Svc (void) |
void | Uart1BufferReset (void) |
void | Uart1RxBufferPut (INT8U Data) |
INT8U | Uart1RxBufferGet (void) |
INT8U | Uart1TxBufferGet (void) |
void | Uart1TxBufferPut (INT8U Data) |
INT8U | Uart1TxBufferCheck (void) |
INT8U | Uart1RxBufferCheck (void) |
void | Uart1CharTx (char Data) |
void | Uart1StringTx (const char *pString) |
Variables | |
UART1_CONTROL | Uart1Ctrl |
void Uart1BufferReset | ( | void | ) |
void Uart1CharPut | ( | char | ) |
void Uart1CharTx | ( | char | Data | ) |
Definition at line 179 of file uart1.c.
00179 { 00180 while(Uart1TxBufferCheck()==BUFFER_FULL) Uart1Svc(); 00181 Uart1TxBufferPut(Data); 00182 Uart1Svc(); 00183 }
void Uart1Init | ( | void | ) |
Definition at line 17 of file uart1.c.
00017 { 00018 //set tx,rx pin function 00019 TRISC6=0; // TRISC6 is uart 1 tx pin...set output 00020 TRISC7=1; // TRISC7 is uart 1 rx pin...set input 00021 // uart works with hs 00022 //SPBRG=((int)(FOSC/(16UL * BAUD) -1)); 00023 BAUDCON1=0x08; // brg16=1...use 16 bit baudrate generator 00024 SPBRGH1=UART1_SPBREG1_HB; // baudrate generator high byte 00025 SPBRG1=UART1_SPBREG1_LB ; // baudrate generator low byte 00026 TXSTA1=0x24; // TX enable & BRGH=1 & SYNC=0 00027 RCSTA1=0x90; // Serial port enabled & RX enable 00028 00029 #if(USART1_ISR_EN==1) 00030 RC1IF=0; // clear uart1 rx interrupt flag 00031 TX1IF=0; // clear uart1 tx interrupt flag 00032 RC1IP=0; // set uart1 rx priority low 00033 TX1IP=0; // set uart1 tx priority low 00034 RC1IE=1; // enable uart rx interrupt 00035 TX1IE=0; // disable uart tx interrupt 00036 #endif 00037 00038 Uart1Ctrl.TxBuffer.Get=0; 00039 Uart1Ctrl.TxBuffer.Put=0; 00040 Uart1Ctrl.RxBuffer.Get=0; 00041 Uart1Ctrl.RxBuffer.Put=0; 00042 Uart1Ctrl.UartTxTransmit=FALSE; 00043 }
INT8U Uart1RxBufferCheck | ( | void | ) |
Definition at line 52 of file uart1.c.
00052 { 00053 if(Uart1Ctrl.RxBuffer.Put!=Uart1Ctrl.RxBuffer.Get){ 00054 if(Uart1Ctrl.RxBuffer.Put==(UART1_MAX_BUFFER_SIZE-1)){ 00055 if(Uart1Ctrl.RxBuffer.Get==0) return BUFFER_FULL; 00056 else return BUFFER_NOT_EMPTY; 00057 } 00058 else{ 00059 if((Uart1Ctrl.RxBuffer.Put+1)==Uart1Ctrl.RxBuffer.Get) return BUFFER_FULL; 00060 else return BUFFER_NOT_EMPTY; 00061 } 00062 } 00063 else return BUFFER_EMPTY; 00064 }
INT8U Uart1RxBufferGet | ( | void | ) |
Definition at line 100 of file uart1.c.
00100 { 00101 INT8U Data; 00102 00103 if(Uart1RxBufferCheck()==BUFFER_EMPTY) return 0; 00104 if(Uart1Ctrl.RxBuffer.Get==(UART1_MAX_BUFFER_SIZE-1)){ 00105 Data=Uart1Ctrl.RxBuffer.Data[Uart1Ctrl.RxBuffer.Get]; 00106 Uart1Ctrl.RxBuffer.Get=0; 00107 } 00108 else{ 00109 Data=Uart1Ctrl.RxBuffer.Data[Uart1Ctrl.RxBuffer.Get]; 00110 Uart1Ctrl.RxBuffer.Get++; 00111 } 00112 return Data; 00113 }
void Uart1RxBufferPut | ( | INT8U | Data | ) |
Definition at line 78 of file uart1.c.
00078 { 00079 if(Uart1RxBufferCheck()==BUFFER_FULL) return; 00080 if(Uart1Ctrl.RxBuffer.Put==(UART1_MAX_BUFFER_SIZE-1)){ 00081 Uart1Ctrl.RxBuffer.Data[Uart1Ctrl.RxBuffer.Put]=Data; 00082 Uart1Ctrl.RxBuffer.Put=0; 00083 } 00084 else{ 00085 Uart1Ctrl.RxBuffer.Data[Uart1Ctrl.RxBuffer.Put]=Data; 00086 Uart1Ctrl.RxBuffer.Put++; 00087 } 00088 }
void Uart1RxIsr | ( | void | ) |
void Uart1StringTx | ( | const char * | pString | ) |
Definition at line 188 of file uart1.c.
00188 { 00189 while(*pString!=0){ 00190 Uart1CharTx(*pString); 00191 pString++; 00192 } 00193 }
void Uart1Svc | ( | void | ) |
Definition at line 206 of file uart1.c.
00206 { 00207 if(Uart1Ctrl.UartTxTransmit==TRUE) return; 00208 if(Uart1TxBufferCheck()==BUFFER_EMPTY) return; 00209 Uart1Ctrl.UartTxTransmit=TRUE; 00210 TX1IE=1; // enable uart tx interrupt 00211 // pic generate interrupt automatically 00212 // data is assigned and transmited in ISR 00213 }
INT8U Uart1TxBufferCheck | ( | void | ) |
Definition at line 127 of file uart1.c.
00127 { 00128 if(Uart1Ctrl.TxBuffer.Put!=Uart1Ctrl.TxBuffer.Get){ 00129 if(Uart1Ctrl.TxBuffer.Put==(UART1_MAX_BUFFER_SIZE-1)){ 00130 if(Uart1Ctrl.TxBuffer.Get==0) return BUFFER_FULL; 00131 else return BUFFER_NOT_EMPTY; 00132 } 00133 else{ 00134 if((Uart1Ctrl.TxBuffer.Put+1)==Uart1Ctrl.TxBuffer.Get) return BUFFER_FULL; 00135 else return BUFFER_NOT_EMPTY; 00136 } 00137 } 00138 else return BUFFER_EMPTY; 00139 }
INT8U Uart1TxBufferGet | ( | void | ) |
Definition at line 151 of file uart1.c.
00151 { 00152 INT8U Data; 00153 00154 if(Uart1TxBufferCheck()==BUFFER_EMPTY) return 0; 00155 if(Uart1Ctrl.TxBuffer.Get==(UART1_MAX_BUFFER_SIZE-1)){ 00156 Data=Uart1Ctrl.TxBuffer.Data[Uart1Ctrl.TxBuffer.Get]; 00157 Uart1Ctrl.TxBuffer.Get=0; 00158 } 00159 else{ 00160 Data=Uart1Ctrl.TxBuffer.Data[Uart1Ctrl.TxBuffer.Get]; 00161 Uart1Ctrl.TxBuffer.Get++; 00162 } 00163 return Data; 00164 }
void Uart1TxBufferPut | ( | INT8U | Data | ) |
Definition at line 140 of file uart1.c.
00140 { 00141 if(Uart1TxBufferCheck()==BUFFER_FULL) return; 00142 if(Uart1Ctrl.TxBuffer.Put==(UART1_MAX_BUFFER_SIZE-1)){ 00143 Uart1Ctrl.TxBuffer.Data[Uart1Ctrl.TxBuffer.Put]=Data; 00144 Uart1Ctrl.TxBuffer.Put=0; 00145 } 00146 else{ 00147 Uart1Ctrl.TxBuffer.Data[Uart1Ctrl.TxBuffer.Put]=Data; 00148 Uart1Ctrl.TxBuffer.Put++; 00149 } 00150 }
void Uart1TxIsr | ( | void | ) |
Definition at line 197 of file uart1.c.
00197 { 00198 if(Uart1TxBufferCheckIsr()==BUFFER_EMPTY){ 00199 Uart1Ctrl.UartTxTransmit=FALSE; 00200 TX1IE=0; // disable uart tx interrupt as last byte finished. 00201 } 00202 else{ 00203 TXREG1=Uart1TxBufferGetIsr(); 00204 } 00205 }