本帖最后由 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));
那么运行结果如何呢????下面是截图:
为了造福后来人,也为了保存一下,我把程序传上来。
- /**
- * \file
- *
- * \brief Empty user application template
- *
- */
- /**
- * \mainpage User Application template doxygen documentation
- *
- * \par Empty user application template
- *
- * This is a bare minimum user application template.
- *
- * For documentation of the board, go \ref group_common_boards "here" for a link
- * to the board-specific documentation.
- *
- * \par Content
- *
- * -# Include the ASF header files (through asf.h)
- * -# Minimal main function that starts with a call to system_init()
- * -# Basic usage of on-board LED and button
- * -# "Insert application code here" comment
- *
- */
- /*
- * Include header files for all drivers that have been imported from
- * Atmel Software Framework (ASF).
- */
- #include <asf.h>
- #include <stdio_serial.h>
- void configure_usart(void);
- struct usart_module usart_instance;
- void configure_usart(void)
- {
- struct usart_config config_usart;
- usart_get_config_defaults(&config_usart);
- config_usart.baudrate = 9600;
- config_usart.mux_setting = EXT3_UART_SERCOM_MUX_SETTING;
- config_usart.pinmux_pad0 = EXT3_UART_SERCOM_PINMUX_PAD0;
- config_usart.pinmux_pad1 = EXT3_UART_SERCOM_PINMUX_PAD1;
- config_usart.pinmux_pad2 = EXT3_UART_SERCOM_PINMUX_PAD2;
- config_usart.pinmux_pad3 = EXT3_UART_SERCOM_PINMUX_PAD3;
-
- while (usart_init(&usart_instance, EXT3_UART_MODULE, &config_usart) != STATUS_OK)
- { }
- stdio_serial_init(&usart_instance, EXT3_UART_MODULE, &config_usart);
- usart_enable(&usart_instance);
- }
- int main (void)
- {
- system_init();
- configure_usart();
- uint8_t string[] = "Hello World!\r\n";
- uint8_t mystring = 0x55;
- int i=30122121;
- long int i2 = 30122121;
-
-
- usart_write_buffer_wait(&usart_instance, string, sizeof(string));
- uint16_t temp;
- while (true)
- {
- usart_write_buffer_wait(&usart_instance, &mystring, sizeof( mystring));
- printf("\n");
- printf("How are youj!!!! \r\n");
- 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));
- if (usart_read_wait(&usart_instance, &temp) == STATUS_OK)
- { while (usart_write_wait(&usart_instance, temp) != STATUS_OK)
- { }
- }
- }
- }
有的看官会问,你怎么不用EDBG而用USB转串口呢?答案很简单,我的WIN8不支持那个EDBG虑拟出的串口,但其余功能好用。只是少了个串口,我就加了一个,现在看来效果很好。
串口调通了意义很重大,我可以把它当一个调试器,程序走到哪里,我就打一句话。等我把所有的话说完了程序也调出来了。呵呵,这是个很好的办法,不信你试试。
以后还有更多的内容要跑一下。欲知后事如何且看下文分解!
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?注册
×
|