我正在尝试创建一个包含指向常量数组的指针的数组。我在 MPLABX 中使用 C30 V3.31,我正在尝试使用 PIC24FJ128GA310 为我的 LCD 创建分段映射。这个想法是将所有 LCD 数字放在常量数组中,然后有一个数组包含指向 LCD 的所有数字的指针,以便于访问。代码段如下所示:
enum SEGS
{
SEG_1A = COM0 |0 , SEG_1B = COM0 |53, SEG_2A = COM0 |33, SEG_K1 = COM0 |44,
SEG_K2 = COM0 |22, SEG_K8 = COM0 |21, SEG_4A = COM0 |62, SEG_4B = COM0 |61,
SEG_5A = COM0 |60, SEG_5B = COM0 |59, SEG_6A = COM0 |58, SEG_6B = COM0 |50,
SEG_7A = COM0 |61, SEG_7B = COM0 |48, SEG_8A = COM0 |59, SEG_8B = COM0 |26,
SEG_9A = COM0 |25, SEG_9B = COM0 |24, SEG_10A= COM0 |23, SEG_10B= COM0 |45,
SEG_2B = COM0 |52, SEG_3A = COM0 |32, SEG_3B = COM0 |51, SEG_S3 = COM0 |24
}
const BYTE DIGIT1[] = {SEG_1A,SEG_1B,SEG_1C,SEG_1D,SEG_1E,SEG_1F,SEG_1G};
const BYTE DIGIT2[] = {SEG_2A,SEG_2B,SEG_2C,SEG_2D,SEG_2E,SEG_2F,SEG_2G};
const BYTE DIGIT3[] = {SEG_3A,SEG_3B,SEG_3C,SEG_3D,SEG_3E,SEG_3F,SEG_3G};
const BYTE DIGIT4[] = {SEG_4A,SEG_4B,SEG_4C,SEG_4D,SEG_4E,SEG_4F,SEG_4G};
const BYTE DIGIT5[] = {SEG_5A,SEG_5B,SEG_5C,SEG_5D,SEG_5E,SEG_5F,SEG_5G};
const BYTE DIGIT6[] = {SEG_6A,SEG_6B,SEG_6C,SEG_6D,SEG_6E,SEG_6F,SEG_6G};
const BYTE DIGIT7[] = {SEG_7A,SEG_7B,SEG_7C,SEG_7D,SEG_7E,SEG_7F,SEG_7G};
const BYTE DIGIT8[] = {SEG_8A,SEG_8B,SEG_8C,SEG_8D,SEG_8E,SEG_8F,SEG_8G};
const BYTE DIGIT9[] = {SEG_9A,SEG_9B,SEG_9C,SEG_9D,SEG_9E,SEG_9F,SEG_9G};
const BYTE DIGIT10[] = {SEG_10A,SEG_10B,SEG_10C,SEG_10D,SEG_10E,SEG_10F,SEG_10G};
const BYTE * const Digits[] ={
DIGIT1,DIGIT2,DIGIT3,DIGIT4,DIGIT5,DIGIT6,DIGIT7,DIGIT8,DIGIT9,DIGIT10};
enum DIGITS {DIG1,DIG2,DIG3,DIG4,DIG5,DIG6,DIG7,DIG8,DIG9,DIG10};
//... FUNCTIONS
void DisplayDigit2(BYTE idx,BYTE Mask)
{
BYTE digit = *Digits[idx];
for(i=0; i<8;i++){
DisplaySeg(digit,(Mask&1));
Mask >>=1;
}
}
void DisplaySeg(BYTE segcode,BOOL state)
{
BYTE mapbyte,com,bitmap,index;
com = (segcode&0xC0)>>6;
segcode = (segcode & 0x3F);
index = segcode/16;
mapbyte = (com * 4) + index;
bitmap = (segcode%16);
if (state)
lcdvals[mapbyte] |= (1<<bitmap);
else
lcdvals[mapbyte] &= ~(1<<bitmap);
}
...
//Calling the function
DisplayDigit2(DIG1,ONE);
谁能帮我确认我做对了吗?代码编译没有任何错误或警告,我可以在监视窗口中看到所有变量和指针,但函数 DisplayDigit2() 没有完全执行。
当我单步执行时,调试器在第一行停止,
BYTE digit = *Digits[idx];
并且简单在状态栏中显示此消息“用户程序已停止”。