46
Chapter 4. Programming
External UART Example
The following example program shows you how to use the external UART to
send and receive serial data. The _getkey and putchar routines are included for
use with the stream functions like printf.
#include <reg251s.h>
#include <stdio.h>
#define DELAY 50000L
#define EXTSIO_ADDR 0xFFE700UL
#define EXTSIO_RBR ((volatile unsigned char far *) (EXTSIO_ADDR))
#define EXTSIO_THR ((volatile unsigned char far *) (EXTSIO_ADDR))
#define EXTSIO_IER ((volatile unsigned char far *) (EXTSI 1))
#define EXTSIO_IIR ((volatile unsigned char far *) (EXTSI 2))
#define EXTSIO_LCR ((volatile unsigned char far *) (EXTSI 3))
#define EXTSIO_MCR ((volatile unsigned char far *) (EXTSI 4))
#define EXTSIO_LSR ((volatile unsigned char far *) (EXTSI 5))
#define EXTSIO_MSR ((volatile unsigned char far *) (EXTSI 6))
#define EXTSIO_SCR ((volatile unsigned char far *) (EXTSI 7))
#define EXTSIO_DLL ((volatile unsigned char far *) (EXTSI 0))
#define EXTSIO_DLM ((volatile unsigned char far *) (EXTSI 1))
#define EXTSIO_CLK 1843200UL
/*-----------------------------------------------
This function sets the baudrate for the external
UART on the MCB251.
-----------------------------------------------*/
void extsio_baudrate (
unsigned long baudrate)
{
unsigned long baud_divisor;
unsigned char lcr_save;
lcr_save = *EXTSIO_LCR;
/* Save LCR */
*EXTSIO_LCR = 0x80;
/* Set DLAB */
baud_divisor = (EXTSIO_CLK / 16UL) / baudrate;
*EXTSIO_DLL = (unsigned char) (baud_divisor & 0xFF);
*EXTSIO_DLM = (unsigned char) ((baud_divisor >> 8) & 0xFF);
*EXTSIO_LCR = lcr_save;
/* Restore LCR */
}
Summary of Contents for MCB251
Page 6: ...vi Contents...
Page 18: ...12 Chapter 2 Setup...
Page 24: ...18 Chapter 3 Hardware Schematics...
Page 25: ...MCB251 Evaluation Board User s Guide 19...
Page 26: ...20 Chapter 3 Hardware...
Page 27: ...MCB251 Evaluation Board User s Guide 21...