这个接着昨天的程序,很简单就是加了个输出字符串的函数:
usart_serial_write_packet(USART_SERIAL, "Test String", strlen("Test String"));
strlen刚编译时过不去,就说没有定义:
在头文件加上#include <string.h>
就可以了。
以下是程序:
- #include <asf.h>
- #include <string.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;
- uint8_t hello[18];
- 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_write_packet(USART_SERIAL, "Test String", strlen("Test String"));
-
-
- }
- /* Insert application code here, after the board has been initialized. */
- }
我运行了一下,可以输出不变的十六进制。我打到文本时也许我的3VU转串不太了。是一种规则的乱码。
|