我明明定义了这个函数为什么这个函数还会显示未定义
时间:10-02
整理:3721RD
点击:
在main函数中
GUI_Show12Char(0,20,"HZ",RED,BLACK);
GUI_Show12Char(20,20,"%",RED,BLACK);
GUI_Show12Char(0,0,F,RED,BLACK);
GUI_Show12Char(20,0,D,RED,BLACK);
在gui.c中
void GUI_Show12Char(uint16_t x, uint16_t y, uint8_t *ch, uint16_t wordColor, uint16_t backColor)
{
uint8_t i, j, color, buf[32];
uint16_t asc;
uint32_t wordAddr = 0;
while(*ch != '\0')
{
/*显示字母 */
if(*ch < 0x80) //ASCII码从0~127
{
/* 在字库中的ASCII码是从空格开始的也就是32开始的,所以减去32 */
wordAddr = *ch - 32;
wordAddr *= 16;
wordAddr += GUI_FLASH_ASCII_ADDR;
/* 读取FLASH中该字的字模 */
FLASH_ReadData(buf, wordAddr, 16);
/* 显示该文字 */
TFT_SetWindow(x, y, x+7, y+15); //字宽*高为:8*16
for (j=0; j<16; j++) //每个字模一共有16个字节
{
color = buf[j];
for (i=0; i<8; i++)
{
if ((color&0x80) == 0x80)
{
TFT_WriteData(wordColor);
}
else
{
TFT_WriteData(backColor);
}
color <<= 1;
}
}
ch++; //指针指向下一个字
/* 屏幕坐标处理 */
x += 8;
if(x > 233) //TFT_XMAX -8
{
x = 0;
y += 16;
}
}
/* 显示汉字 */
else
{
/* 将汉字编码转换成在FLASH中的地址 */
asc = *ch - 0x81; //高字节是表示分区,分区是从0x81到0xFE,所以转换成地址-0x80
wordAddr = asc * 190; //每个分区一共有190个字
asc = *(ch + 1); //低字节代表每个字在每个分区的位置,它是从0x40到0xFF
if(asc < 0x7F) //在0x7F位置有个空位,但是我们取模不留空,所以大于0x7F之后多减一
{
asc -= 0x40;
}
else
{
asc -= 0x41;
}
wordAddr += asc; //求出在GBK中是第几个字
wordAddr *= 32; //将字位置转换位FLASH地址
wordAddr += GUI_FLASH_12CHAR_ADDR; //加上首地址
/* 读取FLASH中该字的字模 */
FLASH_ReadData(buf, wordAddr, 32);
/* 在彩屏上面显示 */
TFT_SetWindow(x, y, x+15, y+15);
for(i=0; i<32; i++)
{
color = buf[i];
for(j=0; j<8; j++)
{
if((color & 0x80) == 0x80)
{
TFT_WriteData(wordColor);
}
else
{
TFT_WriteData(backColor);
}
color <<= 1;
}//for(j=0;j<8;j++)结束
}
/* 屏幕坐标处理 */
x += 16;
if(x > 225) //TFT_XMAX -15
{
x = 0;
y += 16;
}
/* 写下一个字,每个汉字占两个字节所以+2 */
ch += 2;
}
}
}
在gui.h中
void GUI_Show12Char(uint16_t x, uint16_t y, uint8_t *ch, uint16_t wordColor, uint16_t backColor);
main.c和gui.c都调用了gui.h为什么编译时报错为
.\output\工程模板.axf: Error: L6218E: Undefined symbol GUI_Show12Char (referred from main.o).
GUI_Show12Char(0,20,"HZ",RED,BLACK);
GUI_Show12Char(20,20,"%",RED,BLACK);
GUI_Show12Char(0,0,F,RED,BLACK);
GUI_Show12Char(20,0,D,RED,BLACK);
在gui.c中
void GUI_Show12Char(uint16_t x, uint16_t y, uint8_t *ch, uint16_t wordColor, uint16_t backColor)
{
uint8_t i, j, color, buf[32];
uint16_t asc;
uint32_t wordAddr = 0;
while(*ch != '\0')
{
/*显示字母 */
if(*ch < 0x80) //ASCII码从0~127
{
/* 在字库中的ASCII码是从空格开始的也就是32开始的,所以减去32 */
wordAddr = *ch - 32;
wordAddr *= 16;
wordAddr += GUI_FLASH_ASCII_ADDR;
/* 读取FLASH中该字的字模 */
FLASH_ReadData(buf, wordAddr, 16);
/* 显示该文字 */
TFT_SetWindow(x, y, x+7, y+15); //字宽*高为:8*16
for (j=0; j<16; j++) //每个字模一共有16个字节
{
color = buf[j];
for (i=0; i<8; i++)
{
if ((color&0x80) == 0x80)
{
TFT_WriteData(wordColor);
}
else
{
TFT_WriteData(backColor);
}
color <<= 1;
}
}
ch++; //指针指向下一个字
/* 屏幕坐标处理 */
x += 8;
if(x > 233) //TFT_XMAX -8
{
x = 0;
y += 16;
}
}
/* 显示汉字 */
else
{
/* 将汉字编码转换成在FLASH中的地址 */
asc = *ch - 0x81; //高字节是表示分区,分区是从0x81到0xFE,所以转换成地址-0x80
wordAddr = asc * 190; //每个分区一共有190个字
asc = *(ch + 1); //低字节代表每个字在每个分区的位置,它是从0x40到0xFF
if(asc < 0x7F) //在0x7F位置有个空位,但是我们取模不留空,所以大于0x7F之后多减一
{
asc -= 0x40;
}
else
{
asc -= 0x41;
}
wordAddr += asc; //求出在GBK中是第几个字
wordAddr *= 32; //将字位置转换位FLASH地址
wordAddr += GUI_FLASH_12CHAR_ADDR; //加上首地址
/* 读取FLASH中该字的字模 */
FLASH_ReadData(buf, wordAddr, 32);
/* 在彩屏上面显示 */
TFT_SetWindow(x, y, x+15, y+15);
for(i=0; i<32; i++)
{
color = buf[i];
for(j=0; j<8; j++)
{
if((color & 0x80) == 0x80)
{
TFT_WriteData(wordColor);
}
else
{
TFT_WriteData(backColor);
}
color <<= 1;
}//for(j=0;j<8;j++)结束
}
/* 屏幕坐标处理 */
x += 16;
if(x > 225) //TFT_XMAX -15
{
x = 0;
y += 16;
}
/* 写下一个字,每个汉字占两个字节所以+2 */
ch += 2;
}
}
}
在gui.h中
void GUI_Show12Char(uint16_t x, uint16_t y, uint8_t *ch, uint16_t wordColor, uint16_t backColor);
main.c和gui.c都调用了gui.h为什么编译时报错为
.\output\工程模板.axf: Error: L6218E: Undefined symbol GUI_Show12Char (referred from main.o).
不可能不行,你在.h文件中要申明成外部函数,main才能访问,不行的话,就是你错误不止这一个!
在gui.h的函数命名中中 加入extern
extern void GUI_Show12Char(uint16_t x, uint16_t y, uint8_t *ch, uint16_t wordColor, uint16_t backColor);
积分太少啦,赶紧确认.
可以给我看看你的完整代码吗
声明前加extern试试
我按您的方法试过了还是有这个错误,积分少。是因为我刚进这个论坛,,,这是我的新人贴
不行
你在gui.h中申明一下函数,在main.c中#include "gui.h",不可能不能调用,另外注意下你的编译器#include路径
兄弟,这个怎么解决的?