for(i=0;i<Rx_cnt;i++) UartPutc(DMABuffer[i]);
printf("\r\n");
Rx_cnt = 0;
DMA_UR1R_CR = 0xa1; //bit7 1:Enable UART1_DMA,
//bit5 1:Start UART1_DMA automatic reception,
//bit0 1:clear FIFO
}
}
}
}
}
void DMA_Config(void)
{
P_SW2 = 0x80;
DMA_UR1T_CFG = 0x80; //bit7 1:Enable Interrupt
DMA_UR1T_STA = 0x00;
DMA_UR1T_AMT = DMA_AMT_LEN; //Set total bytes to be transferred
:
n+1
DMA_UR1T_TXA = DMABuffer;
DMA_UR1T_CR = 0xc0; //bit7 1:Enable UART1_DMA,
//bit6 1:Start UART1_DMA automatic transmission
DMA_UR1R_CFG = 0x80; //bit7 1:Enable Interrupt
DMA_UR1R_STA = 0x00;
DMA_UR1R_AMT = DMA_AMT_LEN; //Set total bytes to be transferred
:
n+1
DMA_UR1R_RXA = DMABuffer;
DMA_UR1R_CR = 0xa1; //bit7 1:Enable UART1_DMA,
//bit5 1:Start UART1_DMA automatic reception,
//bit0 1:clear FIFO
}
void SetTimer2Baudraye(u16 dat)
{
AUXR &= ~(1<<4); //Timer stop
AUXR &= ~(1<<3); //Timer2 set As Timer
AUXR |= (1<<2); //Timer2 set as 1T mode
T2H = dat / 256;
T2L = dat % 256;
IE2 &= ~(1<<2); //Disable interrupts
AUXR |= (1<<4); //Timer run enable
}
void UART1_config(u8 brt) //select baud rate:
//2: Use Timer2 as baud rate generator,
//Other values: Use Timer1 as baud rate generator.
{
/*********** Use Timer2 as baud rate generator *****************/
if(brt == 2)
{
AUXR |= 0x01; //S1 BRT Use Timer2;
SetTimer2Baudraye(65536UL - (MAIN_Fosc / 4) / Baudrate1);
}
/*********** Use Timer1 as baud rate generator *****************/
else
{