PDA

View Full Version : scrolling text input? for pic18f4520 with 2x16 lcd



alamakazam
- 2nd February 2012, 03:32
scrolling text input? for pic18f4520 with 2x16 lcd


I tried googled, but couldn't get what I want, probably got the searching terms wrong

basically I want to input letters like in the below video, scroll from 0 to Z

http://www.youtube.com/watch?v=dLLdE5QImYo&feature=youtu.be

could anyone tell me what is this method call? I do need sample codes, to work with too

thanks alot for reading

spcw1234
- 2nd February 2012, 12:13
There is no scrolling text in that video. That is just the cursor showing which digit is to be changed, and a set of buttons to toggle the value of that digit. Is this what you are trying to do? Do you have an LCD setup with the ability to display characters onto it already?

alamakazam
- 2nd February 2012, 12:21
There is no scrolling text in that video. That is just the cursor showing which digit is to be changed, and a set of buttons to toggle the value of that digit. Is this what you are trying to do? Do you have an LCD setup with the ability to display characters onto it already?

oh yes, I have the buttons and lcd integrated, and is displaying "hello world"

spcw1234
- 2nd February 2012, 12:35
You need to create a variable to display that the button will toggle.

Do you have some code started that you can post up?

Art
- 3rd February 2012, 00:34
Something like:




value var word
incvalue var word
cursorposition var byte


**LCD setup code here **

LCDOUT $FE, $0F 'turn blinking cursor on
cursorposition = 0 'reset cursor position


dostuff:

LCDOUT #value DIG 3
LCDOUT #value DIG 2
LCDOUT #value DIG 1
LCDOUT #value DIG 0

IF upbutton = 1 THEN
IF cursorposition = 0 THEN
value = value + 1
ENDIF
IF cursorposition = 1 THEN
value = value + 10
ENDIF
IF cursorposition = 1 THEN
value = value + 100
ENDIF
IF cursorposition = 1 THEN
value = value + 1000
ENDIF

IF downbutton = 1 THEN
IF cursorposition = 0 THEN
value = value - 1
ENDIF
IF cursorposition = 1 THEN
value = value - 10
ENDIF
IF cursorposition = 1 THEN
value = value - 100
ENDIF
IF cursorposition = 1 THEN
value = value - 1000
ENDIF

IF leftbutton = 1 THEN
IF cursorposition > 0 THEN
LCDOUT $FE, $10 'move cursor left
cursorposition = cursorposition - 1
ENDIF
ENDIF

IF rightbutton = 1 THEN
IF cursorposition < 3 THEN
LCDOUT $FE, $14 'move cursor right
cursorposition = cursorposition + 1
ENDIF
ENDIF

IF confirmbutton = 1 THEN
'** go back to, or continue the main program here
ENDIF

goto dostuff

Art
- 3rd February 2012, 02:53
oops, straight after the dostuff: label,



LCDOUT $FE,2 'LCD cursor return home
FOR count = 0 TO cursorposition
LCDOUT $FE, $14 'move cursor right
NEXT count


to set up the display for the next frame.
None of this is tested, but you should get the idea.

Demon
- 3rd February 2012, 17:32
Might want to compare cursor position with 0,1,2 and 3 when checking the buttons instead of only 0 and 1 no?

Can you even use cursor position 0? Or does it start at 1?

I think you have them backwards, the units would be at position 3, tens at position 2 and so on.

But yeah, that's a perfect starting point to start building on.

Robert

Art
- 4th February 2012, 02:45
Might want to compare cursor position with 0,1,2 and 3 when checking the buttons instead of only 0 and 1 no?

Can you even use cursor position 0? Or does it start at 1?

I think you have them backwards, the units would be at position 3, tens at position 2 and so on.

But yeah, that's a perfect starting point to start building on.

Robert

Whoops, ... copy & paste & forgot to adjust :D



IF downbutton = 1 THEN
IF cursorposition = 0 THEN
value = value - 1
ENDIF
IF cursorposition = 1 THEN
value = value - 10
ENDIF
IF cursorposition = 2 THEN
value = value - 100
ENDIF
IF cursorposition = 3 THEN
value = value - 1000
ENDIF
and do the same with te up button.
Also need a pause for button debounce, so



pause 500

straight after each button check
cursorposition = 0 is the thousands position.
The thousands digit is the first to be printed to LCD,
so no movement needs to occur from cursor home command.

Art
- 4th February 2012, 10:01
And the other thing you mentioned...
I need to build a generic test circuit before posting code :rolleyes:

Demon
- 4th February 2012, 21:50
Just to be sure, I wasn't being sarcastic. :)

I wanted to post an attempt, but it's easier for me to pick at others. :D

Robert

alamakazam
- 5th February 2012, 02:28
thanks, I will try out myself this week, get back here with any progress and problem

Art
- 5th February 2012, 07:53
Just to be sure, I wasn't being sarcastic. :)

I wanted to post an attempt, but it's easier for me to pick at others. :D

Robert

Not taken that way at all... good catches ;)

alamakazam
- 1st March 2012, 06:12
guys

I manage to get the lcd working with the cursor responding to the left right navigation button

now , I have a problem with the change of letter

lets say if I want the 1st letter to be from 0,1,2,3,..,9,A,B,C

I am thinking of 012345679ABC as a string, then move from bit to bit

or should I get an array of 13, then point to it

Demon
- 1st March 2012, 07:01
This is totally off the top of my head, no code:

Use an array with 1 element for each character on display.
- if 4 characters, then use 4 elements starting at 0.

Store the position of each character in the array.
- character 1 starts at 0 on startup, so array(0)=1.

Use a lookup table to display each character.

Lcdout (clear screen)
For element = 0 To 3 (if using 4 characters)
Lookup array(element),[0,1,2,3,4,5,6,7,8,9,A,B,C],byteout
Lcdout byteout at next position on display
Next element

-syntax must be corrected.
- never used lookup so not sure if it starts at 0 or 1.
- I remember concatenating characters on the same LCD line, somewhere.

Ok Art, now it's your turn. :D

Robert

Art
- 1st March 2012, 15:24
Well since I was invited it's either what you said, or look up from on-chip eeprom if all lookup tables are going to end up the same.

Much nicer if it was just numeric values, and you could just increment/decrement each byte with the up/down button pushes.

After that first attempt, I'm not going to code it without a test circuit here... ;)

alamakazam
- 1st March 2012, 17:46
cool, I just need some hints on the algorithm , or rather a better way of writing...

shouldn't have any problem writing the code myself

thanks again, lets hope my weekend will be fruitful

Art
- 2nd March 2012, 00:51
Actually if it's just "0,1,2,3,4,5,6,7,8,9,A,B,C"
You should still just increment or decrement the values and use LCDOUT outputting the hex byte values.
That string is still sequential when expressed in hex format. Just a value from 0 to 12.


.

alamakazam
- 2nd March 2012, 00:58
I am going to do this

hexadecimal increment/decrement from 0 to C

position 1 to 4

store the position 1-4 to a temp location

all 4 temp location , combine into a string

eg

going to input A123 memory