Problem with GOSUB/GOTO and Newhaven OLED question


Closed Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    Oct 2005
    Location
    New Jersey
    Posts
    425

    Default Problem with GOSUB/GOTO and Newhaven OLED question

    My first issue is related to the program, which I think is due to a GOSUB where a GOTO should have been placed:
    Code:
    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?Name:  Newhaven OLED.JPG
Views: 560
Size:  147.2 KB

  2. #2
    Join Date
    Jan 2009
    Location
    Alabama,USA
    Posts
    219


    Did you find this post helpful? Yes | No

    Default Re: Problem with GOSUB/GOTO and Newhaven OLED question

    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

  3. #3
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,655


    Did you find this post helpful? Yes | No

    Default Re: Problem with GOSUB/GOTO and Newhaven OLED question

    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

  4. #4
    Join Date
    Oct 2005
    Location
    New Jersey
    Posts
    425


    Did you find this post helpful? Yes | No

    Default Re: Problem with GOSUB/GOTO and Newhaven OLED question

    Quote Originally Posted by MOUNTAIN747 View Post
    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.

  5. #5
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,615


    Did you find this post helpful? Yes | No

    Default Re: Problem with GOSUB/GOTO and Newhaven OLED question

    And do not forget the OLEDS are far slower than LCD's ...

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

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

Similar Threads

  1. Programming style - GOTO or GOSUB ?
    By AndrewC in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 8th December 2010, 18:08
  2. timeout of Hserin, goto, gosub or both?
    By flipper_md in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 28th October 2009, 18:43
  3. GOTO main or RETURN - Question
    By studysession in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 31st January 2009, 16:13
  4. If ... Then Gosub <> If ... Then Goto?
    By oldtoddler in forum General
    Replies: 6
    Last Post: - 27th February 2006, 11:52
  5. Goto inside a gosub??? Problems...
    By leonel in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 13th October 2005, 12:17

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts