Searching \ for 'Parity generation ?' in subject line. ()
Help us get a faster server
FAQ page: www.piclist.com/techref/index.htm?key=parity+generation
Search entire site for: 'Parity generation ?'.

Truncated match.
'Parity generation ?'
1998\05\09@235927 by

I remember a list discussion about parity generation a while back
but a search of the piclist archive doesn't turn it up. Could someone
share with me either the code, a pointer to the code or just the
theory

James & Ili
Irving, TX. 75038

>I remember a list discussion about parity generation a while back
>but a search of the piclist archive doesn't turn it up. Could someone
>share with me either the code, a pointer to the code or just the
>theory

Easy

The parity bit can be set in five ways.

Even, Odd, mark, space, or none.

None is easy, nonexistent, don't send it.
Mark and space are easy, transmit your data bits, then set the parity bit to
1 or 0, and send
Even results in always an even number of set bits in the byte: 00000000 P=0
00000001 P=1
Odd results in always an odd number of set bits in the byte:    00000000 P=1
00000001 P=0

That's all there is! :)

James & Ili <PICLISTMITVMA.MIT.EDU> wrote:

> I remember a list discussion about parity generation a while back
> but a search of the piclist archive doesn't turn it up. Could
> someone share with me either the code, a pointer to the code or just
> the theory of the code please ??

James & Ili:

Here are the two routines I posted; Scott Dattalo and others posted
routines, as well.

;
; Even parity generation in seven words / seven cycles.  Enter with
; data byte in register "X"; exits with even parity in bit 1 (and
; also bits 2, 3, 4, and 5) of "X".
;

PARITY_1:           ; X:              W:
; ------------    ------------
SWAPF   X,W     ;     ABCDEFGH        EFGHABCD
;
XORWF   X       ;     ABCDEFGH        EFGHABCD
; xor EFGHABCD
;
RRF     X,W     ;                     -ABCDEFG
;                 xor -EFGHABC
;
XORWF   X       ;     ABCDEFGH
; xor EFGHABCD
; xor -ABCDEFG
; xor -EFGHABC
;
RRF     X,W     ;                     -ABCDEFG
;                 xor -EFGHABC
;                 xor --ABCDEF
;                 xor --EFGHAB
;
RLF     X       ;     BCDEFGH-
; xor FGHABCD-
; xor ABCDEFG-
; xor EFGHABC-
;
XORWF   X       ;     BCDEFGH-
; xor FGHABCD-
; xor ABCDEFG-
; xor EFGHABC-
; xor -ABCDEFG
; xor -EFGHABC
; xor --ABCDEF
; xor --EFGHAB

;
; This one takes 19 words, but executes in either 5 or 7 cycles,
; INCLUDING the test-and-branch at the end of the routine.
;
; Oh... And this one doesn't affect X, either.
;

PARITY_2:

SWAPF   X,W
XORWF   X,W
ANDLW   00001111B

GOTO    ZERO
GOTO    ONE
GOTO    ONE
GOTO    ZERO
GOTO    ONE
GOTO    ZERO
GOTO    ZERO
GOTO    ONE
GOTO    ONE
GOTO    ZERO
GOTO    ZERO
GOTO    ONE
GOTO    ZERO
GOTO    ONE
GOTO    ONE

ZERO:
....

ONE:
....

-Andy

=== Andrew Warren - fastfwdix.netcom.com
=== Fast Forward Engineering - Vista, California
=== http://www.geocities.com/SiliconValley/2499 (personal)

Grahams working code with parity:
*note: two macros used, I find it pretty deadly doing literal to file
shifts and file to file shifts with seperate code lines. macros are
"BTG" and "WMOVL"

(even parity)

;BASIC SETUP INFO:

BAUD_LOOPS      EQU     D'251'  ;1200 BAUD @ 5.58 MHz
ASCII           (SPARE DATA RAM VARIABLE FOR TX DATA)
DEL_A           (SPARE DATA RAM VARIABLE)
#DEFINE         _TX_SCI PORTB,0  ;( REPLACE AS APPLICABLE )

;macro working variables:

MV1     EQU     0
MV2     EQU     0

macro definitions:
WMOVL   MACRO   MV1,MV2 ;       LITERAL TO FILE
NOEXPAND
MOVLW   MV1
MOVWF   MV2
ENDM

WMOVF   MACRO   MV1,MV2 ;       FILE TO FILE
NOEXPAND
MOVF    MV1,W
MOVWF   MV2
ENDM

BTG     MACRO   MV1,MV2 ;       BIT TOGGLE
NOEXPAND
MOVLW   1 << MV2
XORWF   MV1,F
ENDM

;======================================

;transmit code:

ASCII_TX_OUT
START_BIT
CALL    ASYNC_H
TX_ASCII
WMOVL   07,DEL_A        ; (7 BITS DATA, " MOVLW D'07' ",
;               " MOVWF DEL_A " )
EACH_BIT
BTFSC   ASCII,0
GOTO    BZZ_HOT
CALL    ASYNC_H
GOTO    DUN_BZZ
BZZ_HOT
CALL    ASYNC_L
BTG     TASK_FLAGS,PARITY       ; (BTG IS MACRO,  " MOVLW 1 << PARITY ",
;                 " XORWF       MV1,F "
)
DUN_BZZ
RRF     ASCII,F
DECFSZ  DEL_A,F
GOTO    EACH_BIT
SEND_PARITY
GOTO    BZZ_HOTP
CALL    ASYNC_H
GOTO    DUN_BZZP
BZZ_HOTP
CALL    ASYNC_L
DUN_BZZP
CALL    ASYNC_L
RETURN

;==========================================

ASYNC_L
WMOVL   BAUD_LOOPS,CYCLES
BSF     _TX_SCI
LTL_LOOP
DECFSZ  CYCLES,F
GOTO    LTL_LOOP
RETURN

;==========================================

ASYNC_H
WMOVL   BAUD_LOOPS,CYCLES
BCF     _TX_SCI
HTL_LOOP
DECFSZ  CYCLES,F
GOTO    HTL_LOOP
RETURN

;==========================================

James & Ili wrote:
{Quote hidden}

James & Ili wrote:
{Quote hidden}

Apologies all,
previous message XTAL frequency wrong
trim
> BAUD_LOOPS      EQU     D'251'  ;1200 BAUD @ 5.58 MHz trim (transmit parity de
mo)