CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

parity function

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
mshearer



Joined: 12 Jan 2009
Posts: 33

View user's profile Send private message

parity function
PostPosted: Tue Jan 20, 2009 3:44 am     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Jan 20, 2009 4:03 am     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Jan 20, 2009 5:32 am     Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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