①串口的编程很简单,设置好四个引脚就好了
- rPCONE |= (2<<2)|(2<<4); //rxd txd
- //rPCONE |= (0x01<<2)|(0x01<<4); //rxd txd 第一次竟然写成了这个
- rPDATG &= ~BIT1; //RTS 为0请求接收;
- rPCONG |= (1<<2);
这样串口就能通讯了
②中断方式发送数据
设置要点:串口寄存器,中断寄存器,中断函数
- rULCON0=0x3; //Normal,No parity,1 stop,8 bit
- rUCON0=0x045; //0000,0100,0101。rx=edge,tx=level,disable timeout int.,enable rx error int.,normal,interrupt or polling
- Uart_Printf("\nTest begin:!");
- uart0TxStr="UART0 Tx interrupt test is good!!!!\r\n";
- pISR_UTXD0 = (unsigned)Uart0_TxInt;
- rINTCON = 0;
- rINTMSK =~ (BIT_GLOBAL|BIT_UTXD0);
- rINTMOD = 0;
③DMA方式发送数据
设置要点:串口寄存器,DMA寄存器
- rUCON0 = 0x245; //for BDMA0
- Uart_Printf("\n[Uart0 Tx Test by BDMA0]\n");
- uart0TxStr="UART0 Tx Test by BDMA0 is good!!!!\r\n";
- //Uart_TxEmpty(0);
- rUCON0=0x48; //tx:BDMA0 rx:disable
- rBDICNT0=0x0;
- rBDCON0 =0x0;
- rBDISRC0=(unsigned int)uart0TxStr|(0<<30)|(1<<28); // byte,inc
- rBDIDES0=UTXH0 |(1<<30)|(3<<28); //L/B endian,M2IO,fix
- rBDICNT0=strlen((char *)uart0TxStr)|(2<<30)|(1<<26)|(0<<20); //UART0,
- rBDICNT0 |= (1<<20); //enable
- rBDCON0 = (0x0<<2);
阅读(296) | 评论(0) | 转发(0) |