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 support@ccsinfo.com

Strange Hyperterminal output

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



Joined: 30 Oct 2003
Posts: 209
Location: Norfolk, England

View user's profile Send private message Send e-mail Visit poster's website MSN Messenger

Strange Hyperterminal output
PostPosted: Mon Aug 31, 2009 5:41 am     Reply with quote

Head scratched:
Code:
#use rs232(baud=1200,xmit=PIN_C6,rcv=PIN_C7,bits=8,parity=N,stream=PC)


Code:

/*******************************************************************************
* 7bit communications
* Purpose:  calcaultes even parity and transmits 7bits, E, 1stop via 8bit,N
*           hardware.
*/
void seven_bit(int8 txbyte) {
int8 i;
int1 parity;
for (i=0;i<7;i++)
   if (bit_test(txbyte,i)) parity++;
if (parity) bit_set(txbyte,7);
fputc(txbyte,PC);
} // 7bit


This works a treat when I set SIOW to use "1200-7-E No Handshaking", both directional comms to the PIC works flawless.

However when I set up hyper-terminal on the same PC same hardware, same PIC code I get gobbledegook on hyper-terminal.
Any ideas?
I add that another peripheral which is advertised as 1200-7-E works fine with both SIOW and Hyper-terminal set up the same way. So it's my PIC which is playing up!
Will Reeve



Joined: 30 Oct 2003
Posts: 209
Location: Norfolk, England

View user's profile Send private message Send e-mail Visit poster's website MSN Messenger

PostPosted: Mon Aug 31, 2009 5:53 am     Reply with quote

Code:
int1 parity;
should be
Code:
int1 parity  = 0;


Obviously siow is working differently to hyper-terminal!

Now I need to speed this code up. A quick search looks like a look-up table *may* be quicker?
Ttelmah
Guest







PostPosted: Mon Aug 31, 2009 7:30 am     Reply with quote

Quicker, but slightly bulkier:
Code:

if (bit_test(txbyte,0)^bit_test(txbyte,1)^bit_test(txbyte,2) \
^bit_test(txbyte,3)^bit_test(txbyte,4)^bit_test(txbyte,5) \
^bit_test(txbyte,6)) bit_set(txbyte,7);

The individual bit tests, on a fixed bit number, each code to just four instructions (returning 0/1). The XOR's are one instruction each. The whole thing takes just 36 instruction times.
I think this may be almost as fast as the lookup table. The 'setup' for the lookup table, will probably be about 20 instructions, so by the time the value is returned, there won't be much in it, and the lookup table, will use 128 bytes for the table, plus the lookup code....

Best Wishes
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Mon Aug 31, 2009 11:11 am     Reply with quote

The fasted routine for parity calculation I've seen takes only 9 instruction cycles!!!

It was posted by John Payson with comments from Andrew Warren in: http://www.piclist.com/techref/microchip/math/bit/parity.htm
The same code was posted by an anonymous user at http://www.mindhertz.com/Parity.php (now offline?) and used by Mark and Neutone in http://www.ccsinfo.com/forum/viewtopic.php?p=19609

The same routine was also discussed by a Guest user and PCM Programmer in: http://www.ccsinfo.com/forum/viewtopic.php?p=37330
Code:
int8 find_parity(int8 data)
{
  #asm
  swapf data, W
  xorwf data, F
  rrf   data, W
  xorwf data, F
  btfsc data, 2
  incf  data, F
  movf  data, W
  andlw 1
  movwf _return_
  #endasm
Ttelmah
Guest







PostPosted: Mon Aug 31, 2009 11:40 am     Reply with quote

You'll have to add a couple of instructions to this, since it just returns the parity. This will need to be tested, and put into bit seven, but I'd guess it'll still be easily under 15 instructions.
Better than a table solution, and very elegant. Smile

Best Wishes
Will Reeve



Joined: 30 Oct 2003
Posts: 209
Location: Norfolk, England

View user's profile Send private message Send e-mail Visit poster's website MSN Messenger

PostPosted: Wed Sep 02, 2009 1:30 am     Reply with quote

I can't seem to get that assembler to compile for a PIC18, stumbles on the first line.
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