我想使用 ATMEGA16 通过 UART 接收字符串(指向字符的指针)。我在套件上烧录了这段代码,然后我使用超级终端(realterm)并进行了输入字符串(“on”)的测试,如果收到它,则 portc(LEDS)将设置为 1,但它不起作用.. 。 任何人!?:D
功能实现
#include <avr/io.h>
#define F_CPU 8000000UL
unsigned char *x;
#define USART_BAUDRATE 9600
#define BAUD_PRESCALE (((F_CPU / (USART_BAUDRATE * 16UL))) - 1)
void uartinit()
{
UCSRB |= (1 << RXEN) | (1 << TXEN);
// Turn on the transmission and reception circuitry
UCSRC |= (1 << URSEL) | (1 << UCSZ0) | (1 << UCSZ1);
// Use 8-bit character sizes
UBRRL = BAUD_PRESCALE; // Load lower 8-bits of the baud rate value.. …Run Code Online (Sandbox Code Playgroud)