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

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
02/23/03 17:15
Read: times


 
#39841 - RE: DS1620. Look-up table?
Responding to: ???'s previous message
The formulas to convert the degrees C values to degrees F value are well known and not all that hard to implement in 8051 assembly language. (And even easier in C).

But in case one wants to avoid the formula:

F = ((9 * C)/5)+32

....then as mentioned before a lookup table can be used. (Please all of you 'experts'. I know this is way bigger in code size than simply implementing the formula conversion but I want to show table lookup here).

Here is a link to an EXCEL C to F Converter spreadsheet that makes a look up table for this process. The table will have 512 entries and the 9-bit degrees C code (in 1/2 deg C resolution is used to index the table. Each word in the table will contain a two byte value of the equivalent degrees F in 1/10 degree resolution. The value is represented as a four nibble BCD value of the temperature F * 10. It is very simple to isolate the nibbles of the BCD and display the F values as fff.f to show the full temp value.

The first lines of the spreadsheet file look like this:
9 bit                   deg     BCD Table
deg C   deg C   deg F   F*10    code for
code    number  number  integer deg F*10
----    ------  ------  ------- ----------
0	0	32	320	0320H
1	0.5	32.9	329	0329H
2	1	33.8	338	0338H
3	1.5	34.7	347	0347H
4	2	35.6	356	0356H
5	2.5	36.5	365	0365H
6	3	37.4	374	0374H
7	3.5	38.3	383	0383H
8	4	39.2	392	0392H


The final column of the spreadsheet table is made into a source code table like this...
C2F_Table:
DW 0320H, 0329H, 0338H, 0347H
DW 0356H, 0365H, 0374H, 0383H,
DW 0392H ...... and so on for 512 entries

The 8052 code to index this kind of table can look like as shown below. In this example R6::R7 initially contain the 9-bit degree C code in a right justified position. The resulting deg F BCD code value is placed back into R6::R7.

C2F_Table:
DW 0320H, 0329H, 0338H, 0347H
DW 0356H, 0365H, 0374H, 0383H, 
DW 0392H ...... and so on for 512 entries

;code snippett to look up in the table

	MOV  	A,R7               ;get low byte if C code
	ADD  	A,ACC
	MOV  	R7,A               ;mult by 2 and save back to R7
	MOV  	A,R6               ;mult high byte too
	RLC  	A
	MOV  	R6,A
	MOV  	A,#LOW (C2F_Table) ;add word index
	ADD  	A,R7               ;from R6::R7
	MOV  	DPL,A              ;to table address
	MOV  	A,#HIGH (C2F_Table)
	ADDC 	A,R6               ;and put into DPTR
	MOV  	DPH,A
	CLR  	A                  ;fetch high byte of 
	MOVC 	A,@A+DPTR          ;BCD from table
	MOV  	R6,A
	MOV  	A,#01H             ;fetch low byte of
	MOVC 	A,@A+DPTR          ;BCD from table
	MOV  	R7,A


Michael Karas


List of 19 messages in thread
TopicAuthorDate
DS1620. Look-up table?            01/01/70 00:00      
   RE: DS1620. Look-up table?            01/01/70 00:00      
      RE: DS1620. Look-up table?            01/01/70 00:00      
         Internal External memory            01/01/70 00:00      
            RE: Internal External memory            01/01/70 00:00      
   RE: DS1620. Look-up table?            01/01/70 00:00      
      RE: DS1620. Look-up table?            01/01/70 00:00      
   RE: DS1620. Look-up table?            01/01/70 00:00      
      RE: DS1620. Look-up table?            01/01/70 00:00      
         RE: DS1620. Look-up table?            01/01/70 00:00      
         RE: DS1620. Look-up table?            01/01/70 00:00      
   RE: DS1620. Look-up table? / Erik            01/01/70 00:00      
   Sample LUT            01/01/70 00:00      
      RE: Sample LUT            01/01/70 00:00      
         RE: Sample LUT            01/01/70 00:00      
            RE: Sample LUT            01/01/70 00:00      
   RE: DS1620. Look-up table?            01/01/70 00:00      
      RE: DS1620. Look-up table?            01/01/70 00:00      
         RE: DS1620. Look-up table?            01/01/70 00:00      

Back to Subject List