[Atmel] 跑一下XMEGA-B1程序(14)USART

[复制链接]
 楼主| ddllxxrr 发表于 2016-1-12 22:30 | 显示全部楼层 |阅读模式
首先新建工程,工程建完后,加入USART模块。
这次想用USART0,通过查相关的手册知道其在PC2和PC3上边




然后,打开快速指导:



通过快速指导形成程序:

  1. #include <asf.h>



  2. #define USART_SERIAL                     &USARTC0
  3. #define USART_SERIAL_BAUDRATE            9600
  4. #define USART_SERIAL_CHAR_LENGTH         USART_CHSIZE_8BIT_gc
  5. #define USART_SERIAL_PARITY              USART_PMODE_DISABLED_gc
  6. #define USART_SERIAL_STOP_BIT            false
  7. uint8_t received_byte;

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


编译顺利通过,但我的USB转串是5V的,不能3.3,我把5伏放上去一个脚光标正常闪,一个脚光标不闪,说明有反应。至于,能不能把它看到得找个3.3V的USB转串啦。我找找看,以后再说哈。

本帖子中包含更多资源

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

×
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

2403

主题

6994

帖子

68

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

2403

主题

6994

帖子

68

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