From 726a76eeffe70a3eb5593f21e353bc1df62348c3 Mon Sep 17 00:00:00 2001 From: 7u83 <7u83@mail.ru> Date: Fri, 17 May 2024 23:49:24 +0200 Subject: [PATCH] Inital commit --- uart_init.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 uart_init.c 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; +*/ + + +} + +