我要用到一个函数void GUI_DispStringInRect (const char GUI_UNI_PTR * s, GUI_RECT * pRect, int TextAlign);这是emwin的一个系统函数,第一个参数指向一个字符串,第二个参数指定一个矩形区域,第三个参数指定显示时候对齐方式。GUI_RECT定义如下typedef struct { I16 x0,y0,x1,y1; } LCD_RECT;编写如下程序。
int main(void) { static GUI_RECT *aa; aa->x0=(short)100; aa->y0=(short)100; aa->x1=(short)180; aa->y1=(short)180; SDRAM_32M_16BIT_Init(); //GLCD_Init(); GUI_Init();
GUI_DispString("heunivrtsityHÎÒello world!"); GUI_DispStringInRect("heunivrtsityHÎÒello world!", aa, 1); GUI_FillRectEx (aa); while( 1 ) { } } 程序语法检查没有错误,运行后报硬件错误,如下图所示,程序指针指向硬件错误
错误原因及分析:
1、指向结构体GUI_RECT的指针aa并没有具体的指向,也就是没有分配存储空间;
2、需要建立GUI_RECT类型的结构体变量,然后让指针aa指向改结构体变量,再使用就没有问题了。
3、自定义结构不同于系统结构体,因为系统结构体的指针直接指向了内存地址。
修改代码如下:
int main(void) { static GUI_RECT bb,*aa=&bb; aa->x0=(short)100; aa->y0=(short)100; aa->x1=(short)180; aa->y1=(short)180; SDRAM_32M_16BIT_Init(); //GLCD_Init(); GUI_Init();
GUI_DispString("heunivrtsityHÎÒello world!"); GUI_DispStringInRect("heunivrtsityHÎÒello world!", aa, 1); GUI_FillRectEx (aa); while( 1 ) { } }
