新闻中心

EEPW首页>嵌入式系统>设计应用> s3c2440串口调试函数

s3c2440串口调试函数

作者: 时间:2016-11-20 来源:网络 收藏

本文引用地址: //m.amcfsurvey.com/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个数据位,无较验,1个停止位)
  21. rUCON0=0x05;//查询方式,UART时钟源为PCLK
  22. rUFCON0=0x00;//不使用FIFO
  23. rUMCON0=0x00;//不使用流控
  24. rUBRDIV0=UART_BRD;//波特率为115200
  25. }
  26. /*
  27. *发送一个字符
  28. */
  29. voidSend_Byte(unsignedcharc)
  30. {
  31. /*等待,直到发送缓冲区中的数据已经全部发送出去*/
  32. while(!(rUTRSTAT0&TXD0READY));
  33. /*向UTXH0寄存器中写入数据,UART即自动将它发送出去*/
  34. rUTXH0=c;
  35. }
  36. /*
  37. *接收字符
  38. */
  39. unsignedcharGet_Byte(void)
  40. {
  41. /*等待,直到接收缓冲区中的有数据*/
  42. while(!(rUTRSTAT0&RXD0READY));
  43. /*直接读取URXH0寄存器,即可获得接收到的数据*/
  44. returnrURXH0;
  45. }
  46. /*
  47. *判断一个字符是否数字
  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. }



评论


技术专区

关闭