void InitialUART0_Timer1(UINT32 u32Baudrate) //T1M = 1, SMOD = 1 { SCON = 0x52; //UART0 Mode1,REN=1,TI=1 TMOD |= 0x20; //Timer1 Mode1
set_SMOD; //UART0 Double Rate Enable set_T1M; clr_BRCK; //Serial port 0 baud rate clock source = Timer1
#ifdef FOSC_160000 //TH1 = 256 - (1000000/u32Baudrate+1); /*16 MHz */ TH1 = 256 - (1036750/u32Baudrate+1); /*16.588 MHz */ //TH1 = 256 - (1037500/u32Baudrate+1); /*16.6 MHz */
#endif #ifdef FOSC_221184 TH1 = 256 - (1382400/u32Baudrate); /*22.1184 MHz */ #endif set_TR1; } void InitialUART1_Timer3(UINT32 u32Baudrate) //use timer3 as Baudrate generator { P02_Quasi_Mode; //Setting UART pin as Quasi mode for transmit P16_Quasi_Mode; //Setting UART pin as Quasi mode for transmit
SCON_1 = 0x50; //UART1 Mode1,REN_1=1,TI_1=1 T3CON = 0x08; //T3PS2=0,T3PS1=0,T3PS0=0(Prescale=1), UART1 in MODE 1 clr_BRCK;
#ifdef FOSC_160000 //RH3 = HIBYTE(65536 - (1000000/u32Baudrate)-1); /*16 MHz */ //RL3 = LOBYTE(65536 - (1000000/u32Baudrate)-1); /*16 MHz */
RH3 = HIBYTE(65536 - (1037500/u32Baudrate)); /*16.6 MHz */ RL3 = LOBYTE(65536 - (1037500/u32Baudrate)); /*16.6 MHz */
#endif #ifdef FOSC_166000 RH3 = HIBYTE(65536 - (1037500/u32Baudrate)); /*16.6 MHz */ RL3 = LOBYTE(65536 - (1037500/u32Baudrate)); /*16.6 MHz */ #endif set_TR3; //Trigger Timer3 } |