??? 06/27/05 13:01 Read: times |
#96011 - Keil Test Responding to: ???'s previous message |
I tested the Keil C51 compiler with the code block that I previously showed as working for the IAR compiler. I found it to work the same way producing reasonable integer constants.
Here is the code I fed into the Keil C51 compiler: #pragma SRC #define AD_REF 3.0 // A/D converter reference voltage #define AD_CNT_RANGE 1024.0 // count range of the A/D converter #define VIN_R1 47.5E3 // value of upper resistor in the VIN divider #define VIN_R2 10.0E3 // value of lower resistor in the VIN divider #define VIN_OFF 0.3 // VIN drop through diode to the VIN divider #define VIN_MIN 6.5 // minimum VIN volts for device operation #define VIN_MAX 13.5 // maximum VIN volts for device operation #define VIN_HYS 0.2 // hystersis of VIN voltage for recovery #define VIN_MIN_CNT ((unsigned int)(((((VIN_MIN - VIN_OFF) * VIN_R2)/(VIN_R1 + VIN_R2))*AD_CNT_RANGE)/AD_REF)) #define VIN_MAX_CNT ((unsigned int)(((((VIN_MAX - VIN_OFF) * VIN_R2)/(VIN_R1 + VIN_R2))*AD_CNT_RANGE)/AD_REF)) #define VIN_HYS_CNT ((unsigned int)((((VIN_HYS * VIN_R2)/(VIN_R1 + VIN_R2))*AD_CNT_RANGE)/AD_REF)) unsigned int code cnt_array[3] = { VIN_MIN_CNT, VIN_MAX_CNT, VIN_HYS_CNT }; The compiler produced the following SRC output: ; FloatDefs.SRC generated from: FloatDefs.c ; COMPILER INVOKED BY: ; C:KeilC51BINC51.EXE FloatDefs.c BROWSE DEBUG OBJECTEXTEND NAME FLOATDEFS ?CO?FLOATDEFS SEGMENT CODE PUBLIC cnt_array RSEG ?CO?FLOATDEFS cnt_array: DW 00170H DW 0030FH DW 0000BH ; #pragma SRC >- snip-< ; ( original source code copy snipped out ) >- snip-< END Here is the circuit diagram concept that the above code was used with. An onboard A/D converter on the microcontroller monitored the input voltage as being in the proper range so as to provide safe device operation when in range and lockout when out of range. ![]() Michael Karas |