Chinaunix首页 | 论坛 | 博客
  • 博客访问: 396453
  • 博文数量: 380
  • 博客积分: 75
  • 博客等级: 民兵
  • 技术积分: 1925
  • 用 户 组: 普通用户
  • 注册时间: 2011-09-05 15:35
文章分类

全部博文(380)

文章存档

2014年(1)

2013年(2)

2012年(19)

2011年(358)

我的朋友

分类:

2011-09-24 10:39:32

原文地址:44b0串口编程 作者:ehyyngp

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

  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);

              

阅读(209) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~