/* ************************ SCI12.C ***************************** * Jonathan W. Valvano 12/12/02 * Modified by EE345L students Charlie Gough && Matt Hawk * Modified by EE345M students Agustinus Darmawan + Mingjie Qiu * Simple I/O routines to SCI0 serial port * ************************************************************ */ // Copyright 2003 by Jonathan W. Valvano, valvano@uts.cc.utexas.edu // You may use, edit, run or distribute this file // as long as the above copyright notice remains #define RDRF 0x20 // Receive Data Register Full Bit #define TDRE 0x80 // Transmit Data Register Empty Bit //-------------------------Start of SCI_Init------------------------ // Initialize Serial port SC0 // BaudRate=500000/br // br = 52 means 9200 bits/sec // br = 13 means 38400 bits/sec // br = 1 means 500000 bits/sec void SCI_Init(unsigned short br){ SC0BDH = 0; // br=MCLK/(16*BaudRate) SC0BDL = br; // assumes MCLK is 8 Mhz SC0CR1 = 0; /* bit value meaning 7 0 LOOPS, no looping, normal 6 0 WOMS, normal high/low outputs 5 0 RSRC, not appliable with LOOPS=0 4 0 M, 1 start, 8 data, 1 stop 3 0 WAKE, wake by idle (not applicable) 2 0 ILT, short idle time (not applicable) 1 0 PE, no parity 0 0 PT, parity type (not applicable with PE=0) */ SC0CR2 = 0x0C; /* bit value meaning 7 0 TIE, no transmit interrupts on TDRE 6 0 TCIE, no transmit interrupts on TC 5 0 RIE, no receive interrupts on RDRF 4 0 ILIE, no interrupts on idle 3 1 TE, enable transmitter 2 1 RE, enable receiver 1 0 RWU, no receiver wakeup 0 0 SBK, no send break */ } //-------------------------SCI_InChar------------------------ // Wait for new serial port input, return ASCII code for key typed char SCI_InChar(void){ while((SC0SR1 & RDRF) == 0){}; return(SC0DRL); } //-------------------------SCI_OutChar------------------------ // Wait for buffer to be empty, output ASCII to serial port void SCI_OutChar(char data){ while((SC0SR1 & TDRE) == 0){}; SC0DRL = data; } //-------------------------SCI_InStatus-------------------------- // Checks if new input is ready, TRUE if new input is ready unsigned char SCI_InStatus(void){ return(SC0SR1 & RDRF);} //-----------------------SCI_OutStatus---------------------------- // Checks if output data buffer is empty, TRUE if empty unsigned char SCI_OutStatus(void){ return(SC0SR1 & TDRE);} #include "SCIutil.C"