Page 400 - Programming Microcontrollers in C
P. 400
Input/Output Functions 385
#define BAUDREG *(BYTE *)&SC0BDL
void inituart(void)
{
BAUDREG=BAUD9600;/* Set the bit rate */
SC0CR2.TE=ON; /* turn on transmitter */
SC0CR2.RE=ON; /* and the receiver */
}
void putchar(BYTE x)
{
while(!SC0SR1.TDRE)
; /* wait until register is ready */
SC0DRL=x; /* send the data out */
}
BYTE getchar(void)
{
BYTE a;
while(!SC0SR1.RDRF)
;/* Wait for data ready */
a=SC0DRL;
putchar(a); /* echo the data and */
return a; /* then return it*/
}
void puts(char *s)
{
char *sp;
sp=s;
while(*sp!=’\n’ && *sp!=’\0')
putchar(*sp++);
putchar(‘\n’);
}
Listing 7-17: The Input/Output Routines Used with the
M68HC912B32 Chip

