Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
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


List of 31 messages in thread
TopicAuthorDate
defination under Keil            01/01/70 00:00      
   int/float            01/01/70 00:00      
   IAR PreProcessor VS Keil            01/01/70 00:00      
      confusion            01/01/70 00:00      
         just doing text subistituons I guess            01/01/70 00:00      
            un            01/01/70 00:00      
               preprocessor            01/01/70 00:00      
                  Some confusion abounds...            01/01/70 00:00      
                     Wrong again!            01/01/70 00:00      
                        Take is easy...            01/01/70 00:00      
                           The important bit...?            01/01/70 00:00      
         Floating-point not supported in eval            01/01/70 00:00      
      preprocessor maths            01/01/70 00:00      
         I was being carelessly loose............            01/01/70 00:00      
            Keil Test            01/01/70 00:00      
            Save you the trouble            01/01/70 00:00      
               Oh            01/01/70 00:00      
         preproccessor maths            01/01/70 00:00      
            ##########            01/01/70 00:00      
               thats the confusion            01/01/70 00:00      
                  In context            01/01/70 00:00      
                     Thanks            01/01/70 00:00      
                  Think about it            01/01/70 00:00      
   Aside - 'C' #define names            01/01/70 00:00      
      good coding practices            01/01/70 00:00      
   Thank you            01/01/70 00:00      
      Alternatively...            01/01/70 00:00      
         re: Alternatively...            01/01/70 00:00      
      Not a good idea            01/01/70 00:00      
         Not a good idea            01/01/70 00:00      
         floating point in ISRs            01/01/70 00:00      

Back to Subject List