I am doing resarch on interrupts, and have seen several postings describing various aspects, but it is not quite clear how I add an interrupt routine to a program I have running. I actaully can't form the PBP code to really start this without some structural help on how interrupts work, and how they can branch to a routine that will allow a person to change settings by using a button to select a view, and then letting the routine time-out (ie button not pushed for 5 secs), to jump back to the main code and continue running, but now with our new settings..

My situation is probably common - I have a program that 'does stuff', in a loop, say reading from a serial port, and writing to an LCD just fine. What I want to do is interrup this with a button, and select some display options using a pushbutton, then have the program jump back and continue running, but now with the different choices I selected in the interrupt routine..

For example - my current main program loops through automatically displaying 3 different views of the data on the LCD. Example:
--------------------------------------------------------------
Loop from 1-3
Select case displayLCD
Case 1
gosub display1
Case 2
gosub display2
Case 3
gosub display3
End Select
--------------------------------------------------------------

This is fine, but I want to control which data set gets displayed by pressing a button.. I want to make the RB4 pin an interrupt so that If button press/interrupt then goto showmenu....

I *think* my program kinda wants to do this:

on interrupt on RB4 showmenu

Main:
gosub collect data
gosub display
goto main

display:
' show whatever view was selected by the button interrupt
gosub display(x) - ' somehow make this display one view as selected by the button/interrupt routine..
return

---

showmenu:
' loop through 3 different views, if user times out (5 secs) on one of them, this is the view we want to show in the main program.

for t= 1 to 3 ' three times you can push the button - then it loops back

serout to LCD "show first data"
set display(x) to "1"
choice=t+1
' if it times out while this is displayed, then this is our choice (how?)

if button pushed again then
serout to LCD "show second data"
set display(x) to "2"
choice=t+1
' if it times out while this is displayed, then this is our choice (how?)
endif

if button pressed again then
serout to LCD "show second data"
set display(x) to "3"
choice=t+1
' if it times out while this is displayed, then this is our choice (how?)

if choice = 3 then choice =1

endif
---------------------------------------------------------------------

Can someone help me visualize this closer to PBB code ??

Tom