fl { 7-Segment Display Dynamic driver PropForth 5.5 2013/08/23 22:03:49 7-Segment Dynamic drive cuicuit Propeller 1 VDD ---- 3.3V 2 GND ---- 0V 3 Serial data ---- P0 4 ShiftClock ---- P1 5 LatchClock ---- P2 } \ =========================================================================== \ Variables \ =========================================================================== variable value variable number \ =========================================================================== \ Constants \ =========================================================================== 0 wconstant DATA 1 wconstant SCLK 2 wconstant LCLK clkfreq d400 u/ constant 2.5msec wvariable SegData -2 allot hFC c, h60 c, hDA c, hF2 c, h66 c, hB6 c, hBE c, hE4 c, hFE c, hF6 c, hEE c, h3E c, h1A c, h7A c, h9E c, h8E c, \ =========================================================================== \ Set I/O \ =========================================================================== : data_l DATA pinlo ; : data_h DATA pinhi ; : sclk_l SCLK pinlo ; : sclk_h SCLK pinhi ; : lclk_l LCLK pinlo ; : lclk_h LCLK pinhi ; \ =========================================================================== \ Main \ =========================================================================== \ Initialize shift_register \ ( -- ) : init_sr DATA 3 0 do dup pinout 1+ loop drop ; \ Shift out 8bit-data \ ( n -- ) n:8bit data : shift_data 1 8 0 do 2dup and if data_h else data_l then sclk_h sclk_l 1 lshift loop 2drop ; \ Set shift-register to output \ ( -- ) : latch_out lclk_h lclk_l ; \ Test Hardware \ ( -- ) : hw_test 8 0 do 1 i lshift hFF xor 8 0 do \ Send data for dynamic-drive dup shift_data \ Send 7Segment-LED's each element(a,b,cd,e,f,g.dp) 1 7 i - lshift shift_data \ Display 7Segment-LED's each element(a,b,cd,e,f,g.dp) latch_out d200 delms loop drop loop ; \ 7-Segment Drive(400Hz) \ ( -- ) : 7SEG_drive init_sr begin value L@ hF0000000 cnt COG@ 2.5msec + rot2 8 0 do 1 i lshift hFF xor shift_data \ Drive LED-common siganal 2dup and d28 i 4 u* - rshift SegData + C@ \ Get 7-Segment data shift_data latch_out \ Display 7Segment-LED's each element(a,b,cd,e,f,g.dp) 4 rshift rot 2.5msec waitcnt rot2 loop 3drop \ fkey? swap drop 0 until ; : demo init_sr hw_test c" 7SEG_drive" 0 cogx d1000 0 do i value L! d10 delms loop ;