diff --git a/uart_init.c b/uart_init.c new file mode 100644 index 0000000..ccd7fa7 --- /dev/null +++ b/uart_init.c @@ -0,0 +1,29 @@ +#include "mc8051fun.h" + +//#include +#include + +void uart_init(long fosc, long baud) +{ + TMOD = 0; /* Timer 1, 8-bit auto reload mode */ + // P_SW1 |= (1 << 6); // move UART1 pins -> P3_6:rxd, P3_7:txd + + // UART1 use Timer2 +// T2L = (65536 - (fosc / 4 / baud)) & 0xFF; +// T2H = (65536 - (fosc / 4 / baud)) >> 8; + + SM0 = 0; + SM1 = 1; // serial mode 1: 8-bit async + AUXR |= 0x14; // T2R: run T2, T2x12: T2 clk src sysclk/1 + AUXR |= 0x01; // S1ST2: T2 is baudrate generator + SCON = 0x50; + +/* ES = 1; // enable uart1 interrupt + EA = 1; // enable interrupts + REN = 1; +*/ + + +} + +