新聞中心

EEPW首頁 > 嵌入式系統(tǒng) > 設計應用 > s3c2440串口調試函數(shù)

s3c2440串口調試函數(shù)

作者: 時間:2016-11-20 來源:網絡 收藏

本文引用地址:http://butianyuan.cn/article/201611/318936.htm
  1. #include"2440addr.h"
  2. #include
  3. #include
  4. #include
  5. #include
  6. #include
  7. #defineTXD0READY(1<<2)
  8. #defineRXD0READY(1)
  9. #defineUART_CLK50000000//UART0的時鐘源設為PCLK
  10. #defineUART_BAUD_RATE115200//波特率
  11. #defineUART_BRD((UART_CLK/(UART_BAUD_RATE*16))-1)
  12. /*
  13. *初始化UART0
  14. *115200,8N1,無流控
  15. */
  16. voidUart0_Init(void)
  17. {
  18. rGPHCON|=0xa0;//GPH2,GPH3用作TXD0,RXD0
  19. rGPHUP=0x0c;//GPH2,GPH3內部上拉
  20. rULCON0=0x03;//8N1(8個數(shù)據位,無較驗,1個停止位)
  21. rUCON0=0x05;//查詢方式,UART時鐘源為PCLK
  22. rUFCON0=0x00;//不使用FIFO
  23. rUMCON0=0x00;//不使用流控
  24. rUBRDIV0=UART_BRD;//波特率為115200
  25. }
  26. /*
  27. *發(fā)送一個字符
  28. */
  29. voidSend_Byte(unsignedcharc)
  30. {
  31. /*等待,直到發(fā)送緩沖區(qū)中的數(shù)據已經全部發(fā)送出去*/
  32. while(!(rUTRSTAT0&TXD0READY));
  33. /*向UTXH0寄存器中寫入數(shù)據,UART即自動將它發(fā)送出去*/
  34. rUTXH0=c;
  35. }
  36. /*
  37. *接收字符
  38. */
  39. unsignedcharGet_Byte(void)
  40. {
  41. /*等待,直到接收緩沖區(qū)中的有數(shù)據*/
  42. while(!(rUTRSTAT0&RXD0READY));
  43. /*直接讀取URXH0寄存器,即可獲得接收到的數(shù)據*/
  44. returnrURXH0;
  45. }
  46. /*
  47. *判斷一個字符是否數(shù)字
  48. */
  49. intisDigit(unsignedcharc)
  50. {
  51. if(c>=0&&c<=9)
  52. return1;
  53. else
  54. return0;
  55. }
  56. /*
  57. *判斷一個字符是否英文字母
  58. */
  59. intisLetter(unsignedcharc)
  60. {
  61. if(c>=a&&c<=z)
  62. return1;
  63. elseif(c>=A&&c<=Z)
  64. return1;
  65. else
  66. return0;
  67. }
  68. voidUart0_SendString(char*pt)
  69. {
  70. while(*pt)
  71. {
  72. Send_Byte(*pt++);
  73. }
  74. }
  75. voidUart_Printf(char*fmt,...)
  76. {
  77. va_listap;
  78. charstring[256];
  79. va_start(ap,fmt);
  80. vsprintf(string,fmt,ap);
  81. Uart0_SendString(string);
  82. va_end(ap);
  83. }



評論


技術專區(qū)

關閉