[Atmel] 跑一下XMEGA-B1程序(15)USART字符串

[复制链接]
 楼主| ddllxxrr 发表于 2016-1-13 18:10 | 显示全部楼层 |阅读模式
这个接着昨天的程序,很简单就是加了个输出字符串的函数:

usart_serial_write_packet(USART_SERIAL, "Test String", strlen("Test String"));

strlen刚编译时过不去,就说没有定义:

在头文件加上#include <string.h>

就可以了。

以下是程序:

  1. #include <asf.h>
  2. #include <string.h>



  3. #define USART_SERIAL                     &USARTC0
  4. #define USART_SERIAL_BAUDRATE            9600
  5. #define USART_SERIAL_CHAR_LENGTH         USART_CHSIZE_8BIT_gc
  6. #define USART_SERIAL_PARITY              USART_PMODE_DISABLED_gc
  7. #define USART_SERIAL_STOP_BIT            false
  8. uint8_t received_byte;
  9. uint8_t hello[18];

  10. int main (void)
  11. {
  12.         /* Insert system clock initialization code here (sysclk_init()). */
  13.         
  14.         
  15.         sysclk_init();
  16.         
  17.         ioport_configure_pin(IOPORT_CREATE_PIN(PORTC,3), IOPORT_DIR_OUTPUT
  18.         |IOPORT_INIT_HIGH);
  19.         ioport_configure_pin(IOPORT_CREATE_PIN(PORTC,2), IOPORT_DIR_INPUT);
  20.         
  21.         static usart_serial_options_t usart_options = {
  22.                 .baudrate = USART_SERIAL_BAUDRATE,
  23.                 .charlength = USART_SERIAL_CHAR_LENGTH,
  24.                 .paritytype = USART_SERIAL_PARITY,
  25.                 .stopbits = USART_SERIAL_STOP_BIT
  26.         };
  27.         
  28.         
  29.         //usart_serial_init(USART_SERIAL, &usart_options);
  30.         usart_init_rs232(USART_SERIAL,&usart_options);
  31.         
  32.         
  33.         
  34.         while(1)
  35.         {
  36.         usart_serial_write_packet(USART_SERIAL, "Test String", strlen("Test String"));
  37.         
  38.                
  39.         }
  40.         /* Insert application code here, after the board has been initialized. */
  41. }


我运行了一下,可以输出不变的十六进制。我打到文本时也许我的3VU转串不太了。是一种规则的乱码。


dirtwillfly 发表于 2016-1-14 14:38 | 显示全部楼层
给力的分享
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

2403

主题

6994

帖子

68

粉丝
快速回复 在线客服 返回列表 返回顶部
个人签名:http://shop34182318.taobao.com/ http://shop562064536.taobao.com

2403

主题

6994

帖子

68

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