PDA

View Full Version : Help with LCD commands with button I/P



g7jiq
- 6th January 2008, 01:20
Hi all,

I am a newbie and I am looking for any pointers on a little problem i have.

I am trying to get a 2 line LCD display to change its display when it recieves a logic input.
(I am using a 2 line display and a 16F627)
I can get it to display anything I want with the LCDOUT command,
My problem starts when I try to change the displayed words when I recieve an input,

For test purposes I attached a button to the input,
The best I could get was the display to flash both commands when the button was pressed.

Any ideas ?

Cheers
Dave...

CocaColaKid
- 6th January 2008, 03:14
Why not just use and if...then statement and use the button to input to toggle between the two display outputs.

g7jiq
- 6th January 2008, 22:34
Hi,

Thanks for your reply,

The program I am trying to get going is to get an lcd display to display the status of a low power ham radio repeater,
The pic's i/p lines will be connected to the control lines of the radio control circuit.

I have re-writen the program using the IF, THEN commands and all I get is the setup message and lcd back light,
The display remains blank no matter what the i/p lines are doing.
(I/P pins are 10k to Gnd.)

The program I am trying to get working follows:-
(please feel free to rip it apart and advise me where I am going wrong)

Cheers
Dave...


TRISA=%00000000 'Set port A as output
TRISB=%01110111 'Set port B as input except B7 for backlight and B3 for lcd

Backlight VAR PortB.7 'Set var as port B7

SW1 VAR PORTB.0
SW2 VAR PORTB.1
SW3 VAR PORTB.2
SW4 VAR PORTB.4
SW5 VAR PORTB.5
SW6 VAR PORTB.6

Pause 500 'stand by for lcd

lcd_light: 'light up lcd backlight
low Backlight

gosub setup
goto loop

setup:

LCDOUT $FE,1 'clear lcd
lcdout " G7JIQ Micro" 'Display on line 1
lcdout $FE, $C0 'Display on line 2
Lcdout " Link Repeater"
pause 2000
LCDOUT $FE, $0C 'turn off cursor
lcdout $FE,1 'clear display
lcdout $FE,2
return

loop:

if SW1 = 0 then Disp1
if SW1 = 1 then Disp2
IF SW4 = 0 THEN Disp3
if SW4 = 1 THEN Disp4

goto loop


Disp1
lcdout "Standby"
Disp2
lcdout "Main"
Disp3
lcdout $FE,$C0,"Local off " 'display on line 2
lcdout $FE,1
Disp4
LCDOUT $FE,$C0,"local on"
lcdout $FE,1


end

Archangel
- 6th January 2008, 23:04
Hi g7jiq,
looks simple enough, without my trying your code. You want Disp1, disp2, to run only when sent there,
your code

Disp1
lcdout "Standby"
Disp2
lcdout "Main"
Disp3
lcdout $FE,$C0,"Local off " 'display on line 2
lcdout $FE,1
Disp4
LCDOUT $FE,$C0,"local on"
lcdout $FE,1

try:


Disp1:
lcdout "Standby"
return

Disp2:
lcdout "Main"
return

Disp3:
lcdout $FE,$C0,"Local off " 'display on line 2
lcdout $FE,1
return

Disp4:
LCDOUT $FE,$C0,"local on"
lcdout $FE,1
return

end


without the colons the program sees your subdirectories as just the next line of code, the returns send it back to the line after the one which calls it.
JS

CocaColaKid
- 7th January 2008, 12:34
I may be wrong but would you not require a gosub in order to use a return? I believe a simple goto would me more appropriate in this case.

mister_e
- 7th January 2008, 13:53
and there's another danger... DISP3, DISP4,, the second LCD will clear the whole LCd display. :(

CocaColaKid
- 7th January 2008, 14:31
Oops, your right Steve, I never even noticed that, lol.

Archangel
- 7th January 2008, 21:54
I may be wrong but would you not require a gosub in order to use a return? I believe a simple goto would me more appropriate in this case.
YEP!
Shows how close I looked at the code after seeing what I did see! Must have gotten excited.

g7jiq
- 7th January 2008, 22:26
Hi again

I have had a play with the code, and have placed the colons in as stated,
I still get no display,

One thing I did find is if I place the Disp1: to Disp4: section into the main loop I get a very
fast flashing faint display,
It does change tho when the i/p pin is toggled.

So I may be getting a little closer.

Any ideas.....?

mister_e
- 7th January 2008, 22:31
add a PAUSE 100-250 before you Goto Loop

Archangel
- 8th January 2008, 06:47
Hi again

I have had a play with the code, and have placed the colons in as stated,
I still get no display,

One thing I did find is if I place the Disp1: to Disp4: section into the main loop I get a very
fast flashing faint display,
It does change tho when the i/p pin is toggled.

So I may be getting a little closer.

Any ideas.....?
I will attempt to redeem myself, again without actually wiring up a pic to default LCD settings,


TRISA=%00000000 'Set port A as output
TRISB=%01110111 'Set port B as input except B7 for backlight and B3 for lcd



SW1 VAR PORTB.0
SW2 VAR PORTB.1
SW3 VAR PORTB.2

SW4 VAR PORTB.4
SW5 VAR PORTB.5
SW6 VAR PORTB.6
Backlight VAR PortB.7 'Set var as port B7



low Backlight 'light up lcd backlight

Pause 1000 'stand by for lcd



setup:

LCDOUT $FE,1, " G7JIQ Micro" 'clear lcd & Display on line 1
lcdout $FE, $C0," Link Repeater" 'Display on line 2
pause 2000
LCDOUT $FE, $0C 'turn off cursor
lcdout $FE,1 'clear display
lcdout $FE,2 'Return Home


loop:

if SW1 = 0 then Disp1 ' if true, disp1
if SW1 = 1 then Disp2 ' if true, disp2
IF SW4 = 0 THEN Disp3 ' if true, disp3
if SW4 = 1 THEN Disp4 ' if true, disp4

goto loop


Disp1:
lcdout "Standby"
pause 1000 ' gives time to see display

goto loop ' prevents you from having to use gosubs in the loop
' however it returns to the beginning of the loop
' whereas a gosub would go to the next line in the loop

Disp2:
lcdout "Main"
pause 1000 ' gives time to see display

goto loop ' prevents you from having to use gosubs in the loop
' however it returns to the beginning of the loop
' whereas a gosub would go to the next line in the loop

Disp3:
lcdout $FE,$C0,"Local off " 'display on line 2
pause 1000 ' gives time to see display
lcdout $FE,1 ' Erases display

goto loop ' prevents you from having to use gosubs in the loop
' however it returns to the beginning of the loop
' whereas a gosub would go to the next line in the loop
Disp4:
LCDOUT $FE,$C0,"local on"
pause 1000 ' gives time to see display
lcdout $FE,1 ' clears display

goto loop ' prevents you from having to use gosubs in the loop
' however it returns to the beginning of the loop
' whereas a gosub would go to the next line in the loop


end

There are no config fuses set here as I do not know which compiler you are using of which PIC, so you must add them or manually set the config fuses in your programmer. If you supply the information and also the Oscillator speed and if you are using xtal, resonator or internal oscillator, everyone is sure to help.

g7jiq
- 8th January 2008, 21:10
Hi,

Sorry should have given the hardware spec first,
The pic is a 16F627, the clock crystal is 4mhz and I am using Microcode picbasic pro built in compiler.

I have tried your updated code (many thanks) and at last I get somthing on the display,
But its displays "Standby"Standby"Standby"Standby" etc.. across the display incrementing each word once a second, across the topline and then the bottom line intil its full.

If I toggle the sw1 i/p It changes to "Main"Main"Main" etc.. across both lines of the display until full.

SW4 does nothing .

Whats going wrong....

I didn't think it would be so hard to do, I can do it with LED's but an LCD has me beat.
(but i am one not to be beaten)

Any suggestions......

mister_e
- 8th January 2008, 21:13
yes.. read the comment right to LCDOUT $FE,1

everytime you do a LCDOUT, it will write to the current cursor position.. unless you specify it. So what the following will do?



LCDOUT $FE,1,"Hello "
LCDOUT "world!"

g7jiq
- 8th January 2008, 21:53
Thanks Steve,


I now have one line with one word, which changes when I toggle the i/p. (great just the job)
Do you know why I get no change when i toggle the other i/p.
Line 2 stays blank.

mister_e
- 8th January 2008, 22:25
Yes i know... look how your program flow...

it goes to Disp1 or Disp2.. then it return to Loop... knowing that SW1 can't something else than 0 or 1.. it will never execute the IF SW4 = lines.

I would suggest to use GOSUB and RETURN for a quick fix.. and be careful with LCDOUT $FE,1 line in DISP3 & DISP4 routines...

Still possible to use another method...

g7jiq
- 8th January 2008, 22:29
Thanks I will give it a try,

mister_e
- 8th January 2008, 22:37
you could still use something like..


Loop:
IF SW0=0 THEN
' Paste your Disp1 stuff here
ELSE
' paste your Disp2 Stuff here
ENDIF

IF SW4 = 0 then
' Pate your DISP3 stuff here
ELSE
' paste your DISP4 stuff here
ENDIF

GOTO Loop

g7jiq
- 8th January 2008, 22:45
Sorted.

I just inserted a cupple of goto's and returns and It works fine on both lines now,

Many thanks for you and all for your help and advice,

Just one last thing, do you know of where I can get a list of lcdout $ commands as I would like to insert extra info togged by unused i/p's


Thanks
Dave...

mackrackit
- 8th January 2008, 23:05
The PBP manual has some. What are you looking for exactly?

g7jiq
- 8th January 2008, 23:45
I am looking for the lcdout commands, so I am able to send text to any position on a two line display,
Say, 1 command at the beginning of line 1 and another at the end of line 1

cheers
Dave..

mackrackit
- 9th January 2008, 00:48
Thats easy. Look in the manual for full explanation.



LCDOUT $FE, 80 ' First position of line one
LCDOUT $FE, 80 + 4 ' Move over 4 places to the right

Same works for the second line where $C0 is the first position.

g7jiq
- 9th January 2008, 07:49
Hi,

Thanks,
Just what I was looking for,
I can't find my manual so it was just as easy to ask.

Cheers
Dave..

mackrackit
- 9th January 2008, 10:57
You can down load or view the manual online. Gotta have it in some form.

http://www.melabs.com/support/index.htm

You might be interested in custom characters too.

http://www.picbasic.co.uk/forum/showthread.php?p=1489