gnupic: Optimiziing Forth compiler for mid-range PICs
Subject:
Re: Optimiziing Forth compiler for mid-range PICs
From:
Francisco Rodrigo Escobedo Robles ####@####.####
Date:
7 Mar 2000 23:56:01 -0000
Message-Id: <200003072343.XAA01468@xinef.pepix.net>
Oops. There were a pair of bugs in my code for the ping-pong led bar. The
correct code for the PINGPONG word is:
-----8<-----
: PINGPONG ( -- ) ( A FULL CYCLE OF LED BAR PING PONG )
2 CONST, ( INITIAL VALUE, FIRST HALF CYCLE )
BEGIN
DUP
WHILE
DUP PORTB !
MYDELAY DELAY
2* ( EQUIVALENT TO A LEFT SHIFT )
REPEAT
DROP
40 CONST, ( INITIAL VALUE, SECOND HALF CYCLE )
BEGIN
DUP
WHILE
DUP PORTB !
MYDELAY DELAY
2/ ( EQUIVALENT TO A RIGHT SHIFT )
REPEAT
DROP
;
-----8<-----
So, the 2 DROPs make sure the current value for the led bar is gone when not
needed.
Alternatively, we can use a table, so we have total control of the pattern:
-----8<-----
TABLE PINGPONGPATTERN ( TABLE FOR LED BAR PINGPONG PATTERN )
01 , 02 , 04 , 08 , 10 , 20 , 40 , ( FIRST HALF CYCLE )
80 , 40 , 20 , 10 , 08 , 04 , 02 , ( SECOND HALF CYCLE )
0E CONSTANT MAXPATTERN
: LEDPATTERN ( -- ) ( A FULL CYCLE OF LED BAR PATTERN )
0 CONST, ( INITIAL VALUE )
BEGIN
DUP MAXPATTERN <
WHILE
DUP PINGPONGPATTERN PORTB !
MYDELAY DELAY
REPEAT
DROP
;
( HERE COMES MAIN PROGRAM CODE )
MAIN
BEGIN
LEDPATTERN
AGAIN
-----8<-----
Adding this code and deleting that of old PINGPONG we have a new, more general
example.
---
Francisco Rodrigo Escobedo Robles - ####@####.####
El surrealismo vive en Pepix Labs - http://www.pepix.net/
Este mensaje expresa unicamente mi opinion en este momento