fl { Character-LCD demo codes This demo operate on each H/W. Operating HardWare 2_wire_LCD_sr(8bit) 2_wire_LCD_sr(4bit) PropForth 5.5 2013/04/03 17:46:15 } \ Set bar_graph_font(horizontal) to CG-RAM \ ( -- ) : set_bar_graph h20 h40 6 0 do \ set 6 charcters 8 0 do \ set 8 lines for 1 character dup lcd_com \ command for character to CG-RAM swap dup lcd_char swap \ write data 1+ loop hF8 and swap dup 1 rshift or swap loop 2drop ; : demo1 lcd_init d16 4 lcd_setup \ 16characters 4line \ display char-code [0x20 - 0x7f] & [0xa0 - 0xff] h20 line W@ 2 = if 7 0 else 3 0 then do line W@ 2 = if i 3 = if 4 seti drop hA0 then 2 0 else 4 0 then do line W@ 4 = if j 1 = if i 2 = if h20 + thens 1 i 1+ lcd_pos d16 0 do dup lcd_char h100 delms 1+ loop loop loop drop lcd_clr \ display binary, hex, decimal c" 0x1+0x6 = b" lcd_str 1 6 + 4 lcd_bin 1 2 lcd_pos c" 0xACE+0xF=0x" lcd_str hACE hF + 4 lcd_hex 5 0 do d1000 delms loop lcd_clr 1 cur_line W! c" 0x12+0xe0=" lcd_str h12 hE0 + lcd_dec_L c" (D)" lcd_str lcd_cr c" 0x0-0x12=" lcd_str 0 h12 - lcd_dec_L c" (D)" lcd_str 5 0 do d1000 delms loop lcd_clr 1 cur_line W! d-987654321 lcd_dec_L lcd_cr d-54321 d10 lcd_dec_R 3 0 do d1000 delms loop hex set_bar_graph lcd_clr 1 cur_line W! c" Bar Graph" lcd_str 1 \ x-position char W@ 0 do 0 6 0 do dup lcd_char \ Print bar_graph character 1+ d100 delms swap dup 2 lcd_pos swap \ Set same x-position loop drop 1+ dup 2 lcd_pos \ Increment x-position loop drop char W@ 2 lcd_pos char W@ char W@ 0 do 5 6 0 do dup lcd_char \ Print bar_graph character 1- d100 delms swap dup 2 lcd_pos swap \ Set same x-positionap loop drop 1- dup 2 lcd_pos \ Decrement x-position loop drop lcd_clr c" Demo Finished" lcd_str 1 2 lcd_pos hB3 hC4 hDE hB6 hD8 hB1 h20 hC6 hB7 hB5 hB5 d11 0 do lcd_char loop ; \ Set bar_graph_font(vertical) to CG-RAM \ ( -- ) : set_bar_graph2 h40 8 0 do \ Set 8 charcters 8 0 do \ Set 8 lines for 1 character dup lcd_com \ command for character to CG-RAM 7 j - i < if h1F else 0 then lcd_char \ Write data 1+ loop hF8 and loop drop ; variable tmp1 : demo2 \ wave cnt COG@ lcd_init d16 4 lcd_setup \ 16characters 4line set_bar_graph2 lcd_clr c" Wave" lcd_str 1 2 lcd_pos 1 tmp L! 1 tmp1 L! 0 h100 0 do dup char W@ 0 do dup lcd_char dup 7 = tmp L@ 1 = and if drop hFF else dup hFF = if drop 7 -1 tmp L! else dup 0 = if 1+ 1 tmp L! else tmp L@ + thens loop drop 1 2 lcd_pos dup 7 = tmp1 L@ 1 = and if drop hFF else dup hFF = if drop 7 -1 tmp1 L! else dup 0 = if 1+ 1 tmp1 L! else tmp1 L@ + thens loop drop 1 3 lcd_pos cnt COG@ swap - h13880 u/ lcd_dec_L c" msec" lcd_str ; \ This demo use 16characters X 4line LCD. wvariable X wvariable Y wvariable sign wvariable y_limit : demo3 cnt COG@ lcd_init d16 4 lcd_setup \ 16characters 4line set_bar_graph2 lcd_clr char W@ X W! line W@ Y W! 1 sign W! Y W@ 8 u* y_limit W! 1 0 \ ( cnt Y_incremrnt[X=1] Y_value -- ) at X-pos top h100 0 do 2dup \ ( Y_incremrnt Y_value -- ) \ character -out to X-direction X W@ 0 do \ i dup 9 < if dup i 1+ Y W@ lcd_pos dup 8 = if drop hFF then lcd_char i 1+ Y W@ 1- lcd_pos 0 lcd_char else \ ( Y_incremrnt Y_value -- ) dup 8 u/mod \ quotient ( Y_incremrnt Y_value remainder quotient -- ) i swap >r 1+ Y W@ r> 0 do 2dup lcd_pos hFF lcd_char 1- loop nip \ remainder ( Y_incremrnt Y_value remainder Y-pos --) over 0<> if i 1+ swap lcd_pos lcd_char else dup 0> if i 1+ swap lcd_pos 0 lcd_char drop else 2drop then then then \ ( Y_incremrnt Y_value --) 2dup + dup y_limit W@ > if \ check if more than 0x20 drop nip -1 swap else \ check if less than 0 0< if nip 1 swap then then over + \ delay j h12 < if d100 delms then loop 2drop \ ( cnt Y_incremrnt[X=1] Y_value -- ) \ return X-pos to top 2dup + dup y_limit W@ > if \ check if more than 0x20 drop nip -1 swap else \ check if less than 0 0< if nip 1 swap then then over + loop 3drop ; \ Using normal and BigFont wvariable str_buffer h1E allot wvariable ptr wvariable size : demo4 lcd_init str_buffer ptr W! lcd_clr c" May the Forth be with you." \ set string to str_bufer C@++ dup if bounds do i C@ ptr W@ C! ptr W@ 1+ ptr W! loop else 2drop then \ shift-out string from right to left ptr W@ str_buffer - 1- size W! \ set LCD_start_position str_buffer char W@ - size W@ 1+ char W@ + 0 do dup 1 1 lcd_pos char W@ 0 do dup i + dup str_buffer str_buffer size W@ + between \ print blank_char when out of str_buffer if C@ else drop bl then lcd_char d10 delms loop drop 1+ d100 delms loop drop \ Using BigFont bf_set set_char_segment bf_clear str_buffer bf_char W@ - size W@ 1+ bf_char W@ + 0 do dup 1 1 bf_pos bf_char W@ 0 do dup i + dup str_buffer str_buffer size W@ + between \ print blank_char when out of str_buffer if C@ else drop bl then set_big_font next_bigfont_pos d128 delms loop drop 1+ d128 delms loop drop ;