首先新建工程,工程建完后,加入USART模块。
这次想用USART0,通过查相关的手册知道其在PC2和PC3上边
然后,打开快速指导:
通过快速指导形成程序:
- #include <asf.h>
- #define USART_SERIAL &USARTC0
- #define USART_SERIAL_BAUDRATE 9600
- #define USART_SERIAL_CHAR_LENGTH USART_CHSIZE_8BIT_gc
- #define USART_SERIAL_PARITY USART_PMODE_DISABLED_gc
- #define USART_SERIAL_STOP_BIT false
- uint8_t received_byte;
- int main (void)
- {
- /* Insert system clock initialization code here (sysclk_init()). */
-
-
- sysclk_init();
-
- ioport_configure_pin(IOPORT_CREATE_PIN(PORTC,3), IOPORT_DIR_OUTPUT
- |IOPORT_INIT_HIGH);
- ioport_configure_pin(IOPORT_CREATE_PIN(PORTC,2), IOPORT_DIR_INPUT);
-
- static usart_serial_options_t usart_options = {
- .baudrate = USART_SERIAL_BAUDRATE,
- .charlength = USART_SERIAL_CHAR_LENGTH,
- .paritytype = USART_SERIAL_PARITY,
- .stopbits = USART_SERIAL_STOP_BIT
- };
-
-
- usart_serial_init(USART_SERIAL, &usart_options);
- //usart_init_rs232(USART_SERIAL,&usart_options);
-
- while(1)
- {
- usart_serial_putchar(&USARTC0, 0x55);
- usart_serial_getchar(USART_SERIAL, &received_byte);
- usart_serial_putchar(USART_SERIAL, received_byte);
-
- }
- /* Insert application code here, after the board has been initialized. */
- }
编译顺利通过,但我的USB转串是5V的,不能3.3,我把5伏放上去一个脚光标正常闪,一个脚光标不闪,说明有反应。至于,能不能把它看到得找个3.3V的USB转串啦。我找找看,以后再说哈。
|