[PicForth] Re: (no subject)
Samuel Tardieu
sam at rfc1149.net
Wed Mar 16 19:19:36 CET 2005
>>>>> "Polly" == bitwLister <lister at bitwisetech.com> writes:
Polly> I can't make the 'toggle' work .. the port in question is
Polly> all outputs and picforth seems to compile an xorwf instruction
Polly> .. Isn't there something about a read-modify-write not working
Polly> in this case ??
It depends. If your PIC is authoritative in the output and that the
lines switches from low to high and vice-versa in less than one PIC
clock, then you are safe. And this covers most cases.
Otherwise, you can use toggle on this port as PicForth as no way to
know what you put in the port last. You have to write your own toggle,
for example, if this is on port C that you're writing, you could have:
variable latc
:: report-latch latc @ portc ! ;
:: latc-or! latc or! report-latch ;
:: latc-/and! latc /and! report-latch ;
:: latc-xor! latc xor! report-latch ;
macro
: >lat 1 swap lshift ;
: latc-bit-set >lat latc-or! ;
: latc-bit-clr >lat latc-/and! ;
: latc-bit-toggle >lat latc-xor! ;
target
Then you will be able to use a safe version of the port with:
: foo 2 latc-bit-toggle ; / Toggle pin C2
Which expands to:
; name: foo
; max return-stack depth: 0
0x0016 3004 movlw 0x04
0x0017 2812 goto 0x012 ; latc-xor!
Sam
--
Samuel Tardieu -- sam at rfc1149.net -- http://www.rfc1149.net/sam
More information about the PicForth
mailing list