This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Whats happening here ??

Hallo everybody,

got myself another problem.... not exactly a problem... i think
The thing is i would like to know whats happening in this output:

printf("AIN[%d][%d] = %u.%.3u V\n",m,n,(int)(AD_ARRAY[m][n]/V_SCALE),(int)(AD_ARRAY[m][n]%V_SCALE)*R_SCALE);

The preprocessor declarations are :

ine V_REF 5
#define V_SCALE (0xFF/V_REF)
#define R_SCALE (99/V_REF)

I am using a 80C535 µC and the AD_ARRAY[m][n] saves the actual ADC value of the sample and im using µVision2

Thanks for the help
Andy

Parents
  • Do you understand how printf works?

    That line of code is pretty hard to read, being all crammed together with no white space - you could make your life a lot easier by improving the laytout; eg,

    printf(
       "AIN[%d][%d] = %u.%.3u V\n",          // Format string
       m,                                    // 1st value
       n,                                    // 2nd value
       (int)(AD_ARRAY[m][n]/V_SCALE),        // 3rd value
       (int)(AD_ARRAY[m][n]%V_SCALE)*R_SCALE // 4th value
    );
    


    It would also be easier to read if you calculated the 3rd & 4th values separately, rather than cramming inline expressions into the printf call. With modern optimising compilers, it is unlikely that this would actually add to the code.

    It is a false assumption that reducing the number of source lines (eg, by cramming as much into each line as possible) will reduce the size of the generated code!

Reply
  • Do you understand how printf works?

    That line of code is pretty hard to read, being all crammed together with no white space - you could make your life a lot easier by improving the laytout; eg,

    printf(
       "AIN[%d][%d] = %u.%.3u V\n",          // Format string
       m,                                    // 1st value
       n,                                    // 2nd value
       (int)(AD_ARRAY[m][n]/V_SCALE),        // 3rd value
       (int)(AD_ARRAY[m][n]%V_SCALE)*R_SCALE // 4th value
    );
    


    It would also be easier to read if you calculated the 3rd & 4th values separately, rather than cramming inline expressions into the printf call. With modern optimising compilers, it is unlikely that this would actually add to the code.

    It is a false assumption that reducing the number of source lines (eg, by cramming as much into each line as possible) will reduce the size of the generated code!

Children