1 /******************************************************************************
2 * based on software from:
3 * Copyright 2004, R O SoftWare
4 * No guarantees, warrantees, or promises, implied or otherwise.
5 * May be used for hobby or commercial purposes provided copyright
6 * notice remains intact.
8 * reduced to learn what has to be done to enable and use UART0
9 *****************************************************************************/
19 ///////////////////////////////////////////////////////////////////////////////
20 // use the following macros to determine the 'baud' parameter values
21 // for uart0Init() and uart1Init()
22 // CAUTION - 'baud' SHOULD ALWAYS BE A CONSTANT or
23 // a lot of code will be generated.
24 // Baud-Rate is calculated based on pclk (VPB-clock)
25 // the devisor must be 16 times the desired baudrate
26 #define UART_BAUD(baud) (uint16_t)(((FOSC*PLL_MUL/PBSD) / ((baud) * 16.0)) + 0.5)
28 ///////////////////////////////////////////////////////////////////////////////
29 // Definitions for typical UART 'baud' settings
30 #define B1200 UART_BAUD(1200)
31 #define B9600 UART_BAUD(9600)
32 #define B19200 UART_BAUD(19200)
33 #define B38400 UART_BAUD(38400)
34 #define B57600 UART_BAUD(57600)
35 #define B115200 UART_BAUD(115200)
37 ///////////////////////////////////////////////////////////////////////////////
38 // Definitions for typical UART 'mode' settings
39 #define UART_8N1 (uint8_t)(ULCR_CHAR_8 + ULCR_PAR_NO + ULCR_STOP_1)
40 #define UART_7N1 (uint8_t)(ULCR_CHAR_7 + ULCR_PAR_NO + ULCR_STOP_1)
41 #define UART_8N2 (uint8_t)(ULCR_CHAR_8 + ULCR_PAR_NO + ULCR_STOP_2)
42 #define UART_7N2 (uint8_t)(ULCR_CHAR_7 + ULCR_PAR_NO + ULCR_STOP_2)
43 #define UART_8E1 (uint8_t)(ULCR_CHAR_8 + ULCR_PAR_EVEN + ULCR_STOP_1)
44 #define UART_7E1 (uint8_t)(ULCR_CHAR_7 + ULCR_PAR_EVEN + ULCR_STOP_1)
45 #define UART_8E2 (uint8_t)(ULCR_CHAR_8 + ULCR_PAR_EVEN + ULCR_STOP_2)
46 #define UART_7E2 (uint8_t)(ULCR_CHAR_7 + ULCR_PAR_EVEN + ULCR_STOP_2)
47 #define UART_8O1 (uint8_t)(ULCR_CHAR_8 + ULCR_PAR_ODD + ULCR_STOP_1)
48 #define UART_7O1 (uint8_t)(ULCR_CHAR_7 + ULCR_PAR_ODD + ULCR_STOP_1)
49 #define UART_8O2 (uint8_t)(ULCR_CHAR_8 + ULCR_PAR_ODD + ULCR_STOP_2)
50 #define UART_7O2 (uint8_t)(ULCR_CHAR_7 + ULCR_PAR_ODD + ULCR_STOP_2)
52 ///////////////////////////////////////////////////////////////////////////////
53 // Definitions for typical UART 'fmode' settings
54 #define UART_FIFO_OFF (0x00)
55 #define UART_FIFO_1 (uint8_t)(UFCR_FIFO_ENABLE + UFCR_FIFO_TRIG1)
56 #define UART_FIFO_4 (uint8_t)(UFCR_FIFO_ENABLE + UFCR_FIFO_TRIG4)
57 #define UART_FIFO_8 (uint8_t)(UFCR_FIFO_ENABLE + UFCR_FIFO_TRIG8)
58 #define UART_FIFO_14 (uint8_t)(UFCR_FIFO_ENABLE + UFCR_FIFO_TRIG14)
60 void uart0Init(uint16_t baud
, uint8_t mode
, uint8_t fmode
);
61 int uart0Putch(int ch
);
62 uint16_t uart0Space(void);
63 const char *uart0Puts(const char *string
);
64 int uart0TxEmpty(void);
65 void uart0TxFlush(void);