最近本人编写了一个简单串口程序,只是发送,PC的软件接收。但是几天下来,都不成功,调试时PC软件根本接收不到,汗 !!!
现在把代码贴出来,请大家帮忙指点。
#include "2410addr.h"
void Delay(int NUM) {
int i;
for(i=NUM;i>0;i--);
}
//************************************************************************************************
void Clock_Init() {
rCLKCON = 0x7fff0;
rCLKDIVN = 0x03; //HCLK=FCLK/2 ; PCLK=HCLK/2
rMPLLCON = 0x520101; //MPLL ouput F=180MHz
}
//************************************************************************************************
void Port_Init(void) {
//*** PORT H GROUP
//Ports : GPH10 GPH9 GPH8 GPH7 GPH6 GPH5 GPH4 GPH3 GPH2 GPH1 GPH0
//Signal : CLKOUT1 CLKOUT0 UCLK nCTS1 nRTS1 RXD1 TXD1 RXD0 TXD0 nRTS0 nCTS0
//Binary : 10 , 10 10 , 11 11 , 10 10 , 10 10 , 10 10
rGPHCON = 0xa0; //0x2afaaa;
//rGPHUP = 0x7ff; // The pull up function is disabled GPH[10:0]
rGPHUP = 0x00;
}
//************************************************************************************************
void Uart_Init(int pclk,int baud) {
//uart0
rULCON0 = 0x3; //Line control register : Normal,No parity,1 stop,8 bits
// [10] [9] [8] [7] [6] [5] [4] [3:2] [1:0]
// Clock Sel, Tx Int, Rx Int, Rx Time Out, Rx err, Loop-back, Send break, Transmit Mode, Receive Mode
// 0 1 0 , 0 1 0 0 , 01 01
// PCLK Level Pulse Disable Generate Normal Normal Interrupt or Polling
rUCON0 = 0x345; // Control register
//rUBRDIV0=( (int)(pclk/16./baud) -1 ); //Baud rate divisior register 0
rUBRDIV0=( (int)(pclk/16.0/baud+0.5) -1 ); //Baud rate divisior register 0
// pclk = PCLK;
rUFCON0 = 0x00; //UART channel 0 FIFO control register, FIFO disable
rUMCON0 = 0x0; //UART chaneel 0 MODEM control register, AFC disable
}
//************************************************************************************************
void putc(unsigned char ch) {
while (!(rUTRSTAT0 & 0x02)); //wait until TBR is empty
Delay(100);
WrUTXH0(ch);
}
char getc() {
while (! (rUTRSTAT0 & 0x01)); //wait until receive data ready
Delay(100);
return RdURXH0();
}
//************************************************************************************************
int main() {
Clock_Init();
Port_Init();
Delay(1000);
Uart_Init(180000000,115200);
while(1)
putc(0x10);
}