Add character counting guard
This commit is contained in:
+24
-22
@@ -13,8 +13,8 @@ humid_offset equ 09eh
|
|||||||
bdos equ 0005h
|
bdos equ 0005h
|
||||||
conout equ 02h
|
conout equ 02h
|
||||||
conin equ 01h
|
conin equ 01h
|
||||||
|
printstr equ 09h
|
||||||
|
|
||||||
char_idx equ 10h
|
|
||||||
|
|
||||||
start:
|
start:
|
||||||
call init_lcd
|
call init_lcd
|
||||||
@@ -42,8 +42,6 @@ start:
|
|||||||
main:
|
main:
|
||||||
call read_char_b
|
call read_char_b
|
||||||
call parse_char
|
call parse_char
|
||||||
;call lcd_delay
|
|
||||||
;call print_char_to_lcd
|
|
||||||
ld c,11
|
ld c,11
|
||||||
call bdos
|
call bdos
|
||||||
or a
|
or a
|
||||||
@@ -119,14 +117,24 @@ parse_char: ; char should be in register a
|
|||||||
cp a,048h ; H character
|
cp a,048h ; H character
|
||||||
jr z,set_char_idx_h ; point the char_idx to the humidity buffer
|
jr z,set_char_idx_h ; point the char_idx to the humidity buffer
|
||||||
|
|
||||||
|
push af
|
||||||
|
ld a,(char_cnt) ; get number stored in char_cnt
|
||||||
|
cp char_max ; compare it to maximum character count
|
||||||
|
jr nc,store_full ; if no carry, the buffer is full
|
||||||
|
inc a ; otherwise increment
|
||||||
|
ld (char_cnt),a ; and store back in char_cnt
|
||||||
|
pop af
|
||||||
|
|
||||||
ld bc,(char_idx) ; get address stored in char_idx
|
ld bc,(char_idx) ; get address stored in char_idx
|
||||||
ld (bc),a ; deref that address and store char
|
ld (bc),a ; deref that address and store char
|
||||||
inc bc
|
inc bc
|
||||||
ld (char_idx),bc ; store incremented address in char_idx
|
ld (char_idx),bc ; store incremented address in char_idx
|
||||||
|
|
||||||
;out (lcd_data),a
|
|
||||||
parse_char_done:
|
parse_char_done:
|
||||||
ret
|
ret
|
||||||
|
store_full:
|
||||||
|
pop af
|
||||||
|
ret
|
||||||
|
|
||||||
print_telem_to_lcd:
|
print_telem_to_lcd:
|
||||||
call move_to_tempaddr
|
call move_to_tempaddr
|
||||||
@@ -142,7 +150,6 @@ print_telem_to_lcd:
|
|||||||
call print_str_to_lcd
|
call print_str_to_lcd
|
||||||
|
|
||||||
ld a,1h
|
ld a,1h
|
||||||
out (0),a
|
|
||||||
ret
|
ret
|
||||||
|
|
||||||
null_term: ; null terminate end of parsed string in memory
|
null_term: ; null terminate end of parsed string in memory
|
||||||
@@ -155,36 +162,25 @@ null_term: ; null terminate end of parsed s
|
|||||||
set_char_idx_t:
|
set_char_idx_t:
|
||||||
ld bc,temperature
|
ld bc,temperature
|
||||||
ld (char_idx),bc
|
ld (char_idx),bc
|
||||||
|
xor a ; reset char_cnt to zero
|
||||||
|
ld (char_cnt),a
|
||||||
ret
|
ret
|
||||||
|
|
||||||
set_char_idx_p:
|
set_char_idx_p:
|
||||||
ld bc,pressure
|
ld bc,pressure
|
||||||
ld (char_idx),bc
|
ld (char_idx),bc
|
||||||
|
xor a ; reset char_cnt to zero
|
||||||
|
ld (char_cnt),a
|
||||||
ret
|
ret
|
||||||
|
|
||||||
set_char_idx_h:
|
set_char_idx_h:
|
||||||
ld bc,humidity
|
ld bc,humidity
|
||||||
ld (char_idx),bc
|
ld (char_idx),bc
|
||||||
|
xor a ; reset char_cnt to zero
|
||||||
|
ld (char_cnt),a
|
||||||
ret
|
ret
|
||||||
|
|
||||||
|
|
||||||
print_char_to_lcd:
|
|
||||||
cp a,00h ; null byte
|
|
||||||
jr z,lcd_done
|
|
||||||
cp a,0dh ; carriage return
|
|
||||||
jr z,lcd_done
|
|
||||||
cp a,0ah ; new line
|
|
||||||
jr z,lcd_done
|
|
||||||
cp a,054h ; T character
|
|
||||||
call z,move_to_tempaddr
|
|
||||||
cp a,050h ; P character
|
|
||||||
call z,move_to_presaddr
|
|
||||||
cp a,048h ; H character
|
|
||||||
call z,move_to_humidaddr
|
|
||||||
out (lcd_data),a
|
|
||||||
lcd_done:
|
|
||||||
ret
|
|
||||||
|
|
||||||
print_str_to_lcd: ; place memory address in hl first
|
print_str_to_lcd: ; place memory address in hl first
|
||||||
ld a,(hl)
|
ld a,(hl)
|
||||||
or a
|
or a
|
||||||
@@ -221,6 +217,12 @@ clabel: DB 'degree C',0
|
|||||||
plabel: DB 'pascal',0
|
plabel: DB 'pascal',0
|
||||||
hlabel: DB '% RH',0
|
hlabel: DB '% RH',0
|
||||||
|
|
||||||
|
char_max equ 15
|
||||||
|
char_cnt DB 0
|
||||||
|
|
||||||
|
char_idx DW scratch
|
||||||
|
scratch: DS 16
|
||||||
|
|
||||||
temperature: DS 16
|
temperature: DS 16
|
||||||
humidity: DS 16
|
humidity: DS 16
|
||||||
pressure: DS 16
|
pressure: DS 16
|
||||||
|
|||||||
Reference in New Issue
Block a user