Decimal representation of a letter Question
RonP
Posts: 384
Hello All,
I modified this code Hydra Morse Code Sender from the OBEX for use in my project. The code works fine but I have a few questions about it.
Question In the original code they are receiving key strokes for the Letter to be displayed. In my my modification I am using a string in DATA for the message.The original code has the pointer written like this "A","a" : pntr := @A, which didn't work for me I was getting the Decimal representation of the Letter. So I changed the pointer to this 65,97 := pntr @A and all is fine. I am assuming that in the original codes keyboard object there is something there that produces the letter "A". I looked through the object but It wasn't clear to me, as I am new and a lot of it is in PASM. And finally the question if I needed the Letter "A" and not the decimal representation how would I go about getting it?
Sorry for probably over explaining the question, but I am new and that's how I think now.
Ron
I modified this code Hydra Morse Code Sender from the OBEX for use in my project. The code works fine but I have a few questions about it.
Question In the original code they are receiving key strokes for the Letter to be displayed. In my my modification I am using a string in DATA for the message.The original code has the pointer written like this "A","a" : pntr := @A, which didn't work for me I was getting the Decimal representation of the Letter. So I changed the pointer to this 65,97 := pntr @A and all is fine. I am assuming that in the original codes keyboard object there is something there that produces the letter "A". I looked through the object but It wasn't clear to me, as I am new and a lot of it is in PASM. And finally the question if I needed the Letter "A" and not the decimal representation how would I go about getting it?
'' MorseCode.spin ' Modified from Larry Jennings and Andre' LaMothe - Morse Code Sender Demo in OBEX ' ' Still need to work on the timeing, letter space, word space and turning ' it into an object to call from my top object. CON _clkmode = xtal1 + pll16x '80 Mhz clock _xinfreq = 5_000_000 MCpin = 16 pause = 10_000_000 VAR word Temp, Char, pntr, ltr, index, letter[6] PUB Main | ix repeat until ((Temp := byte[@Message][ix++]) == 0) ' Index the @Message string waitcnt(clkfreq/4 + cnt) ' in the DATA Block I am not Char := Temp ' reciving a letter rather the Letters(Char) ' decimal equivilant. I wonder? PUB Letters (Char_pntr) pntr := 0 case Char_pntr 65,97 : pntr:=1 'A ' Case Statement and Pointers 66,98 : pntr:=2 'B ' "B","b" : pntr:=2 'B original code sample 67,99 : pntr:=3 'C 68,100 : pntr:=4 'D 69,101 : pntr:=5 'E ltr := byte[letter[pntr]] index := 0 repeat 'Recive number from Case statement if (ltr == "1") 'and call Dot or Dash Dot if (ltr == "2") Dash ltr := byte[letter[pntr]][++index] until (ltr == 0) letter[0] := 0 'Letter Aray letter[1] := @A letter[2] := @B letter[3] := @C letter[4] := @D letter[5] := @E PRI Dot ' Dot method dira[MCpin] := outa[MCpin] := 1 waitcnt(pause + cnt) outa[MCpin] := 0 waitcnt(pause + cnt) PRI Dash ' Dash Method dira[MCpin] := outa[MCpin] := 1 waitcnt(pause * 3 + cnt) outa[MCpin] := 0 waitcnt(pause * 3 + cnt) DAT Message byte "AbCdE",0 'Message to be displayed on signal light A byte "12",0 'Data Table 1=Dot 2=Dash B byte "2111",0 C byte "2121",0 D byte "211",0 E byte "1",0
Sorry for probably over explaining the question, but I am new and that's how I think now.
Ron
Comments
I'm not sure if you understand the way ASCII works.
Char := 97
and
Char := "a"
sets Char to the exact same thing. The difference comes in how you display it.
(I'm assuming Debug is a serial object.)
Debug.dec("a")
Debug.dec(97)
Debug.dec(Char) will all output 97
Debug.tx("a")
Debug.tx(97)
Debug.tx(Char) will all output a
Message byte "AbCdE",0
could also be written as
Message byte 65, 98, 67, 100, 69, 0
Debug.str(@Message)
will output AbCdE
with either of the two Message versions above. The zero at the end tells the Propeller that it has reached the end of the string.
I hope I'm understanding your question correctly. Let me know if this isn't what you needed to know.
Duane
How are the letters displayed? I think that's where your problem is.
Duane
I am using PST to try and debug I get this ???f??? ("E" in the @Message) in the terminal window when I use pst.str(char). When I use pst.dec(char) I get the decimal value thats why I changed the original code. I don't see that tx is an option in the PST demo. I think I need to find a Debug Object that supports text I am looking in the OBEX now. Unless there is a way, I can't seem to figure it out.
I am using BST I don't know if that is an issue.
Thanks
Ron
My original question is why did I have to change the case statement from:
To The last CASE statement is the only way it works if a=97 and 97=a why wont it work either way?
Thanks and sorry being so confusing.
Still doesn't explain the post above.
Ron
I just looked at pst. Use pst.char(char). Char in PST is th same as tx in FullDuplexSerial.
I'm typing on a netbook in bed and keep elbowing my wife as I try to type. I'll answer any other questions tomorrow. When you use str method, your string needs to end with a zero.
Duane
Also the debugging doesn't sound right, and if you can't debug it makes other things more difficult. Any of the serial drivers in the obex ought to work. This morning, for a brief moment to check my sanity on some code, I rewrote a baud driver from 115200 baud down to 300 baud and ran Hyperterminal. Sometimes the slower baud rates fix things.
Can you run the proptool?
Addit: I see Duane is using pst.char(char) - that ought to fix things. Maybe the "A" vs 65 is ok after all?
Well its working for me now I revisited the original way "A","a" : pntr := 1 and presto. Don't know why it didn't work the first time but one thing I am sure of. It was my fault. One problem I have four letters ("EEee") in the @Message my light should blink 4 times but its only blinking 3? Just now changed to 5 e's and got 4 blinks. I am going to revisit the original code and see if I missed something.
@Dr_Acula A vs 65 checks out fine Thanks
Ron
I see another problem. You use letter array before you fill the array. Move where you fill the array to the beginning of Main.
You could also move the array to the DAT section. You'd need to use the @@ sybol.
I think that would work. It would also make it easier to add letters in the future.
When you use PST use char method to dispay one character and str to display zero terminating strings.
Duane
That did it moved the letter array up to the main method perfect. Now I need to walk through it so I can better understand it. I am going to play with the DAT section idea to see how much more trouble I can get into.
Learning a lot here tonight.
Don't get in trouble. Thanks
Ron
Yes, What you wrote is correct.
One clarification "so it went of into space" is really "so it was equal to zero." Global variables are initialized to zero. Only result is initialized to zero with local variables (the others could be anything).
Your right about the DAT section being written to memory at compile time. I'm not sure if I gave you correct information about using he @@ (Address Plus Symbol page 173 of manual v1.1). I'd suggest keeping your array initialization where it is (now). The address plus symbol can only be used in certain ways, I'm not sure if the way I used above would work (I don't think it would). There are ways of having your array of pointers in the DAT section but I'm not sure if it is worth the trouble in this case.
Duane
Your right about the @@ in the DAT section. Everything works fine now so I'll move on to the next thing maybe come back and revisit the DAT thing later.
Thanks Again
Ron