本帖最后由 张耀九123 于 2010-8-16 17:52 编辑
我求助向来都给分,答对了就给分,除非被领完了,答得好也有评分。
今次遇到UART口->;PC(收不到数据)。用的完全是范例Smpl_UART2PC.zip,奇怪咯。
/*---------------------------------------------------------------------------------------------------------*/
/* Routine to write a char */
/*---------------------------------------------------------------------------------------------------------*/
void SendChar(int ch)
{
while(UART0->FSR.TX_FULL == 1);
UART0->DATA = ch;
//if(ch == '\n')
//{
// while(UART0->FSR.TX_FULL == 1);
// UART0->DATA = '\r';
}
}
/*---------------------------------------------------------------------------------------------------------*/
/* Routine to get a char */
/*---------------------------------------------------------------------------------------------------------*/
char GetChar()
{
while (1)
{
if(UART0->FSR.RX_EMPTY == 0 )
{
return (UART0->DATA);
}
}
}
int32_t main (void)
{
/* Step 1. GPIO initial */
SYS->GPBMFP.UART0_RX =1;
SYS->GPBMFP.UART0_TX =1;
/* Step 2. Enable and Select UART clock source*/
UNLOCKREG();
SYSCLK->;PWRCON.XTL12M_EN = 1;
LOCKREG();
SYSCLK->APBCLK.UART0_EN = 1;//Enable UART clock
SYSCLK->CLKSEL1.UART_S = 0; //Select 12Mhz for UART clock source
SYSCLK->CLKDIV.UART_N = 0; //UART clock source = 12Mhz;
/* Step 3. Select Operation mode */
UART0->FCR.TFR =1; //Reset Tx FIFO
UART0->FCR.RFR =1; //Reset Rx FIFO
UART0->FCR.RFITL = 0;//Set Rx Trigger Level -1byte FIFO
UART0->LCR.PBE = 0;//Disable parity
UART0->LCR.WLS = 3;//8 data bits
UART0->LCR.NSB = 0;//Enable 1 Stop bit
/* Step 4. Set BaudRate */
UART0->BAUD.DIVX_EN = 1;
UART0->BAUD.DIVX1 = 1;
UART0->BAUD.DIV = 12000000 / 115200 -2;
do
{
printf("\nUART Sample Demo. (Press 'ESC' to exit)\n");
SendChar(0x55);
}while(GetChar()!=0x1B);
printf("Exit\n");
} |