C51 - 与指针相关的错误

时间:2017-03-31 14:27:20

标签: c c51

编辑:当我检查"按顺序保存变量时,问题似乎消失了#34; C51优化菜单中的框。我还是不知道是什么原因导致了这个问题。如果是永久性修复有没有人知道发生了什么?

我正在尝试在C51中构建一个图形菜单。我正在使用menu_init()功能将文本带到4行LCD屏幕上。该函数定义为:

void menu_init(unsigned char** menu_array, unsigned char menu_length)
{   
unsigned char i, menu_max_index;
write_command(CLEAR_DISPLAY);
if (menu_length < 4)            {menu_max_index = menu_length;}
else                            {menu_max_index = 4;}


 for (i = 0; i < menu_max_index; i++)
 {
     write_string_to_line(i+1, (menu_array[i]));
 }

}

void write_string_to_line (unsigned char line, unsigned char* lcd_string)
{
    unsigned char i = 0;

    gotoxy(0, line);
    while(lcd_string[i] != '\0')
    {
        EN = 0;
        RS = 1;
        EN = 1;
        P0 = lcd_string[i];
        i++;
        EN = 0;
        delay(DELAY_COUNT);
    }   
}

在错误发生时,menu_array是:

unsigned char* xdata enter_byte_count_items[3] = {enter_byte_count_text, enter_byte_count_text2, enter_byte_count_number};
//For the unfamiliar, xdata is the segment in the 8051 memory, which the variable is located in

数组的初始值设定项如下:

unsigned char xdata enter_byte_count_text[20] = " Enter byte count of";
unsigned char xdata enter_byte_count_text2[20] = " PGN: ";
unsigned char xdata enter_byte_count_number[20] = " Bytes";

这些就在代码附近,这是另一个菜单的字符串:

unsigned char xdata enter_pgn_text[20] = " Enter PGN Number";
unsigned char xdata enter_pgn_number[20] = " 64000" ;

我希望这段代码能够按顺序打印字符串。但是,情况并非如此,输出如下:

 Enter byte count of
 x:
 Bytes PGN Number

调试器会验证此结果:enter image description here

我无法理解发生了什么......我相信这是关于指针衰减的东西,但我无法确定问题所在。我哪里做错了?

0 个答案:

没有答案
相关问题