I am just beginning a project with the MAX31856 thermocouple digital converter. The results are in "19-bit" 2's complement and cover a range from -250°C to 1600°C.
For example, b'0000 0110 0100 1111 0000 0000' translates to 100.9375°C. I am planning to use it for timing roasts and do not need that range (no roast I have ever cooked reached 255°C internal temperature). All values will be positive, and for internal calculations, I will use the 2's complement after shifting to get rid of unnecessary precision. I would like to display current temperature as the roast cooks.
For that purpose, the above binary value can be shortened to b'0000 0110 0100 1111' (0x064F) and still give me plenty of range with a single digit decimal, e.g., 0x64F can be converted to decimal and divided by 16 to give 100.9375 (0.9375 = 15x2^-4) . For display only, here's what I came up with:
This is NOT homework, but I thought I would show my work before asking for help. Are there more generalized and relatively simple ways to do that conversion? Also, for me °C doesn't matter much, but I would like to send this gadget to my daughters for whom °F is more familiar. So, a simple °C to °F routine (with decimal) would be helpful.
For example, b'0000 0110 0100 1111 0000 0000' translates to 100.9375°C. I am planning to use it for timing roasts and do not need that range (no roast I have ever cooked reached 255°C internal temperature). All values will be positive, and for internal calculations, I will use the 2's complement after shifting to get rid of unnecessary precision. I would like to display current temperature as the roast cooks.
For that purpose, the above binary value can be shortened to b'0000 0110 0100 1111' (0x064F) and still give me plenty of range with a single digit decimal, e.g., 0x64F can be converted to decimal and divided by 16 to give 100.9375 (0.9375 = 15x2^-4) . For display only, here's what I came up with:
Code:
movlw 0x00
movwf tempL
movlw 0x4F
movwf tempM
movlw 0x06
movwf tempH
Start ;preserve tempX regs for further calculations
movf tempM,w
andlw 0xF0
xorwf tempH,w
swapf WREG
call bin2bcd ;or bin2ascii
; print bcd ;1-wire serial
; print '.' ;decimal point, 0x2E
movf tempM,w
andlw 0x0F
call Table
; print ascii
Table ;Table can be 1 or 2 digits with a little extra work
brw
dt '0','1','1','2','2','3','4','4'
dt '5','6','6','7','8','8','9','9'