URGENT HELP with code on 1769

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

URGENT HELP with code on 1769

979 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by pindonga123 on Sun Nov 03 03:40:07 MST 2013
Hello. I did this code but something is wrong. I dont know where it's. I send a number of 1 to 6 digit and i wanna shows them in the 6 seven segment display. But when i send for example 2 all is ok, 24 too, 243 too, 2438 too, 24387 too. But the problem is that when i send the 6 digit sometime only show me 5 or sometime nothing. For example if i send 243879, only show me 43879 or something nothing. Here is the code. The problem is not in the display refresh, I did something probes more and it's ok, Is not in the display neither.

void mostrar_dig (unsigned long num)
{
unsigned long i=0, vect[5];
while (num > 0)
{
vect=num%10;
num=num/10;
i++;
}
i--;
while (i>=0)
{
switch (i)
{
case 0:
GPIO_ClearValue (0, clear);
GPIO_SetValue (0, vector_b0[vect]);
i--;
Delay (1);
break;
case 1:
GPIO_ClearValue (0, clear);
GPIO_SetValue (0, vector_b1[vect]);
i--;
Delay (1);
break;
case 2:
GPIO_ClearValue (0, clear);
GPIO_SetValue (0, vector_b2[vect]);
Delay (1);
i--;
break;
case 3:
GPIO_ClearValue (0, clear);
GPIO_SetValue (0, vector_b3[vect]);
i--;
Delay (1);
break;
case 4:
GPIO_ClearValue (0, clear);
GPIO_SetValue (0, vector_b4[vect]);
i--;
Delay (1);
break;
case 5:
GPIO_ClearValue (0, clear);
GPIO_SetValue (0, vector_b5[vect]);
Delay (1);
i--;
break;
default:
break;
}
}
}
标签 (1)
0 项奖励
回复
3 回复数

968 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Pacman on Mon Nov 04 02:20:26 MST 2013

Quote:
In fact i have some serious problem with size declaration



I recommend using these:
for unsigned values:
uint8_t
uint16_t
uint32_t


for signed values:
int8_t
int16_t
int32_t


-Because if you use 'long' or 'int' or the like, the compiler will choose a size.

Overrun is if you have an array, with for instance space for 10 bytes, and you are writing to the byte at location 11 (or higher).

You can use the following universal #define to get the number of elements in an array, thus you can check the size in an easy way:

#define ARRAY_SIZE(a)  (sizeof((a)) / sizeof((a)[0]))


Example:
uint8_t buf[13];

len = ARRAY_SIZE(buf)
while(i < len)
{
  i++;
}

0 项奖励
回复

968 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by pindonga123 on Sun Nov 03 04:12:44 MST 2013
I corrected the array number and now it only shows me the numer 0. Can you explain me a little more about overrun?. I mean my number is only of 1 digit because I divided it by 10, so in each positition of array enter only a number from 0 to 9. Sorry but my english is not good.


Thanks a lot. I corrected it and now it work ok. I changed unsigned long vect , only for int vect, but i dont know exactly but did......ja ja ja. In fact i have some serious problem with size declaration. Do you Know or have some where i can read it?
0 项奖励
回复

968 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by capiman on Sun Nov 03 03:54:57 MST 2013
Hello Pindonga123,

your variable/array vect is too small.
vect[5] has 5 entries which go from vect[0] to vect[4] and you are using vect[5] in last case of your switch (and even before, when filling the entry).
You are also not checking for overrun, if your number is bigger than your array.

Best regards,
Martin
0 项奖励
回复