打印

新手求助 LPC2368 串口通信

[复制链接]
1543|3
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
zjk0728|  楼主 | 2013-1-11 13:49 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
沙发
huangxz| | 2013-1-11 13:59 | 只看该作者
lpc23xx跟lpc21xx 很多不一样的

#include <LPC23xx.H>                    /* LPC24xx definitions               */

/*----------------------------------------------------------------------------
*       init_serial:  Initialize Serial Interface
*---------------------------------------------------------------------------*/
void init_serial (void) {
   /* Initialize the serial interface */

   /* Configure UART0 for 115200 baud. */
   PINSEL0 &= ~(3 << 4);
   PINSEL0 |=  1 << 4;                   /* Enable TxD0 pin              */
   PINSEL0 &= ~(3 << 6);
   PINSEL0 |=  1 << 6;                   /* Enable RxD0 pin              */

   U0LCR = 0x83;                             /* 8 bits, no Parity, 1 Stop bit*/
   U0DLL = 26;                                /* for 11.0592MHz PCLK Clock         */
//   U0FDR = 0x67;                             /* Fractional Divider           */
   U0LCR = 0x03;                             /* DLAB = 0                     */
}

/*----------------------------------------------------------------------------
*       sendchar:  Write a character to Serial Port
*---------------------------------------------------------------------------*/
int sendchar (int ch) {
   if (ch == '\n') {
      while (!(U0LSR & 0x20));
      U0THR = '\r';
   }
   while (!(U0LSR & 0x20));
   return (U0THR = ch);
}

/*----------------------------------------------------------------------------
*       getkey:  Read a character from Serial Port
*---------------------------------------------------------------------------*/
int getkey (void) {
   while (!(U0LSR & 0x01));
   return (U0RBR);
}

/*----------------------------------------------------------------------------
*       RxDataReady:  if U1RBR contains valid data reurn 1, otherwise 0
*---------------------------------------------------------------------------*/
int RxDataReady( void )
{
        return ( U0LSR & 0x01 );        //Receive data ready
        //return ( U0LSR & 0x01 );        //Receive data ready
}

/*----------------------------------------------------------------------------
* end of file
*---------------------------------------------------------------------------*/

哦.

使用特权

评论回复
评分
参与人数 1威望 +1 收起 理由
zjk0728 + 1 赞一个!
板凳
ceac1| | 2013-1-11 14:08 | 只看该作者
关注一下了

使用特权

评论回复
地板
zjk0728|  楼主 | 2013-1-11 14:18 | 只看该作者
huangxz 发表于 2013-1-11 13:59
lpc23xx跟lpc21xx 很多不一样的哦.

谢谢你的回复和代码,我再试试

使用特权

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

本版积分规则

1

主题

1

帖子

0

粉丝