7bit ascii with odd parity

For E-blocks user to discuss using E-blocks and programming for them.

Moderators: Benj, Mods

Post Reply
Desdewit
Posts: 130
Joined: Sat Feb 26, 2011 4:26 am
Location: South Africa
Has thanked: 25 times
Been thanked: 11 times
Contact:

7bit ascii with odd parity

Post by Desdewit »

Hi Guys

Does anyone have some flowcode to receive 7bit ascii with odd parity on a pic 16f877.
I tried to receive 7bit ascii with odd parity from a Instrotech 5004 instrument but it keeps changing some characters like a
0 to - and a 3 to some weird character. :cry: :cry: :cry: Struggling for more than a year now please help if possible.
ASM code will also do if iets the only way.

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: 7bit ascii with odd parity

Post by Benj »

Hello,

Have you looked at this forum topic?

http://www.matrixmultimedia.com/mmforum ... ity#p19866

Desdewit
Posts: 130
Joined: Sat Feb 26, 2011 4:26 am
Location: South Africa
Has thanked: 25 times
Been thanked: 11 times
Contact:

Re: 7bit ascii with odd parity

Post by Desdewit »

Yes Ben I Imported & tried like you explaned but the data on my lcd does the same thing if you look at the ascii table and its binary it looks like there are a one infront of all the bytes coming thru so iet sends the ascii code for that like 0 shows as -
(It might be the start bit but I don't know how to work around that in flowcode.) as I am new to flowcode.

This is the info from the manual of the instrument I'm trying to read from.

The data format string output from the indicator is as follows. (7 bit ASCII code is used):
Line Settings : 7 Data Bits, 1 Parity bit, Odd Parity, 1 Stop Bit.
Baud Rate : Selectable 2400, 4800, 9600, 19200.(I'm using 9600)
Data Bits : Numerical ASCII characters : 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
Other ASCII characters : #, blank/space, +, -, CR, LF
Protocol format is : # A A S D D D D D D D D P CR LF
where : # = indicates start of message
: A A = Instrument address. ASCII 00 to 99. 00 is default.
: S = sign (polarity) ( ASCII "+" or "-" ).
: D = data bits (data for 8 numerals). See Note (1).
: P = decimal point position. ASCII 0 to 8.
: CR = ASCII carriage return.
: LF = ASCII line feed.

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: 7bit ascii with odd parity

Post by Benj »

Hello,

The RS232 component will automatically ignore the start bit and will expect 8 data bits followed by a stop bit.

You could remove the parity bit altogether if you like by reading the data and then masking off the parity bit.

data = ReceiveRS232Char
data = data & 0x7F

If you have to send data back out with the parity bit then you will need to calculate this as shown in the last post.

Regarding your problem where you are seeing "0" come in as "-".

If you look at the ascii for these characters: http://www.asciitable.com

"0" = 0b00110000
"-" = 0b00101101

These seem odd as they are very dissimilar.

Have you confirmed your Flowcode clock speed and configuration settings are correct by creating a 1 second flasher program? If not then its probably worth doing this first to ensure that your not calculating the baud rate incorrectly.

Desdewit
Posts: 130
Joined: Sat Feb 26, 2011 4:26 am
Location: South Africa
Has thanked: 25 times
Been thanked: 11 times
Contact:

Re: 7bit ascii with odd parity

Post by Desdewit »

Ben

If you look at the attached file all the character under lighned in red comes thru like they should but you will see that the numbers with different colors are replaced by the signs with the same color.
If I use HyperTerminal with 9600,8,N,1 to send the characters it work fine but when I set HyperTerminal to send with 9600,7,odd,1 I get the same characters as from the Instrotech instrument.

I'm using a Version 3 PICmicro MCU development board Model HP488-00-3 with a pic16f877
Attachments
Character map.JPG
Character map.JPG (118.03 KiB) Viewed 10530 times

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: 7bit ascii with odd parity

Post by Benj »

Hello,

Right ok it looks like this code should work for you to remove the parity bit.

Component Macro: data = ReceiveRS232Char
Calculation: data = data & 0x7F

This code clears the most significant bit that is causing your incoming characters to appear as 0b1011xxxx instead of 0b0011xxxx.

Desdewit
Posts: 130
Joined: Sat Feb 26, 2011 4:26 am
Location: South Africa
Has thanked: 25 times
Been thanked: 11 times
Contact:

Re: 7bit ascii with odd parity

Post by Desdewit »

Ben

Thank you for your time & effort. So far my program is working between HyperTerminal set at 7bit,odd,n,1 and my pic
Now it’s just for the final test from the instrument.
Hope you have a wonderful day.
:lol: :lol: :lol:

Desdewit
Posts: 130
Joined: Sat Feb 26, 2011 4:26 am
Location: South Africa
Has thanked: 25 times
Been thanked: 11 times
Contact:

Re: 7bit ascii with odd parity

Post by Desdewit »

Ben

I've tested my program with the instrument & it works fine, I just need to get rid of the leading zeros.
What do I need to do if I want to capture the value on my display and add it to another value.

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: 7bit ascii with odd parity

Post by Benj »

Hello,

To convert your incoming character to a decimal number eg 0 to 9 you simply have to subtract '0' eg the character 0.

To add together multiple numbers you will need to repeat this process and then times each of the values by the decimal multiplier.

eg.

byte0 = byte0 - '0'
byte1 = byte1 - '0'
byte2 = byte2 - '0'

Number = (byte2 * 100) + (byte1 * 10) + byte0

Desdewit
Posts: 130
Joined: Sat Feb 26, 2011 4:26 am
Location: South Africa
Has thanked: 25 times
Been thanked: 11 times
Contact:

Re: 7bit ascii with odd parity

Post by Desdewit »

The multiplier part makes sense but if I receive a number like 031045 won’t it remove both zeros instead of just the first one because the six digits coming thru will change the whole time like on a scale instrument.

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: 7bit ascii with odd parity

Post by Benj »

Hello,

It shouln't do as long as your using an INT type variable to store a number that big.

eg.

31045

3 x 10000 = 30000
1 x 1000 = 1000
0 x 100 = 0
4 x 10 = 40
5 x 1 = 5

Added together = 31045 :mrgreen:

INT variable can hold between -32768 and 32767

Desdewit
Posts: 130
Joined: Sat Feb 26, 2011 4:26 am
Location: South Africa
Has thanked: 25 times
Been thanked: 11 times
Contact:

Re: 7bit ascii with odd parity

Post by Desdewit »

Hi Ben

Please have a look at my prog. and see if you can see were I'm going wrong.
The attatched prog. can recieve the data and show it like +123456 but if the instrument sends a short number like +321 the lcd wil show +000321
The instrument can send any number from 0 to 199999
I tried to remove the leading zeros like you said but then I get the wrong characters on the lcd.

The data format string output from the indicator is as follows. (7 bit ASCII code is used):
Line Settings : 7 Data Bits, 1 Parity bit, Odd Parity, 1 Stop Bit.
Baud Rate : I'm using 9600
Data Bits : Numerical ASCII characters : 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
Other ASCII characters : #, blank/space, +, -, CR, LF
Protocol format is : # A A S D D D D D D D D P CR LF
where : # = indicates start of message
: A A = Instrument address. ASCII 00 to 99. 00 is default.
: S = sign (polarity) ( ASCII "+" or "-" ).
: D = data bits (data for 8 numerals). See Note (1).
: P = decimal point position. ASCII 0 to 8.
: CR = ASCII carriage return.
: LF = ASCII line feed.
Attachments
Temp.fcf
(31.11 KiB) Downloaded 337 times

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: 7bit ascii with odd parity

Post by Benj »

Hello,

This should work for you now. It basically allows the input number to be ignored while the most significant digits are 0.
Attachments
Temp.fcf
(31.53 KiB) Downloaded 290 times

Post Reply