anyone can tell me how to make a automatic newline on the 16*2LCD display ?
daniel ding
Posts: 52
Hi everyone, I am going to use a ps2 keybard to input words or characters to the 16*2LCD.
But I don't know how to make a automatic newline.
who can give me some adivices or help, thanks!
But I don't know how to make a automatic newline.
who can give me some adivices or help, thanks!
Comments
I know it, but how to track the cursor. You know I should read the value of the AC, but how to do it?
en----, could you give me a example~thanks a lot!
http://obex.parallax.com/objects/474/
...you'll see that the waitbusy method returns the current cursor position.
con
_clkmode=xtal1+pll8x
_xinfreq=5_000_000
obj
key:"keyboard"
lcd:"lcdroutines4"
pub main |temp,counter,index ,x
lcd.initialize_lcd
key.start(16,17)
repeat
case key.getkey
13:lcd. position(2,1)
42:lcd.print(string("*"))
43:lcd.print(string("+"))
45:lcd.print(string("-"))
46:lcd.print(string("."))
47:lcd.print(string("/"))
48:lcd.print_dec(0)
49:lcd.print_dec(1)
50:lcd.print_dec(2)
51:lcd.print_dec(3)
52:lcd.print_dec(4)
53:lcd.print_dec(5)
54:lcd.print_dec(6)
55:lcd.print_dec(7)
56:lcd.print_dec(8)
57:lcd.print_dec(9)
200:lcd.shiftleft
lcd.space(1)
lcd.shiftleft
192:lcd.shiftleft
193:lcd.shiftright
194:lcd.home
waitcnt(clkfreq/100+cnt)
It is my program, I use a keyboard to input numbers and characters, can you tell me how and where add a parameter for a cursor add?
Thanks!
Knowing where the cursor should be after each expression you can add, subtract or pre define a value.
Jeff T.
Thanks for your reply. But do you mean that I should add a "counter++" every "lcd.print(......)".
just like
42:lcd.print(string("*"))
count++
43:lcd.print(string("+"))
count++
45:lcd.print(string("-"))
count++
46:lcd.print(string("."))
count++
47:lcd.print(string("/"))
count++
additions can you tell me how to make a code display just like yours reply.
I am really a new guy to this forum, if you can tell me how to make a photo for me just like your guitar I will appreciate it very much.
Thanks;
Yes, I'm sure there is a more elegant method but that's the idea. The count provides line and position with simple math. (count // 16) // 2 = line 0 or 1; (count // 16) = character position in a line. I believe that's right.
lcd.print(string("*+-./"))
Then you would have print also increment the count although it is better to have a count for the X or character position and another for the Y or line position. For every printing character you would increment the X count and compare it with the maximum length of the display. If it reaches the end of the line you would implement the equivalent of a CR LF sequence and depending upon you LCD it may need to have the internal cursor position translated from you X and Y.
I have just written a full blown 20x4 LCD driver complete with big digits and emulation for a popular serial display as well so I could give you lot's of tips but perhaps you should think more about the task before asking questions as you will learn a lot more.
If you need more help then it's fairly customary (and necessary) for you to post your code plus some overview of what you are trying to achieve by this exercise.
Your advice of using "lcd.print(string("_,+,*,."))" is good, but how to distinguish the dec-number. Can you give me some help.
Thanks very very very much.
Though your method is not elegant enough, but it is very effective. I am very glad to it.
As a Chinese student, it is really a hard work to read these English words. But I am adapting myself to it. Thanks again.
additions, I got another problem here http://forums.parallax.com/showthread.php?134888-anyone-who-can-tell-me-how-to-achieve-this-function-using-a-16*2lcd-and-a-keyboard%26%2365311%3B&p=1040539#post1040539.
Jon's object includes an "out" method.
If you're only displaying one character you can use "lcd.out("+")" (or "lcd.out(43)") instead of using "lcd.print(string("+"))". Your Propeller will thank you (or at least run faster).
An even better idea is to use "lcd.out(key.newkey)".
Duane
Sorry, now that I see your complete code I see what you are trying to do with lcd.string("*)) etc is normally done just as a single character using the equivalent of lcd.out("*"). Strings can be used for single characters but it's very inefficient and a round-about way of doing things.
The code looks a bit puzzling as to why you are interpreting keyboard codes this way. If the keyboard codes are printable ASCII then you can just echo them to the LCD and handle the control codes separately. For instance 48 through to 57 are just plain ASCII for 0 to 9. The value of 200 looks like it should just be a standard backspace ($08) character. If the keyboard is spitting out standard and non-standard codes you could employ a lookup table to translate these to standard ASCII and then process them.
Any standard ASCII code below $20 is a control character and you can have a CASE statement to handle these otherwise handle all the rest as standard printable characters that you send straight to the display. Every character causes the X count to be advanced and a check is done to see if X has advanced past the end of line in which case you perform your defined functions for CR and LF. The CR function should only reset the X count and update the LCD cursor according to X and Y so that the cursor (visible or not) returns to the left side. The LF function increments the Y count and checks for wrap-around after which it updates the cursor according to X and Y count. HOME will reset X and Y count and update the LCD cursor.
Here's a small snapshot of my character processing statement and what the CR and LF functions look like. Just use these as a guide as they are specific to my implementation.
but I use a "case--other" method, why when I input the first time "other" number, the lcd display nothing and the second time when I press the key it display the number?
I am going to study the object's out mehod now!
Thanks,
You gave me a big help, I got it now. Thank you very much !
I'm not trying to teach you how to program in Spin, that's for you to learn. Your question was very specific about how to make an automatic newline and my snippet of code is just to show you how I handle part of it. Would you like me to write all the code for you? I hope you don't because you will miss out on the joy and benefits of learning. There are plenty of examples in the OBEX and throughout the forum so what have you found?
What I have difficulty with is understanding your objective and without that it is a cumbersome piecemeal process of providing help. Perhaps you could provide an overview of why you are going through this exercise and what you hope to achieve.
Are u here? Do u remember u tell me that use a lcd.out(key.newkey) to display the keyboard? I got it , but now I want to let the propeller distinguish what the lcd is displaying.
For one, if I press the "g" key on keyboard and lcd display a "g" charactor, and the chip know taht I input a "g" charactor ,and if I press enter key next the chip will light a led.
thanks
daniel