PDA

View Full Version : Problem with GOSUB/GOTO and Newhaven OLED question



Christopher4187
- 11th April 2013, 17:00
My first issue is related to the program, which I think is due to a GOSUB where a GOTO should have been placed:

Q3:
GOSUB ALL_LEDS_OFF
LCDOUT $FE,128,"WHAT COLOR IS GOLD?"
LCDOUT $FE,192,"A: BLACK"
LCDOUT $FE,148,"B: SILVER"
LCDOUT $FE,212,"C: AMBER"
FOR X=1 TO 160
PAUSE 125
IF A=0 OR B=0 OR C=0 THEN
GOSUB CLEAR_SCREEN
IF C=0 THEN
GOSUB CORRECT_ANSWER
GOTO DONE_Q3
ELSE
GOSUB INCORRECT_ANSWER
GOSUB Q3 <------ Will this cause problems with the code?
ENDIF
ENDIF
NEXT X
DONE_Q3:
WRITE 16, 4
RETURN
Before the code arrived at Q3, it came from a GOSUB and that's covered with a RETURN at the end. When checking what button "C" is, if the answer is incorrect I had a GOSUB but no RETURN for that GOSUB (the one with the arrow pointing to it). I believe it should be the same as the correct answer. I can't try this fix until tonight but can someone tell me if that GOSUB will cause my code to do strange things?

My other question is about how to shut off the OLED screen. According to the datasheet, I need to zero everything out and then pull DB7 high. At least that's that way I think it should be done but it's not working. I'd like to shut off the LCD screen and clear it using the table shown below. Is there anything I'm missing?6961

MOUNTAIN747
- 11th April 2013, 22:19
Christopher, On the Newhaven OLED you can use LCDOUT $fe,$08 to turn the OLED off and LCDOUT $fe, $0C to turn it back on, but this will not clear DDRAM. Once turned on again you will still have the same thing on your screen. There may be a better way but in some cases cycling power is the only way I have found to truly clear the screen. A poor, but sometime useful, fix for this problem in some cases is to write blanks to all locations as LCDOUT $fe, 1 doesn’t always work. I have also found that if there is a glitch during a command to the OLED the address gets scrambled and the OLED screen reads gibberish and can only be cleared by cycling power. Some of these problems are discussed on the Newhaven OLED forum. Your table below looks like the initialization routine which PBP is taking care of. I haven’t tried to write my own re-initialization routine for this OLED but I would be surprised if DDRAM would be cleared to give you a blank screen. I hope this is of some help.
Wayne

Demon
- 12th April 2013, 00:05
GOSUB from within the subroutine is bad for several reasons.

The most important; you can nest a limitted number of levels. Go beyond that number and the program gets lost.

Robert

Christopher4187
- 12th April 2013, 01:20
I have also found that if there is a glitch during a command to the OLED the address gets scrambled and the OLED screen reads gibberish and can only be cleared by cycling power. Some of these problems are discussed on the Newhaven OLED forum. Glad I'm not the only one. I was pulling my hair out trying to figure out what I was doing wrong. I notice this problem mostly when the screen is idle (characters sitting on the screen and haven't changed for a while). Is that what you see?

If there isn't a software fix for it, I guess I'll have to use an output from my ULN2003A to take care of the power cycle.

Acetronics2
- 12th April 2013, 10:24
And do not forget the OLEDS are far slower than LCD's ...

so, do place some DEFINES to pace somewhat PBP commands ...

Alain