Check specific bit of a byte
qsuscs
Posts: 12
Hi,
for my morse keyer, I have to get the sequence for every letter. It is either "dit" or "dah" some times, e.g. the letter A is "dit dah", the letter B is "dah dit dit dit", and so on. A PIC programmer told me how he stored the "codes": one byte per character, consisting of zeroes, the startbit and a 0 for "dit" and a 1 for "dah". So a A would be stored as %0000_0101, a B would be %0001_1000, etc. The program shall read from Bit #7 to #1, if it's 0, continue reading, it it's 1, go ahead and issue dit or da for 0 or 1. My implementation looks like that:
But this code doesn't work, I don't hear any output. The methods dit and dah are definitely working, I tested them.
What am I doing wrong?
for my morse keyer, I have to get the sequence for every letter. It is either "dit" or "dah" some times, e.g. the letter A is "dit dah", the letter B is "dah dit dit dit", and so on. A PIC programmer told me how he stored the "codes": one byte per character, consisting of zeroes, the startbit and a 0 for "dit" and a 1 for "dah". So a A would be stored as %0000_0101, a B would be %0001_1000, etc. The program shall read from Bit #7 to #1, if it's 0, continue reading, it it's 1, go ahead and issue dit or da for 0 or 1. My implementation looks like that:
sign := byte[@A] repeat i from 7 to 0 if sign[i] == 1 repeat j from i-1 to 0 case sign[j] 0 : dit 1 : dah waitdit quit DAT A byte %0000_0101dit and dah are methods, sign, i and j are declared as byte.
But this code doesn't work, I don't hear any output. The methods dit and dah are definitely working, I tested them.
What am I doing wrong?
Comments
1) Use bitmasks (|<) and the bit logical operations (& | ^ !)
2) Move your value to one of the unused special function registers (OUTB or DIRB) and use the bit access syntax there
To check for bit x, do: "IF sign & |< x" or "IFNOT sign & |< x" (note: IFNOT is one word).
A couple years ago I did lighting control for this display, which included Morse Code output of the character names (Mourningstar and Typhon) from the back of their costumes:
At that particular convention, G4 TV did an interview with Steve Wang (his shop built the display) and the Morse Code IFF output from the characters was a big topic of discussion. I chucked it in for fun as I had an extra cog!
Here's the code I converted from a Scott Edwards program for the BASIC Stamp 1 (grandfather of the Propeller); you'll need to define timing constants.
Scott uses a clever scheme of encoding the length (number of dits and dahs) in the lower three bits of the character code. See page 39 of this document for Scott's original BS1 project:
-- http://www.parallax.com/Portals/0/Downloads/appnt/stamps/bs1Appnotes.pdf
Code is at GitHub: https://github.com/qsuscs/PropCW