我有一个 LCD,连接到 Atmega32,使用此功能处理单个字符:
void send_char(uint8_t c){
PORTD = c; // set the output pins to the ascii value of the char
PORTB |= 0x05;
_delay_us(1);
PORTB &= 0xfa;
_delay_us(60);
PORTD = 0x00;
update_cursor();
}
我可以用一个字符作为参数来调用它:send_char('a');
它有效。
然后我尝试在它周围包装一个 send_string 函数:
void send_string(const char * msg){
while (*msg != '\0'){
send_char(*msg++);
}
}
这只会在我的 LCD 上显示乱码,表明 ASCII 值已经很远了。当我尝试传递一个空字符串 ( send_string("")
) 时,LCD 上至少会显示三个乱码。