30 lines
649 B
C
30 lines
649 B
C
#include "mc8051fun.h"
|
|
|
|
//#include <stc12.h>
|
|
#include <at89c51ed2.h>
|
|
|
|
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;
|
|
*/
|
|
|
|
|
|
}
|
|
|
|
|