fl { Graph-display on LCD(16character 4Line) about TouchSens status Using RC-Decay phsa count until each port become to low. max_TS & min_TS might vary against each boards & temperature & body. phsa's value shift to small by low temperature. PropForth 4.5 29/06/2011 23:10:15 } hex [ifndef waitcnt \ waitcnt ( n1 n2 -- n3 ) \ wait until n1, n3 = n1 + n2 : waitcnt _execasm2>1 1F1 _cnip ; ] 1F8 wconstant ctra 1FA wconstant frqa 1FC wconstant phsa 400000 constant max_TS \ when no touch 80000 constant min_TS \ when touch 38000 constant segment \ (max_TS - min_TS) / 16 variable pad_array 6 allot \ each pad level [pad0 - pad7] : all_sense \ ( -- ) sensing pad0 - pad7 Store to pad_array begin 8 0 do 1 1 1 i 20000000 + ctra COG! 1 frqa COG! i lshift outa COG@ ffffff00 and or outa COG! \ set each port-out to 1 i lshift dira COG@ ffffff00 and or dira COG! \ set each port-dir to 1 cnt COG@ 1000 + 1 waitcnt drop \ charge up each pad 0 phsa COG! \ clear phsa dira COG@ ffffff00 and dira COG! \ set P0 -P7 to input begin dup i lshift ina COG@ and 0= if phsa COG@ dup max_TS > if drop max_TS else dup min_TS < if drop min_TS then then 80000 - segment u/ 1- dup -1 = if drop f else invert f and then i pad_array + C! 1 else 0 then until drop a delms loop 0 until ; wvariable x_pos : put_blank 0 0 2 0 do lcd_char loop ; \ ( -- ) put 2-blank on LCD : graph lcd_init set_bar_graph2 c" all_sense" 4 cogx begin 300 delms \ wait until stable 8 0 do i 2 u* 1+ x_pos W! 7 i - pad_array + C@ 1+ 1 lshift \ pad_value(0x0 - 0xf) ==> LCD_level(0x1 - 0x10) 8 u/mod dup dup 0> \ 1char[0xFF] = LCD_level 8 if \ quotient is more than 0 0 do x_pos W@ 4 i - lcd_pos \ set LCD position 2 0 do ff lcd_char loop \ put character loop dup 4 = if 2drop \ quotient is 4 else dup >r 4 swap - \ quotient is 1 or 2 or 3 x_pos W@ swap lcd_pos dup 2 0 do lcd_char loop r> dup 3 = if drop \ quotient is 3 else 1 = if x_pos W@ 2 lcd_pos \ quotient is 1 put_blank then x_pos W@ 1 lcd_pos put_blank then then else \ quotient is 0 2drop x_pos W@ 4 lcd_pos dup 2 0 do lcd_char loop 3 0 do x_pos W@ 3 i - lcd_pos \ move from y=3 to y=1 put_blank loop then loop 1 delms 0 until ; decimal