-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #408 from TG9541/onewire
Onewire and minor UM/MOD improvement
- Loading branch information
Showing
4 changed files
with
46 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
\ STM8 eForth: CRC8 for 1-Wire protocol, polynomial x8 + x5 + x4 + 1 | ||
\ refer to github.com/TG9541/stm8ef/blob/master/LICENSE.md | ||
|
||
\ implementation for 1-wire protocol | ||
|
||
: CRC8 ( crc c -- crc ) [ \ 1-Wire CRC8 | ||
$A608 , \ LD A,#8 ; loop through 8 bits | ||
$F7 C, \ LD (X),A ; use MSB as bit counter | ||
$E601 , \ LD A,(1,X) ; | ||
$E803 , \ 1$: XOR A,(3,X) ; crc XOR c.bit0 | ||
$46 C, \ RRC A ; to carry | ||
$E603 , \ LD A,(3,X) ; crc -> A | ||
$2402 , \ JRNC 0$ | ||
$A818 , \ XOR A,#0x18 ; apply x5 + x4 | ||
$46 C, \ 0$: RRC A ; apply x8 + 1 | ||
$E703 , \ LD (3,X),A ; update crc value | ||
$6401 , \ SRL (1,X) ; next c.bit0 | ||
$E601 , \ LD A,(1,X) | ||
$7A C, \ DEC (X) ; bit counter until 0 | ||
$26ED , \ JRNE 1$ ; loop? | ||
$5C C, \ INCW X ; DROP | ||
$5C C, \ INCW X | ||
] ; | ||
|
||
\\ Test | ||
|
||
\ DALLAS MAXIM AN937 Figure 3 Example Calculation for DOW CRC | ||
HEX 0 2 CRC8 1C CRC8 B8 CRC8 1 CRC8 0 CRC8 0 CRC8 0 CRC8 . DECIMAL \ -> A2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
\ STM8eForth : LSHIFT TG9541-210301 | ||
\ refer to github.com/TG9541/stm8ef/blob/master/LICENSE.md | ||
|
||
: LSHIFT ( n c - n ) \ shift n left c times | ||
[ $5C C, \ INCW X | ||
$F6 C, \ LD A,(X) | ||
$5C C, \ INCW X | ||
$4D C, \ TNZ A | ||
$2705 , \ JREQ 1$ | ||
$6801 , \ 2$: SLA (1,X) | ||
$79 C, \ RLC (X) | ||
$4A C, \ DEC A | ||
$26F8 , \ JRNE 2$ | ||
] \ 1$: | ||
; |