Page 420 - Programming Microcontrollers in C
P. 420
Serial Input/Output 405
inituart() Initializes the uart to the passed baud
rate and sets 8 bit, no parity, and one
stop bit.
getchar() tests for receive ready and echo
getch() no echo
getce() no ready test or echo
kbhit() returns TRUE if a key has been hit,
FALSE otherwise
putchar() Tests for transmit ready
puts() sends out the indicated string
gets() reads in a string into the buffer
getse() reads in a string and echos
printd() convert an unsigned long integer to an
ascii string representation of a decimal
integer and send it out the serial port
printx() convert an unsigned long integer to an
ascii string representation of a
hexidecimal integer and send it out the
serial port
*********************************************************************/
#include “mmc2001.h”
#include “uart.h”
#include “serial.h”
#define U1SRint (*(volatile unsigned short *)(0x1000a086))
enum {TRDYint=8192};
#define U1RXint (*(volatile unsigned short *)(0x1000a000))
enum {CHARRDYint=32768};
#define CLOCK_FREQ 32000000L
/* the functions */
/* Initialize the UART1 */
void inituart(int baud)
{
/* Parity is disabled at reset by default */
/* stop bits is set to 1 by default */
/* assumes a 32 mHz system clock */
U1CR1.UARTEN=ON; /* Turn the uart on */
U1CR1.TXEN=ON; /* enable transmitter and receiver */
U1CR1.RXEN=ON;
U1CR2.IRTS=ON; /* ignore request to send */
U1CR2.WS=ON; /* 8 bit word */
/* Baud rate=CLOCK_FREQ/16/baud= */
U1BRGR.CD=(UHWORD)(CLOCK_FREQ/16/baud);