0

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);              
            }
        }
    }
}
2
  • You cannot assign the contents of DAC_table this way. Assign them directly in the declaration of the array and use curly brackets { Commented Apr 18, 2013 at 7:18
  • please format your question Commented Apr 18, 2013 at 7:26

2 Answers 2

1
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.

Sign up to request clarification or add additional context in comments.

1 Comment

He never changes the array: he can simply define the elements when declaring it.
0

After a brief look at your code, I can say that:

  • ptr2tbl is being used without initialization, when it is first called -> 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 nowhere
  • P2 is not declared (Is P2 a global variable?)
  • and, as said before, you cannot initialize DAC_table that way (using parenthesis is wrong).

1 Comment

yes you are right..it was my stupidity to put common braces instead of curvy braces..as i'm new to pointers programming there is a lot to learn..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.