typedef __xdata struct
{
unsigned char SRCADDRH; //源地址高8位
unsigned char SRCADDRL; //源地址低8位
unsigned char DESTADDRH; //目的地址高8位
unsigned char DESTADDRL; //目的地址低8位
unsigned char VLEN :3; //长度域模式选择
unsigned char LENH :5; //传输长度高字节
unsigned char LENL :8; //传输长度低字节
unsigned char WORDSIZE :1; //字节(byte)或字(word)传输
unsigned char TMODE :2; //传输模式选择
unsigned char TRIG :5; //触发事件选择
unsigned char SRCINC :2; //源地址增量:-1/0/1/2
unsigned char DESTINC :2; //目的地址增量:-1/0/1/2
unsigned char IRQMASK :1; //中断屏蔽
unsigned char M8 :1; //7或8bit传输长度,仅在字节传输模式下适用
unsigned char PRIORITY :2; //优先级
}DMA_CFG;
//实验说明:将字符数组sourceString的内容通过DMA传输到字符数组destString中,转换结果通过串口显示到PC上。
void main(void)//
{
DMA_CFG dmaConfig; //定义配置结构体
unsigned char sourceString[]="I'm the sourceString!\r\n"; //源字符串
unsigned char destString[sizeof(sourceString)]="I'm the destString!\r\n"; //目的字符串
InitLed();
initUARTtest();
UartTX_Send_String(sourceString); //传输前的原字符数组
UartTX_Send_String(destString); //传输前的目的字符数组
//配置DMA结构体
dmaConfig.SRCADDRH=(unsigned char)((unsigned short int)&sourceString >> 8); //源地址
dmaConfig.SRCADDRL=(unsigned char)((unsigned short int)&sourceString);
dmaConfig.DESTADDRH=(unsigned char)((unsigned short int)&destString >> 8); //目的地址
dmaConfig.DESTADDRL=(unsigned char)((unsigned short int)&destString);
dmaConfig.VLEN=0x00; //选择LEN作为传送长度
dmaConfig.LENH=(unsigned char)((unsigned short int)sizeof(sourceString) >> 8); //传输长度
dmaConfig.LENL=(unsigned char)((unsigned short int)sizeof(sourceString));
dmaConfig.WORDSIZE=0x00; //选择字节(byte)传送
dmaConfig.TMODE=0x01; //选择块传送(block)模式