打印

lpc2103串口查询发送出现乱码

[复制链接]
1917|3
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
米其林r|  楼主 | 2010-4-28 15:13 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
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);

   }
   
}

请高手们指点下,小弟我刚开始学,见笑了~~~

相关帖子

沙发
yoyowodeai| | 2010-4-28 15:13 | 只看该作者
请问你用的是zlg的板吗  如果是的话可能是你跳线帽没有连哈 ,连上试下嘛。我之前也是这个问题哈,后来连上就好了……

使用特权

评论回复
板凳
LPC300| | 2010-4-28 15:14 | 只看该作者
在KEIL中自动生成的startup.s 中,对PLL的调制如下:

.equ    PLL_SETUP,      1       //默认是打开的
.equ    PLLCFG_Val,     0x00000024  

/*默认的倍频值是M=4+1=5,这样如果你的外部时钟是Fosc=11.0592Mhz的话,那你的Fcclk=5*fosc;
所以要在周立公公司给的config.h 中要把#define Fcclk           (Fosc * 4) 中的4改为5.    */

使用特权

评论回复
地板
歪 歪| | 2010-4-29 12:02 | 只看该作者
用这个串口调试工具监视一下,看你的设置和数据是否和你想的一样。
注意:一定按照下面详细使用方法里说明的顺序操作。

下载地址:
http://download.cnet.com/ComTrac ... 6892.html?tag=mncol

感觉好别忘了给个review(评论),谢谢!

FAQ
How to use it?
1.Run ComTrace
2.Select serial port name(e.g. COM1)
3.Run serial port application program that you want to debug(e.g. Windows HyperTerminal)
4.debug......(e.g. press any key in Windows HyperTerminal, then watch the data that is captured.)
5.Close application program(e.g. Windows HyperTerminal)
6.Close ComTrace

Notice: You must operate by the order, only support Win2000 and WinXp(32 bit) system!

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

340

主题

1587

帖子

3

粉丝