File "sci12.c"
Full Path: /home/analogde/www/68hc11/sci12.c
File size: 2.9 KB
MIME-type: text/x-c
Charset: utf-8
5a0
HTTP/1.1 200 OK
Date: Sat, 18 Jun 2005 20:20:25 GMT
Server: Apache/1.3.26 (Unix) Debian GNU/Linux mod_perl/1.26 mod_ssl/2.8.9 OpenSSL/0.9.6g PHP/4.1.2
Last-Modified: Wed, 08 Jan 2003 19:43:34 GMT
ETag: "15ce605-a32-3e1c7f66"
Accept-Ranges: bytes
Content-Length: 2610
Keep-Alive: timeout=15, max=99
Connection: Keep-Alive
Content-Type: text/x-csrc
/* ************************ 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, norma
492
l 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--------
0
------------------
// 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"