免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 867 | 回复: 0
打印 上一主题 下一主题

44b0串口编程 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-12-23 03:03 |只看该作者 |倒序浏览

①串口的编程很简单,设置好四个引脚就好了

  1. rPCONE |= (2<<2)|(2<<4); //rxd txd

  2.            //rPCONE |= (0x01<<2)|(0x01<<4); //rxd txd 第一次竟然写成了这个

  3.            rPDATG &= ~BIT1; //RTS 为0请求接收;

  4.            rPCONG |= (1<<2);


这样串口就能通讯了

②中断方式发送数据
    设置要点:串口寄存器,中断寄存器,中断函数

  1. rULCON0=0x3; //Normal,No parity,1 stop,8 bit

  2.     rUCON0=0x045; //0000,0100,0101。rx=edge,tx=level,disable timeout int.,enable rx error int.,normal,interrupt or polling


  3. Uart_Printf("\nTest begin:!");
  4. uart0TxStr="UART0 Tx interrupt test is good!!!!\r\n";

  5. pISR_UTXD0 = (unsigned)Uart0_TxInt;
  6. rINTCON = 0;
  7. rINTMSK =~ (BIT_GLOBAL|BIT_UTXD0);
  8. rINTMOD = 0;

 

③DMA方式发送数据
    设置要点:串口寄存器,DMA寄存器

  1. rUCON0 = 0x245; //for BDMA0


  2. Uart_Printf("\n[Uart0 Tx Test by BDMA0]\n");
  3. uart0TxStr="UART0 Tx Test by BDMA0 is good!!!!\r\n";
  4. //Uart_TxEmpty(0);


  5. rUCON0=0x48; //tx:BDMA0 rx:disable


  6. rBDICNT0=0x0;
  7. rBDCON0 =0x0;
  8. rBDISRC0=(unsigned int)uart0TxStr|(0<<30)|(1<<28); // byte,inc

  9. rBDIDES0=UTXH0 |(1<<30)|(3<<28); //L/B endian,M2IO,fix

  10. rBDICNT0=strlen((char *)uart0TxStr)|(2<<30)|(1<<26)|(0<<20); //UART0,

  11. rBDICNT0 |= (1<<20); //enable

  12. rBDCON0 = (0x0<<2);

              

您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP