打印
[Atmel]

跑一下SAM4N例程(二十二):USART1

[复制链接]
527|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
在Atmle Studio6.2的开发环境直接插入开发板。就可直接打开例程。

今天例程简单,通过串口打印一个字符串,然后接收用户的输入字符,每输入一个回显一个

我觉得高难的是初始化函数用了大量的指针:

 */
static inline void stdio_serial_init(volatile void *usart, const usart_serial_options_t *opt)
{
        stdio_base = (void *)usart;
        ptr_put = (int (*)(void volatile*,char))&usart_serial_putchar;
        ptr_get = (void (*)(void volatile*,char*))&usart_serial_getchar;
# if (XMEGA || MEGA_RF)
        usart_serial_init((USART_t *)usart,opt);
# elif UC3
        usart_serial_init(usart,(usart_serial_options_t *)opt);
# elif SAM
        usart_serial_init((Usart *)usart,(usart_serial_options_t *)opt);
# else
#  error Unsupported chip type
# endif

# if defined(__GNUC__)
#  if (XMEGA || MEGA_RF)
        // For AVR GCC libc print redirection uses fdevopen.
        fdevopen((int (*)(char, FILE*))(_write),(int (*)(FILE*))(_read));
#  endif
#  if UC3 || SAM
        // For AVR32 and SAM GCC
        // Specify that stdout and stdin should not be buffered.
        setbuf(stdout, NULL);
        setbuf(stdin, NULL);
        // Note: Already the case in IAR's Normal DLIB default configuration
        // and AVR GCC library:
        // - printf() emits one character at a time.
        // - getchar() requests only 1 byte to exit.
#  endif
# endif
}
平时用,我想不用管这些函数只是那来用就行。

接下来是打印一串字符然后就等待用户输入

// Print welcome message
        printf("\n\rHello ATMEL World!\n\r");

        // Get and echo a character forever.
        while (true) {
                scanf("%c",(char*)&ch);

                if (ch) {
                        printf("%c",(char)ch);
                }
        }


这个例和调用的大量的库函数:

 read.c : System implementation function used by standard library
* - write.c : System implementation function used by standard library


本例运行如下:


相关帖子

发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

2398

主题

6948

帖子

66

粉丝