From 33fe56dade0528aa3cbcb82d94e4b762453260af Mon Sep 17 00:00:00 2001 From: maddiebaka Date: Sun, 23 Aug 2026 20:26:52 -0400 Subject: [PATCH] Add conversion to hPa --- bme280_util.z80 | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/bme280_util.z80 b/bme280_util.z80 index ca3d20d..cf0e647 100644 --- a/bme280_util.z80 +++ b/bme280_util.z80 @@ -90,8 +90,30 @@ delay1: jr nz,delay1 ret -convert_to_hpa: - ld a,(pressure) +convert_to_hpa: ; shift the decimal point in (pressure) two places left + ld hl,pressure + ld b,0 ; count of digits ahead of the point +find_point: + ld a,(hl) + or a + ret z ; no point in the string, leave it alone + cp a,2eh ; period + jr z,found_point + inc hl + inc b + jr find_point +found_point: + ld a,b + cp 3 ; need three whole digits to shift by two + ret c + dec hl ; step back over the ones digit + dec hl ; hl now holds the new tenths digit + ld a,(hl) + ld (hl),2eh ; drop the point in two places left + inc hl + ld (hl),a ; and the saved digit after it + inc hl + ld (hl),00h ; null terminate, discarding the rest ret read_char_b: @@ -141,6 +163,7 @@ print_telem_to_lcd: ld hl,temperature call print_str_to_lcd + call convert_to_hpa call move_to_presaddr ld hl,pressure call print_str_to_lcd @@ -202,7 +225,7 @@ move_to_tempaddr: ret move_to_presaddr: - ld a,0c1h + ld a,0c3h out (lcd_ctrl),a call lcd_delay ret @@ -214,7 +237,7 @@ move_to_humidaddr: ret clabel: DB 'degree C',0 -plabel: DB 'pascal',0 +plabel: DB 'hPa',0 hlabel: DB '% RH',0 char_max equ 15