If Keil arm is used, vpbdiv = 0x00000000 is automatically generated in startup. S, which leads to fpclk dividing by 4. The baud rate is reduced by four times. The default value of startup. s in Keil is as follows .; // <E> vpbdiv setup
; // <I> Peripheral Bus clock rate
; // <O1.0.. 1> vpbdiv: VPB clock
; // <0 => VPB clock = CPU clock/4
; // <1 => VPB clock = CPU clock
; // <2 => VPB clock = CPU clock/2
; // <O1.4.. 5> xclkdiv: xclk pin
; // <0 => xclk pin = CPU clock/4
; // <1 => xclk pin = CPU clock
; // <2 => xclk pin = CPU clock/2
; // </E>
Vpbdiv_setup equ 0vpbdiv_val equ 0x00000000 we will change it:
Vpbdiv_setup equ 1
Vpbdiv_val equ 0x00000001
Solve the problem.
- # Include <lpc20.x. h>
- # Include "config. H"
- # Define uart_baud (baud) (unsigned INT) (fosc * pll_m)/(baud * 16 ))
- Void init_uart0 (unsigned int baud)
- {
- /* Initialize the serial interface */
- Pinsel0 = 0x00000005;/* enable rxd0 and txd0 */
- U0lcr = 0x83;/* 8 bits, no parity, 1 stop bit */
- U0dlm = (unsigned char) (baud> 8 );
- U0dll = (unsigned char) baud;
- U0lcr = 0x03;/* dlab = 0 */
- }
- Void delay (unsigned int I) {/* Delay function */
- Unsigned int N;
- While (I> 1)
- {
- For (n = 65535; n> 1; n --);
- I --;
- }
- }
- Void sent_byte (unsigned char data)
- {
- U0thr = data; // send data
- While (u0lsr & 0x40) = 0); // wait for the data to be sent
- }
- Void sent_str (unsigned char const * Str)
- {While (1)
- {If (* STR = '/0') break;
- Sent_byte (* STR ++); // send data
- }
- }
- Void main (void)
- {
- Init_uart0 (uart_baud (115200 ));
- For (;;)
- {
- Sent_str ("www.dnp.cn/N ");
- Delay (200 );
- }
- }