欢迎来到天天文库
浏览记录
ID:57631811
大小:13.71 KB
页数:5页
时间:2020-08-29
《UART串口通信程序.docx》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、1、UART串口通信voidDelay(inttt){U32i;for(;tt>0;tt--){for(i=0;i<10000;i++){}}}voidUart_SendByte(intdata){intwhichUart=0;if(whichUart==0){if(data==''){while(!(rUTRSTAT0&0x2));Delay(1);//becausetheslowresponseofhyper_terminalWrUTXH0('r');}while(!(rUTRSTAT0&0x2))
2、;//WaituntilTHRisempty.Delay(1);5WrUTXH0(data);}}voiduart_init(intpclk,intbaud){inti;if(pclk==0)pclk=PCLK;rUFCON0=0x0;rUCON0=0x245;rUMCON0=0x0;rULCON0=0x3;rUBRDIV0=((int)(pclk/16./baud+0.5)-1);for(i=0;i<100;i++);Delay(400);}charUart_Getch(void){while(!(rUTR
3、STAT0&0x1));//ReceivedatareadyreturnRdURXH0();}5voidUart_TxEmpty(intch){if(ch==0){while(!(rUTRSTAT0&0x4));}}voidUart_SendString(char*pt){while(*pt)Uart_SendByte(*pt++);}voidUart_Printf(char*fmt,...){va_listap;charstring[256];va_start(ap,fmt);vsprintf(string
4、,fmt,ap);Uart_SendString(string);va_end(ap);5}intMain(intargc,char**argv){//intdata;charch;U8key;U32mpll_val=0;mpll_val=(92<<12)
5、(1<<4)
6、(1);ChangeMPllValue((mpll_val>>12)&0xff,(mpll_val>>4)&0x3f,mpll_val&3);ChangeClockDivider(key,12);MMU_DisableICache();MMU
7、_DisableDCache();rGPBCON=0x155555;rGPHCON=0x00faaa;rGPHUP=0x7ff;uart_init(0,115200);Uart_Printf("Pleaseenterchar:");ch=Uart_Getch();Uart_Printf("");5Uart_SendByte(ch);while(1){Uart_SendByte(ch);Uart_SendByte(',');ch++;Delay(100);}return0;}5
此文档下载收益归作者所有