An 8bit byte plus parity. How?
LoopyByteloose
Posts: 12,537
Parity seems to inconviently add a 9th bit to RS-232 routines.
All the tutorial examples seem to avoid the issue [noparse][[/noparse]aparently consider this advanced, independent study]
Obviously I don't want to have 16 bits of RAM used for 8 bits of data and 1 parity bit.· So it seems that the Virtual Peripheral UART has to add and strip parity.
I sense two problems.·
1.· Timing
2.· A simple algorhtym.· {is ODD parity actually the sum of all the 1 bits plus 1?}
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"When all think alike, no one is thinking very much.' - Walter Lippmann (1889-1974)
······································································ Warm regards,····· G. Herzog [noparse][[/noparse]·黃鶴 ]·in Taiwan
All the tutorial examples seem to avoid the issue [noparse][[/noparse]aparently consider this advanced, independent study]
Obviously I don't want to have 16 bits of RAM used for 8 bits of data and 1 parity bit.· So it seems that the Virtual Peripheral UART has to add and strip parity.
I sense two problems.·
1.· Timing
2.· A simple algorhtym.· {is ODD parity actually the sum of all the 1 bits plus 1?}
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"When all think alike, no one is thinking very much.' - Walter Lippmann (1889-1974)
······································································ Warm regards,····· G. Herzog [noparse][[/noparse]·黃鶴 ]·in Taiwan
Comments
http://www.sxlist.com/techref/ubicom/lib/io/osi2/serial/elx1tmpl.htm
regards peter
·
I am trying to interface with a standard AT keyboard and it has 8bits plus odd parity. Essentially, I am trying to create my own version of Al William's device in SASM. One side is synchronous, the other side is asychronous. And it is asymetrical concerning how it uses Acknowledge.
I figure if I really am able to understand and code this, all my serial coding will be easy. I must say that I admire Al Williams for doing it and also managing to convert the key codes to ASCII.
Both SPI and I2C are cleaner to code as they don't have the parity bit and the Acknowledge when used is done to in both directions.
A very interesting challange.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"When all think alike, no one is thinking very much.' - Walter Lippmann (1889-1974)
······································································ Warm regards,····· G. Herzog [noparse][[/noparse]·黃鶴 ]·in Taiwan
It uses the 68HC705J1A uP but its mnenomics are easily translated to SX.
http://www.beyondlogic.org/keyboard/keybrd.htm
regards peter
Post Edited (Peter Verkaik) : 2/22/2006 12:49:01 PM GMT
{is ODD parity actually the sum of all the 1 bits plus 1?}
It is adding whichever bit is required to make the _total_ number of bits odd. As an example:
Data byte sent = 10101010, this will require a 1 parity bit to make the total odd. Opposite for even parity....
Jim
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
In the end, it seems that it's all about getting the LEDs to blink....
Jim
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
In the end, it seems that it's all about getting the LEDs to blink....
Apparently the algorhythm starts with an intial value of 1 or 0, dependent on the parity you want.
And then you merely XOR each bit and do a shift to the right or the left [noparse][[/noparse]as required by whatever format LSBit or MSBit first]
After all, how can you add the result when you don't already have it.
And Peter,
Your KEYBOARD code site is good [noparse][[/noparse]verifies a lot of info], but the code is over 20,000 bytes!· I will have to squeeze something.· I imagine if I have to, I can have a EEPROM do a lookup table [noparse][[/noparse]but I don't think Al Williams had to and I thought he used an SX-18].
The Keycode for the Break key really surprises me [noparse][[/noparse]8 bytes], but that is what my other data shows too.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"When all think alike, no one is thinking very much.' - Walter Lippmann (1889-1974)
······································································ Warm regards,····· G. Herzog [noparse][[/noparse]·黃鶴 ]·in Taiwan
Post Edited (Kramer) : 2/22/2006 2:16:03 PM GMT
Let's take for example 7 data bits and even parity.· Each byte is (without regard for MSB/LSB issues) something like DDDDDDDP (where D represents a data bit, and P the parity bit).
The rule is to simply count all of the D's that are·one (or high or true, if you prefer).· Then if that count is an even number, make the P a zero; if the count is odd, make the P a one so that the total number of one bits in the byte is an even number.
For ODD parity, the setting of the parity bit is so that the total number of bits in the byte is an odd number.
HTH,
Daniel
Odd number of databits 1 -> paritybit for even parity = 1
Even number of databits 1 -> paritybit for even parity = 0
paritybit for odd parity = inverted paritybit for even parity
regards peter
For more information about things serial than you want to know, go to Jan Axelson's Serial Port Central·page (http://lvr.com/serport.htm) and learn from there.· Similar information about the Parallel port, and USB, can be also obtained from her web site.
Daniel
the paritybit is part of the keyboard data, which is synchronous.
So why do you need asynchronous uart with parity?
I would convert it to uart without parity.
regards peter
·
Yes,
The easiest way to do this is to drop the parity bit on the output going into RS-232. But in that case, I still need to ADD the parity bit to input to the keyboard from the RS-232. [noparse][[/noparse]I suspect IBM intended to make this a very difficult interface to duplicate]
There is always the possiblity that one might want to preserve the parity in this or a future project, have the destination verify it, and make requests to resend.
I suppose here it would best best to just trap it as an error and immediately ask for the keyboard to resend its output to the SX. But still, that requires one to recalculate parity and compare it. It certainly would simplify the RS-232 output. Adding a 9th bit is a big project.
Seems impossible to do without a parity calculation in at least one direction, if not both.
I took a look at Peter V's code and was quite surprised by the way parity is calculated - boolean logic rather than a simple iteration of XORs. It seems there are at least 4 ways to do this. I guess this saves program space and time.
BTW< I got all four parity calculation examples at http://www.sxlist.com
That is where Peter V. posted his code and made reference to his source for parity code.
Seems that I have been ignoring an excellent resource for SX SASM code examples. Everyone should try SXLIST for more support.
Daniel,
Jan Axelson has several good books. I noticed yesterday that all are ON SALE at Amazon. I am more interested in her Ethernet text.
I may at times seem pedantic too, but it is exactly because there are others that might be struggling with similar issues, but not jumping in. If I look only at who is logged on, I begin to think I am one one of maybe 10 beginners to SASM. I am sure that isn't the case.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"When all think alike, no one is thinking very much.' - Walter Lippmann (1889-1974)
······································································ Warm regards,····· G. Herzog [noparse][[/noparse]·黃鶴 ]·in Taiwan
Remember, odd parity is inverted even parity.
For 7databits, bit7 is cleared before entering this code.
(a 0 bit has no effect)
·; calculate even parity for w
; result in temp.0
;
even_parity
mov temp,w
;calculation code by John Payson, as found on sxlist.com
;This routine will leave the parity of temp in temp.0
;while blenderizing most of the rest of temp
mov w,<>temp ; temp = abcdefgh
xor temp,w
mov w,>>temp
xor temp,w
; at this point, the parity for half the bits
; (a, b, e, and f) is in bit 2 of temp, and the
; parity for the other half (bits c, d, g, and h)
; is in bit 0 of temp.
snb temp.2 ; if the parity of (a,b,e,f) is 0,
······················· ; then the parity of (a,b,c,d,e,f,g,h)
······················· ; is equal to the parity of (c,d,g,h)...
······················· ; which is already in bit 0, so skip ahead.
inc temp ; otherwise, the parity of (a,b,e,f) is 1,
; so the parity of (a,b,c,d,e,f,g,h) is
; NOT equal to the parity of (c,d,g,h).
; invert bit 0.
; at this point, bit 0 contains the parity of
; (a,b,c,d,e,f,g,h).
retp
regards peter