Announcement

Collapse
No announcement yet.

Problem after 8 button presses

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem after 8 button presses

    I'm working on a sort of "video jukebox" using the uLCD-144G2, and I'm having a really odd problem with the IO pins as inputs. I've tried using both IO1 and IO2 for a button input (changing the video number when the button is pressed). I've tried both configured as pull-ups and as pull-downs and the problem is still the same.

    Here's what happens: basically the button works as it is supposed to work for the first seven presses: pressing once advances to the next video. But when you get to that 8th press, the screen either freezes, reboots, or the hardware seems to fail because the LCD backlight turns off (the display needs to be hard power-cycled when this happens). I'm not doing anything odd in the code, and I've never seen behavior like this with IO inputs before. And why would it happen only after 8 presses?

    Here's the relevant code (the checkPin() function is called repeatedly from within main() to check for button presses):

    Code:
    pin_Set(INPUT, IO2);
    Code:
      
    func checkPin()
              if(pin_Read(IO2)==0)
                    vidNum := vidNum + 1;
                    showTitle();  // Show the title screen for the next video
                    pause(2000);
    
                    // Write the new video value to the SD Card
                    media_SetSector(0,MDA);
                    media_WriteByte(vidNum);
                    media_Flush();
                    // Play the intro footage for the selected video
                    frame := 0;
                    playIntro();
    
                    // Set up the next video
                    frame := 0;
                    setupVideo();
                endif
    
    endfunc
    Nothing fancy. Nothing I can see that should be making the display freeze/reboot/hang after a specific number of presses (it is always 8).

    Any idea what could be happening here?

  • #2
    OK, I think I figured this one out. After staring at code for a very long time, I realized that checkPin() was being called recursively-- I had accidentally set up a function call back to the calling function that executed from within a sub-function call. If that makes any sense. I cleaned it up and removed the recursion, and now the display doesn't freeze/crash/reboot.

    Comment

    Working...
    X