[菜农助学交流] tendence第四帖:UART读写

[复制链接]
 楼主| tendence 发表于 2011-11-19 14:52 | 显示全部楼层 |阅读模式
本帖最后由 tendence 于 2011-11-19 14:54 编辑

我的串口折腾了好久,之前久久显示不出来,看了sh007的帖子,发现把R5,R6焊掉之后就可以了,我也不是很清楚为什么。之前用的时候要先选中DTR然后再去掉,有的时候还不灵,怒了!!!
自从焊掉R5,R6之后腿不酸了,腰不疼了,吃啥啥香,玩啥啥爽,一口气爬5层楼,气都不喘一口……
接受部分用的查询方式,看三心大神的中断方式,实在没看懂,而且我觉得吧,发送完全没必要中断(如果我理解得不到位,欢迎指正)
接受部分用的中断,这个倒是很有必要,话不多说
翠花,上程序……
includes.h
//包含所有头文件
  1. #include <stdio.h>
  2. #include "NUC1xx.h"
  3. #include "DrvUART.h"
  4. #include "variables.h"
  5. #include "hw_config.h"
  6. #include "Driver\DrvGPIO.h"
  7. #include "Driver\DrvSYS.h"

hw_config.c
//配置文件


  1. #include "includes.h" //包含所需的头文件
  2. uint8_t inchar[1];
  3. uint8_t output1[]={"lease input a char\n"};
  4. uint8_t output2[]={"The char you input is:"};
  5. /*************************************************************************************
  6. ** Function name: Set_System
  7. ** Descriptions: 系统
  8. ** input parameters: 无
  9. ** output parameters: 无
  10. ** Returned value: 无
  11. *************************************************************************************/
  12. void RCC_Configuration(void);
  13. void GPIO_Configuration( void);
  14. void UART_Configuration(void );
  15. void UART_INT_HANDLE(uint32_t );

  16. void Set_System(void)
  17. {
  18. RCC_Configuration( ); //配置系统时钟

  19. GPIO_Configuration( ); //配置GPIO

  20. UART_Configuration( ); //配置UART
  21. }



  22. /*************************************************************************************
  23. ** Function name: RCC_Configuration
  24. ** Descriptions: 系统时钟源设置
  25. ** input parameters: none
  26. ** output parameters: none
  27. ** Returned value: none
  28. *************************************************************************************/
  29. void RCC_Configuration(void)
  30. {
  31. UNLOCKREG(); // 对写保护位操作时 需要一次向0x50000 0100写入 0x59,0x16,0x88,
  32. DrvSYS_SetOscCtrl(E_SYS_XTL12M, 1);//与其 SYSCLK->WRCON.XTL12M_EN = 1; 等同
  33. // PWRCON寄存器(这些寄存器在上电复位到用户解锁定之前是锁定的)除了 BIT[6]位其他位都受写保护
  34. // 解除这些需要向 0x50000 0100写入 0x59,0x16,0x88 // 令PWRCON寄存器的BITP[0]为1(即设定12M外部晶振)
  35. delay_ms(100); //while (DrvSYS_GetChipClockSourceStatus(E_SYS_XTL12M) != 1);//等待外部12MHZ晶振就绪
  36. LOCKREG(); // 向“0x5000_0100”写入任何值,就可以重锁保护寄存器
  37. }
  38. /*************************************************************************************
  39. ** Function name: GPIO_Configuration
  40. ** Descriptions: 端口配置
  41. ** input parameters: none
  42. ** output parameters: none
  43. ** Returned value: none
  44. *************************************************************************************/
  45. void GPIO_Configuration()
  46. {
  47. // DrvGPIO_Open( E_GPA, 2, E_IO_OUTPUT );
  48. // DrvGPIO_Open( E_GPA, 3, E_IO_OUTPUT );
  49. // DrvGPIO_Open( E_GPA, 4, E_IO_OUTPUT );
  50. //DrvGPIO_Open( E_GPA, 5, E_IO_OUTPUT );
  51. }

  52. /*************************************************************************************
  53. ** Function name: delay_ms
  54. ** Descriptions: 1ms(晶振为12MHZ)延时子程序
  55. ** input parameters: count
  56. ** output parameters: 无
  57. ** Returned value: 无
  58. *************************************************************************************/
  59. void UART_Configuration()
  60. {
  61. STR_UART_T param;

  62. DrvSYS_SelectIPClockSource(E_SYS_UART_CLKSRC, 0); // 使能UART时钟
  63. DrvGPIO_InitFunction(E_FUNC_UART0); // 复用功能引脚设置

  64. param.u32BaudRate = 115200; // 波特率
  65. param.u8cDataBits = DRVUART_DATABITS_8; // 数据位
  66. param.u8cStopBits = DRVUART_STOPBITS_1; // 停止位
  67. param.u8cParity = DRVUART_PARITY_NONE; // 校验位
  68. param.u8cRxTriggerLevel = DRVUART_FIFO_1BYTES; // FIFO存储深度 1 字节
  69. param.u8TimeOut = 0; // FIFO超时设定
  70. DrvUART_Open(UART_PORT0, ¶m); // 串口开启、结构体整体赋值
  71. DrvUART_EnableInt(UART_PORT0, DRVUART_RDAINT,UART_INT_HANDLE); //接收数据中断

  72. }

  73. void delay_ms(uint32_t count)
  74. {
  75. uint32_t i,j;
  76. for(i=count;i>0;i--)
  77. for(j=2395;j>0;j--);
  78. }
  79. void UART_INT_HANDLE(uint32_t u32IntStatus)
  80. {
  81. if(u32IntStatus & DRVUART_RDAINT)
  82. {
  83. /* Get all the input characters */
  84. //DrvUART_Write(UART_PORT0,output1,sizeof(output1));
  85. while(UART0->ISR.RDA_IF==1)
  86. {
  87. DrvUART_Read(UART_PORT0,inchar,1);
  88. DrvUART_Write(UART_PORT0,output2,sizeof(output2));
  89. delay_ms(50); /* 保存输入按键 */
  90. DrvUART_Write(UART_PORT0,inchar,1);
  91. delay_ms(50);
  92. DrvUART_Write(UART_PORT0,"\n",1);
  93. delay_ms(50);
  94. DrvUART_Write(UART_PORT0,output1,sizeof(output1));
  95. }
  96. }
  97. }

main.c

  1. #include"includes.h"
  2. uint8_t output3[]={"lease input a char\n"};
  3. uint8_t show[]={"21ic test uart0!\n"};
  4. int main (void)
  5. {
  6. Set_System();
  7.     DrvUART_Write(UART_PORT0,show,sizeof(show));
  8. delay_ms(500);
  9. DrvUART_Write(UART_PORT0,output3,sizeof(output3));
  10. delay_ms(500);
  11. while(1)
  12. {
  13.   delay_ms(500);
  14. };
  15. }
工程文件

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

×
 楼主| tendence 发表于 2011-11-19 14:58 | 显示全部楼层
有图有真相

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

×
hotpower 发表于 2011-11-19 15:33 | 显示全部楼层
有进步
 楼主| tendence 发表于 2011-11-19 16:26 | 显示全部楼层
3# hotpower
其实我也是这么想的
 楼主| tendence 发表于 2011-11-19 22:23 | 显示全部楼层
谢谢菜农的裤子
sh007 发表于 2011-11-20 10:04 | 显示全部楼层
哈哈!恭喜LZ 一口气爬五楼了!
 楼主| tendence 发表于 2011-11-20 10:19 | 显示全部楼层
6# sh007
谢谢你的建议啊!拿掉了R5,R6
您需要登录后才可以回帖 登录 | 注册

本版积分规则

个人签名:把技术记在心里

1

主题

164

帖子

0

粉丝
快速回复 在线客服 返回列表 返回顶部
个人签名:把技术记在心里

1

主题

164

帖子

0

粉丝
快速回复 在线客服 返回列表 返回顶部