|
|
View previous topic :: View next topic |
Author |
Message |
mshearer
Joined: 12 Jan 2009 Posts: 33
|
parity function |
Posted: Tue Jan 20, 2009 3:44 am |
|
|
Hi
I am using the following two functions to test the parity of a sent char.
Code: | char check_parityRCREG(void)
{
char check_parity_result = FALSE;
received_byte = reg_RCREG;
if(bit_RX9D == parity_errorDetection(received_byte))
{
check_parity_result = TRUE;
}
else
{
check_parity_result = FALSE;
received_byte = ZERO;
}
return check_parity_result;
} |
Code: | char parity_errorDetection(char cms_rc_message)
{
char rx_loop_count = ZERO;
char rx_bit_count = ZERO;
char parity_detect_result = FALSE;
for(rx_loop_count = ZERO; rx_loop_count < ONE_BYTE; rx_loop_count++)
{
if((cms_rc_message & ONE) == TRUE)
{
rx_bit_count++;
}
cms_rc_message >>= ONE;
}
if((rx_bit_count & ONE) == FALSE) // Check the parity
{
parity_detect_result = TRUE;
}
else
{
parity_detect_result = FALSE;
}
return parity_detect_result;
} |
the code works well for a the majority of the time. Except on the very first inputted char, also with certain combinations, such as a 'T' following a 'Y'
Considering all the variables should be zeroed at each call, i can't figure out whats going wrong.
thanks, for any help
matt |
|
|
mshearer
Joined: 12 Jan 2009 Posts: 33
|
|
Posted: Tue Jan 20, 2009 4:03 am |
|
|
and the some more needed to compile/test etc
Code: | #include <18f4520.h>
#fuses H4,NOWDT,WDT128,NOPROTECT,NOBROWNOUT,NOPUT,STVREN,DEBUG,NOLVP,WRT,NOWRTB,NOWRTC,NOCPD,NOCPB,NOEBTR,NOEBTRB
#use delay(clock=40000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, parity=O)
#define ZERO 0x00
#define ONE 0x01
#define TWO 0x02
#define ONE_BYTE 0x08
#byte reg_RCREG = 0xFAE
#byte reg_RCSTA = 0xFAB
#bit bit_RX9D = reg_RCSTA.0
#byte reg_PIR1 = 0xF9E
#bit bit_RCIF = reg_PIR1.5
char received_byte= 0;
char check_parityRCREG(void);
char parity_errorDetection(char cms_rc_message);
void main(void)
{
while(1)
{
if(bit_RCIF == TRUE)
check_parityRCREG();
}
} |
|
|
|
mshearer
Joined: 12 Jan 2009 Posts: 33
|
|
Posted: Tue Jan 20, 2009 5:32 am |
|
|
turns out my terminal program isn't sending a reliable 'odd' parity
the first 'Y' will give parity bit '0'
from then on it will give '1'
bit of a pain |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|