fl { Inifinity LED PropForth 5.5 2013/09/20 21:28:38 Inifinity LED cuicuit Propeller 1 VDD ---- 3.3V 2 GND ---- GND 3 Serial data ---- P8 4 ShiftClock ---- P9 5 LatchClock ---- P10 ---------------------------------------------------------------------- GND |COM |COM |COM |COM | | | | 220ohm 220ohm 51ohm 51ohm | | | | LED1(red) ---LED8(red) LED1(blue) --- LED8(blue) 2-colorLED:OSRB5131A anode anode anode anode | | | | ------------------------- ------------------------- | Qa ----------- Qh Vcc|--3.3V | Qa ----------- Qh Vcc|--3.3V | 3.3V ----|RESET | 3.3V ----|RESET | P8 -----|A 74HC595 SQh|-----------|A 74HC595 SQh| P9 -----|SCLK | P9 -----|SCLK | P10 -----|LCLK OE | P10 -----|LCLK OE | ------------------------- ------------------------- | | GND GND } \ =========================================================================== \ Constants \ =========================================================================== 8 wconstant DATA 9 wconstant SCLK d10 wconstant LCLK \ =========================================================================== \ 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 ; \ Set shift-register to output \ ( -- ) : latch_out lclk_h lclk_l ; \ Shift out 16bit-data and latch data \ ( n -- ) n:16bit data b0-b7:Red b8-b15:Blue : shift_16 d16 lshift \ Out firstly bit16 h80000000 d16 0 do 2dup and if data_h else data_l then sclk_h sclk_l 1 rshift \ next bit loop 2drop latch_out ; \ Clear shift-register \ ( -- ) : clr_sr 0 shift_16 latch_out ; \ Test Hardware \ ( -- ) : hw_test init_sr d16 0 do 1 i lshift shift_16 d500 delms loop clr_sr ; \ Move LED-blink to CW \ ( n1 -- n2 ) n1:8bit n2:(8bits) n1 shifted bit to left(if bit8 is 1, set bit0 to 1) : cw 1 lshift dup h100 and if 1 or hFF and then ; \ Move LED-blink to CCW \ ( n1 -- n2 ) n1:8bit n2:(8bits) n1 shifted bit to right(if bit0 is 1, set bit7 to 1) : ccw dup 1 and if h100 or then 1 rshift ; : demo init_sr hAA h55 8 lshift or shift_16 d500 delms h55 hAA 8 lshift or shift_16 d500 delms \ Rotate red-LED to cw-direction h1FE shift_16 d500 delms 1 hFE \ red-LED:1pc blue-LED:7pcs begin 6 0 do d24 0 do 2dup 8 lshift or shift_16 cw swap cw swap d50 delms loop 1 lshift hFF and swap 1 lshift 1 or hFF and swap \ Increase red-LED, decrease blue-LED loop \ Rotate blue-LED to cw-direction 7 0 do d24 0 do 2dup 8 lshift or shift_16 cw swap cw swap d50 delms loop 1 lshift 1 or hFF and swap 1 lshift hFF and swap \ Decrease red-LED, increase blue-LED loop fkey? swap drop until 2drop clr_sr ;