embedded systems developers tools, cross compilers
  Home  |   SwiftX Archive  |   SwiftForth Archive  |

Re: Dallas one - wire on avr

From: Charles Steinkuehler <charles_at_steinkuehler.net>
Date: Thu, 18 Nov 2004 11:16:24 -0600

Leon Wagner wrote:

> Definitly write this in assembler. The bit-level I/O instructions (SBI and
> CBI) on the AVR are exactly what you need. Here's all the code needed to
> toggle bit 0 of Port A:
>
> CODE TOGGLE
> 0 PORTA SBI 0 PORTA CBI
> RET END-CODE
>
> Note: There's no "interpreter overhead" inside a SwiftX/AVR definition.
>
> : TOGGLE FF PORTA C! 0 PORTA C! ;
>
> SEE TOGGLE
>
> 18F0 FF R16 LDI 0FEF
> 18F2 R16 1B OUT 0BBB
> 18F4 0 R16 LDI 00E0
> 18F6 R16 1B OUT 0BBB
> 18F8 RET 0895

...or just make yourself a few inline assembly words to twiddle the port,
which you can then use inside a normal colon definition. I had a similar
problem recently (bit-banging an "almost" I2C bus that I couldn't use the
on-board I2C engine to talk to).

EXAMPLE CODE:
NOTE: I created duplicate words in both the compiler and assembler word
lists so I could easily write with either colone or code definitions:

COMPILER

: shtscl- ( -- )
    [+ASSEMBLER] PC0 PORTC CBI [PREVIOUS] ;

: shtscl+ ( -- )
    [+ASSEMBLER] PC0 PORTC SBI [PREVIOUS] ;

: shtsda- ( -- )
    [+ASSEMBLER] DDC1 DDRC SBI [PREVIOUS] ;

: shtsda+ ( -- )
    [+ASSEMBLER] DDC1 DDRC CBI [PREVIOUS] ;

ASSEMBLER

: shtscl- ( -- )
    [+ASSEMBLER] PC0 PORTC CBI [PREVIOUS] ;

: shtscl+ ( -- )
    [+ASSEMBLER] PC0 PORTC SBI [PREVIOUS] ;

: shtsda- ( -- )
    [+ASSEMBLER] DDC1 DDRC SBI [PREVIOUS] ;

: shtsda+ ( -- )
    [+ASSEMBLER] DDC1 DDRC CBI [PREVIOUS] ;

\ Execute next instruction if SDA is Low
: shtsdaL? ( -- )
    [+ASSEMBLER] PINC1 PINC SBIS [PREVIOUS] ;

\ Execute next instruction if SDA is High
: shtsdaH? ( -- )
    [+ASSEMBLER] PINC1 PINC SBIC [PREVIOUS] ;

TARGET

: SHT-reset ( -- )
    shtsda+
    12 BEGIN
       shtscl+ shtscl-
       1-
       DUP 0=
       UNTIL ;

: SHT-start ( -- )
    shtscl-
    shtsda+
    shtscl+
    shtsda-
    shtscl-
    shtscl+
    shtsda+
    shtscl- ;

-- 
Charles Steinkuehler
charles_at_steinkuehler.net
----------------------------------------------------------------------
swiftx_at_forth.com          The SwiftX programming discussion email list
To unsubscribe, send subject "unsubscribe" to swiftx-request_at_forth.com
For list command help, send subject "help" to swiftx-request_at_forth.com
Message archives are located at http://www.forth.com/archive/swiftx
----------------------------------------------------------------------
This list is a forum for SwiftX users.  For product support and bug 
reports, please send email to support_at_forth.com
----------------------------------------------------------------------
Received on Thu Nov 18 2004 - 09:16:56 PST

This archive was generated by hypermail 2.2.0 : Thu Nov 20 2008 - 03:04:47 PST