PIC 18F2525
I have my first interrupt and timer routine working as part of a menu system, and it feels over my head.. The system loop has several subroutines, and it chooses which to do based on some flags set in the menu interrupt.
The problem is two fold:
1. When I hit the button (b0) to interrupt to my menu handler, it jumps to the menu handler fine. However, when selecting a new menu, the code returns back whatever routine it WAS just in to finish that BEFORE it will jump to the next one. I need it to really INTERRUPT -- ie if I start a download routine, and then click the button to choose a different menu, I want it NOT to then download, but to just skip to the next routine. (Below)
2. Timeout - if I click a menu select button (bo), then never click the menu submit button (b1), I want it to 'time out' and keep doing what it was doing before. I have a timout routine I got from this forum, but I don't think it is working right as it never does this. (Below)
3. Crashing - this code watches a modem line for activity, and if it sees it, it starts reading. If it does NOT see it, it just loops thorugh a routine that says 'No data'.. and then returns to the top of the code.
basically :
getdata:
Serin2 Cpinin,84,1000,nodata,[wait($02,$47), STR SSMAX\34]
return
'*******[No Data from modem] ***********
nodata:
Pause 30
LCDout $fe, L2, " Searching"
LCDout $fe, L3, " No TracIDs Found"
LCDout $fe, L4, " Check Tranmsitters"
pause 50
goto main
Then main ends up calling 'get data' again. This is supposed to loop, but eventually, the code hangs and has to be power cycled to come back to life..
I am thinking this might have something to do with my timer..
TG
-- some of the code follows ----
ADCON0 = %00110000 ' turn off - select port AN12 (nothing)
ADCON1 = %00001111 ' turn portA to digital I/O (same as dec 15)
CMCON = $07 ' turn off
HLVDCON = %00000000 ' turn off
CVRCON = $00000000 ' turn off
SSPCON1 = %11011100 ' supposed to be turning on I2C
SSPCON2 = %01111000 ' supposed to be turning on I2C
INTCON = %11110000 ' TG guess at 2525 interrups for all INT pins
INTCON2= %01110100 ' rising edge of INT0,1,2 RB0,1,2
RCON = %10000000 ' no priority interrups
T1CON = %11000000 'Timer1 1:1 prescale.
T0CON = 1
----------------------------------------------------
On Interrupt Goto INT_handle
Smenu = 0
ReStart:
TMR1H = 0 ' Clear time counts before Timer1 re-start
TMR1L = 0 ' Clear time counts before Timer1 re-start
PIR1.0 = 0 ' CLear over-flow flag before enable
T1CON.0 = 1 ' Turn Timer1 back on before entry into MainProcedure
Main:
Main program stuff happens here
' --------- Interrupt Handler in main loop---------------
IF PIR1.0 THEN ' IF Timer1 has over-flowed then
Timer = Timer + 1 ' Increment Timer variable
PIR1.0 = 0 ' Clear over-flow/int flag
' @20MHz 200nS * 65,536 * 8 = 0.1048576 seconds per over-flow
' 0.1048576 * 48 = ~5.033 seconds before jump to NextStage
IF Timer >= 20 and Mnu = 1 THEN NextStage
ENDIF
goto Main
-----------------------------------------------------
NextStage: ' timer routine
Mnu = 0
T1CON.0 = 0 ' Turn off Timer1 if you need to here
Timer = 0 ' Clear Timer var on entry here
TMR1H = 0
TMR1L = 0 ' CLear timer count registers as required
LCDout $fe, 1
LCDout $fe, 2
LCDout $fe, L2, "Timer Ran Out"
pause 1000
GOTO ReStart ' When you're ready to start all over
' Interrupt handler stuff here
Disable ' Disable interrupts in handler
INT_handle:
Timer = 0 ' Clear Timer var on entry here
TMR1H = 0
TMR1L = 0 ' CLear timer count registers as required
Selectit=0
While selectit = 0
Mnu=1 ' we are in the menu system
If Mmenu = 0 then
While Mmenu = 0 ' waiting until
wend ' push-button is release
pause 100 ' debounce time
Bmenu=Bmenu+1
endif ' bo pressed – go to next menu
Select Case Bmenu
Case 0
LCDout $fe, 1
LCDout $fe, 2
LCDout $fe, L2, " Menu 0: Cycle Menu"
pause 10
Case 1
LCDout $fe, 1
LCDout $fe, 2
LCDout $fe, L2, " Menu 1: Sensors"
pause 10
... etc ...
If Smenu = 0 then ' select button is pressed
While MMenu = 0 ' waiting until
wend ' push-button is release
pause 100 ' debounce time
selectit = 1 ' b1 pressed get out of the loop!
endif
Wend
Mnu=0 ' turn off menu flag
Here:
While MMenu = 0 ' waiting until
wend ' push-button is release
pause 100 ' debounce time
If MMenu = 0 then here
PIR1.0 = 0 ' Clear Timer1 over-flow flag
Timer = 0 ' Clear Timer counts before return
INTCON.1=0 ' reset RB0 interrupt flag
Resume ' Return to main program
Enable ' Enable interrupts after
' handler
end
----------------------------------------------------------------------
Bookmarks