Reputation: 21
Kindly help in resolving this,the error i'm getting here is syntax near '{' since i had declared unsigned char near DAC_table i got an error,so define outside the function which is wrong...i have not posted my complete code here...in this part of the code i'm getting problem..
unsigned char DAC_table[16];
unsigned char *ptr2tbl;
void fnSelectVoltage(void)
{
line_display(1, "Volt Sel");
sprintf(line_buf," %d V",(unsigned int)*ptr2tbl);
line_display(2, line_buf);
DAC_table[16] = ( 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F);
*ptr2tbl = &DAC_table;
while (START_KEY)
{
if (!UP_KEY)
{
wait_for_any_key_counter_0 = 0;
for (i = 0; i<15; i++)
{
P2 = *ptr2tbl++;
// delay_ms(1000);
}
}
else if(!DOWN_KEY)
{
wait_for_any_key_counter_0 = 0;
for (i = 0; i<15; i++)
{
P2 = *ptr2tbl++;
// delay_ms(1000);
}
}
}
}
Upvotes: 0
Views: 119
Reputation: 10665
After a brief look at your code, I can say that:
sprintf(line_buf," %d V",(unsigned int)*ptr2tbl)
.*ptr2tbl = &DAC_table;
is incorrect. You probally wanna something like that:
ptr2tbl = DAC_table
once both are pointers. Remember that *ptr2tbl will access the element that it is pointing to, and at this moment, in your code, it is pointing to nowhereUpvotes: 0
Reputation: 5239
unsigned char DAC_table[16];// u hv created a global array here
To assign values to it,
DAC_table[0] = 0x00;
DAC_table[1] = 0x01; and so on.
OR even better
unsigned char DAC_table[16] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F}; at the line of declaration.
You can't assign values to variables at file scope except at the line of declaration.
Upvotes: 1