lpc2103串口查询发送出现乱码
波特率:9600
奇偶校验:奇校验
FIFO:设置8位数据
停止位:1位
查询发送:0123456789
(串口调试工具也是这样设置的)
但是出来的全是汉字
程序如下:
#include "lpc2103.h"
typedef unsigned char uint8;
typedef unsigned int uint32;
typedef unsigned short uint16;
#define FPCLK 11059200
#define uart_bps 9600
#define led 1<<17
void delay(unsigned int dly)
{ unsigned int i;
for(; dly>0; dly--)
for(i=0; i<50000; i++);
}
void uart0_sendbyte(unsigned char data)
{ U0THR = data; // 发送数据
while( (U0LSR&0x40)==0 ); // 等待数据发送完
}
void uart0_sendstr(unsigned char const *str)
{
uint32 i;
for(i=0;i<10;i++,str++)
{
uart0_sendbyte(*str); // 发送数据
IOCLR=led;
delay(20);
IOSET=led;
delay(20);
}
}
void uart0_int(void)
{ unsigned short int fdiv;
U0LCR = 0x8b; // DLAB = 1,可设置波特率
fdiv = (FPCLK/16)/uart_bps;
U0DLM= fdiv/256;
U0DLL =fdiv%256;
U0LCR = 0x0b; // DLAB = 0,锁定置波特率
}
int main(void)
{ unsigned char const send_string[] = "0123456789";
PINSEL0 = 0x00000005; // 设置I/O连接到UART0
PINSEL1 = PINSEL1&led;
IODIR = led;
IOSET = led;
uart0_int();
while(1)
{
uart0_sendstr(send_string);
}
}
请高手们指点下,小弟我刚开始学,见笑了~~~ |