我正在尝试对 Dragon12-Light 板进行编程,以通过 Cool Term 终端软件向 PC 显示信息,但是我似乎无法让 sprintf 功能正常工作。目标是从温度传感器和光传感器向终端发送信息,但我什至用虚拟值尝试过它,但它运行不正常。这是代码:
void main(void) {
PLL_init(); // set system clock frequency to 24 MHz
DDRB = 0xff; // Port B is output
DDRJ = 0xff; // Port J is output
DDRP = 0xff; // Port P is output
PTJ = 0x00; // enable LED
PTP = 0x00; // enable all 7-segment displays
PORTB = 0x55; // turn on every other led and segment on 7-seg displays
initSCI0();
for(;;) {
unsigned char pot = '1';
unsigned char pot_out;
unsigned char temperature;
unsigned char light;
unsigned char receive;
char buffer[50];
int test = 10;
sprintf(buffer, "test = %d", test);
receive = SCI0_receiveByte();
if(receive == '1'){
SCI0_transmitString(buffer);
}
} /* wait forever */
}
我已经验证了所有函数都可以正常运行,如果我将具有定义值的 char 数组放入传输字符串函数中,当在键盘上按下“1”时,它将在终端上正确显示,但 sprintf 命令没有t 似乎正在向数组写入任何内容。任何帮助将不胜感激。谢谢!