[Atmel] 用ASF跑SAMD21程序(10)printf好用么?

[复制链接]
1597|1
 楼主| ddllxxrr 发表于 2014-12-27 06:18 | 显示全部楼层 |阅读模式
本帖最后由 ddllxxrr 于 2014-12-27 06:32 编辑

这篇接上篇,上篇调通了串口那个printf函数,这里我测一下,它好用不啦!!!!

首先一些符号得知道:

转换说明及作为结果的打印输出
a                浮点数、十六进制数字和p-记数法(C99)
%A    浮点数、十六进制数字和p-记法(C99)
%c    一个字符 
%d    有符号十进制整数 
%e    浮点数、e-记数法
%E    浮点数、E-记数法
%f    浮点数、十进制记数法  
%g    根据数值不同自动选择%f或%e
%G    根据数值不同自动选择%f或%e.
%i               有符号十进制数(与%d相同)
%o    无符号八进制整数
%p    指针    
%s    字符串
%u    无符号十进制整数
%x    使用十六进制数字0f的无符号十六进制整数 
%X    使用十六进制数字0f的无符号十六进制整数
%%    打印一个百分号
  使用printf ()函数

 printf()的基本形式: printf("格式控制字符串",变量列表)

还有一些特殊字符,比如“/r”回车换行,“/n”是空格。


那么好用不好用呢:

我加上了以下这些程序:

int i=30122121;
long int i2 = 30122121;


printf("%d,%ld\n",i,i2);
    printf("The size of uint8_t is  %d \r\n",sizeof(uint8_t));
    printf("The size of uint8_t is  %d \r\n",sizeof(uint16_t));
    printf("The size of uint8_t is  %d \r\n",sizeof(uint32_t));
    printf("The size of uint8_t is  %d \r\n",sizeof(uint64_t));
    printf("The size of uint8_t is  %d \r\n",sizeof(int8_t));


那么运行结果如何呢????下面是截图:



为了造福后来人,也为了保存一下,我把程序传上来。
  1. /**
  2. * \file
  3. *
  4. * \brief Empty user application template
  5. *
  6. */

  7. /**
  8. * \mainpage User Application template doxygen documentation
  9. *
  10. * \par Empty user application template
  11. *
  12. * This is a bare minimum user application template.
  13. *
  14. * For documentation of the board, go \ref group_common_boards "here" for a link
  15. * to the board-specific documentation.
  16. *
  17. * \par Content
  18. *
  19. * -# Include the ASF header files (through asf.h)
  20. * -# Minimal main function that starts with a call to system_init()
  21. * -# Basic usage of on-board LED and button
  22. * -# "Insert application code here" comment
  23. *
  24. */

  25. /*
  26. * Include header files for all drivers that have been imported from
  27. * Atmel Software Framework (ASF).
  28. */
  29. #include <asf.h>
  30. #include <stdio_serial.h>

  31. void configure_usart(void);
  32. struct usart_module usart_instance;

  33. void configure_usart(void)
  34. {   
  35.          struct usart_config config_usart;
  36.          usart_get_config_defaults(&config_usart);
  37.          config_usart.baudrate    = 9600;
  38.          config_usart.mux_setting = EXT3_UART_SERCOM_MUX_SETTING;
  39.          config_usart.pinmux_pad0 = EXT3_UART_SERCOM_PINMUX_PAD0;
  40.          config_usart.pinmux_pad1 = EXT3_UART_SERCOM_PINMUX_PAD1;
  41.          config_usart.pinmux_pad2 = EXT3_UART_SERCOM_PINMUX_PAD2;
  42.          config_usart.pinmux_pad3 = EXT3_UART_SERCOM_PINMUX_PAD3;
  43.          
  44.          while (usart_init(&usart_instance, EXT3_UART_MODULE, &config_usart) != STATUS_OK)
  45.           {    }
  46.           stdio_serial_init(&usart_instance, EXT3_UART_MODULE, &config_usart);
  47.           usart_enable(&usart_instance);
  48. }



  49. int main (void)
  50. {
  51.         system_init();
  52.         configure_usart();
  53.         uint8_t string[] = "Hello World!\r\n";
  54.         uint8_t mystring = 0x55;
  55.         int i=30122121;
  56.         long int i2 = 30122121;
  57.        
  58.        
  59.         usart_write_buffer_wait(&usart_instance, string, sizeof(string));
  60.         uint16_t temp;
  61.         while (true)
  62.         {
  63.                                 usart_write_buffer_wait(&usart_instance, &mystring, sizeof(        mystring));
  64.                                 printf("\n");
  65.                                 printf("How are youj!!!! \r\n");
  66.                                 printf("%d,%ld\n",i,i2);
  67.                                 printf("The size of uint8_t is  %d \r\n",sizeof(uint8_t));
  68.                                 printf("The size of uint8_t is  %d \r\n",sizeof(uint16_t));
  69.                                 printf("The size of uint8_t is  %d \r\n",sizeof(uint32_t));
  70.                                 printf("The size of uint8_t is  %d \r\n",sizeof(uint64_t));
  71.                                 printf("The size of uint8_t is  %d \r\n",sizeof(int8_t));
  72.                                 if (usart_read_wait(&usart_instance, &temp) == STATUS_OK)
  73.                 {            while (usart_write_wait(&usart_instance, temp) != STATUS_OK)
  74.                                  {            }
  75.                 }
  76.         }
  77. }

有的看官会问,你怎么不用EDBG而用USB转串口呢?答案很简单,我的WIN8不支持那个EDBG虑拟出的串口,但其余功能好用。只是少了个串口,我就加了一个,现在看来效果很好。

串口调通了意义很重大,我可以把它当一个调试器,程序走到哪里,我就打一句话。等我把所有的话说完了程序也调出来了。呵呵,这是个很好的办法,不信你试试。

以后还有更多的内容要跑一下。欲知后事如何且看下文分解!






本帖子中包含更多资源

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

×
86269838 发表于 2017-3-19 17:14 | 显示全部楼层
好用好用,受益匪浅。支持一个
您需要登录后才可以回帖 登录 | 注册

本版积分规则

个人签名:http://shop34182318.taobao.com/ http://shop562064536.taobao.com

2404

主题

7001

帖子

68

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