Interrupt Problem

pilko

Senior Member
Hi folks,
I am reading 3 temperatures, one differential temperature and an analog signal, using subs bb, cc, dd, ee and ff. Temps. The 5 readings are displayed in sequence on a single 7 seg display. This part of the system works fine although the code is not very elegant.
I then added an interrupt so that by pressing a switch at input 1 from one to five times I could hold the display at bb or cc or dd etc. This is done by counting b8.
The interrupt addition works fine on the simulator but I cannot get past b8 = 1 with the actual device. Any help would be appreciated.

Thanks

pilko

Code:
temp28X:

setint %00000010,%00000010

'Differential Temperature = Feed Temperature minus Return Temperature 
bb:
setint %00000010,%00000010                     'Feed Temperature
readtemp 4,b0                                  'Return Temperature 
readtemp 5,b4                                  
pins=%10111100:pause 200:pins=%00000000:pause 200 ' flash a "d" 
if b0>=b4 then let b5=b0-b4 endif
if b0>128 then aa                              'Sub zero temps value correction
if b0>128 then let b5=b0-127+b4 endif
if b4>b0  then aa 
if b4>b0  then let b6=b0-b4  let b5=256-b6 endif
b1= b5/10		                       'divide orig temp to get tens value
b2= b5//10                                     'divide orig temp so remainder yields units value
pause 200

on b1 gosub zero,one,two,three,four,five,six,seven,eight,nine  'tens 
pause 300:pins=%00000000                       'blanks all 7 segs  
pause 300                

on b2 gosub zero,one,two,three,four,five,six,seven,eight,nine   'units
pause 300:pins=%00000000                       'blanks all 7 segs

if b8=1 then bb
if b8=2 then cc

 
'Temperature 1
cc:
setint %00000010,%00000010
readtemp 4,b0                                  'Feed Temperature
pins=%11100010:pause 200:pins=%00000000:pause 200 ' flash a "F" 
if b0>128 then negtemps                        'Sub zero temps value correction
b1= b0/10		                       'divide orig temp to get tens value
b2= b0//10                                     'divide orig temp so remainder yields units value
pause 200

on b1 gosub zero,one,two,three,four,five,six,seven,eight,nine  'tens 
pause 300:pins=%00000000                       'blanks all 7 segs  
pause 300                

on b2 gosub zero,one,two,three,four,five,six,seven,eight,nine   'units
pause 300:pins=%00000000                       'blanks all 7 segs

if b8=2 then cc
if b8=3 then dd
         
                 
'Temperature 2
dd:
setint %00000010,%00000010
readtemp 5,b0                                  'Return Temperature
pins=%01100110:pause 200:pins=%00000000:pause 200 'flash a "r" 
if b0>128 then negtemps                        'Sub zero temps value correction
b1= b0/10		                       'divide orig temp to get tens value
b2= b0//10		                       'divide orig temp so remainder yields units value
pause 200

on b1 gosub zero,one,two,three,four,five,six,seven,eight,nine  'tens
pause 300:pins=%00000000 	           'blanks all 7 segs  
pause 300                

on b2 gosub zero,one,two,three,four,five,six,seven,eight,nine  'units
pause 300:pins=%00000000

if b8=3 then dd
if b8=4 then ee
                  
     
'Temperature 3
ee:
setint %00000010,%00000010
readtemp 6,b0                                   'Outdoor Temperature
pins=%10111000:pause 200:pins=%00000000:pause 200 'flash a "o" 
if b0>128 then negtemps                         'Sub zero temps value correction
b1= b0/10		                        'divide orig temp to get tens value
b2= b0//10		                        'divide orig temp so remainder yields units value
pause 200

on b1 gosub zero,one,two,three,four,five,six,seven,eight,nine  'tens
pause 300:pins=%00000000 	           'blanks all 7 segs  
pause 300                

on b2 gosub zero,one,two,three,four,five,six,seven,eight,nine  'units
pause 300:pins=%00000000

if b8=4 then ee
if b8=5 then ff

'Frost level
ff:
setint %00000010,%00000010
pause 500
readadc 1,b0                                   'Voltage representing Frost Level
pins=%01110000:pause 200:pins=%00000000:pause 200 'flash a "L" 

b1= b0/10		                        'divide orig reading to get tens value
b2= b0//10		                        'divide orig reading so remainder yields units value
pause 200

on b1 gosub zero,one,two,three,four,five,six,seven,eight,nine  'tens
pause 300:pins=%00000000 	           'blanks all 7 segs  
pause 300                

on b2 gosub zero,one,two,three,four,five,six,seven,eight,nine  'units
pause 300:pins=%00000000

if b8=5 then ff
if b8>5 then let b8=0 endif
                   
goto temp28X

 zero: pins=%01111110:return '0 shows
 one:  pins=%01100000:return '1 shows
 two:  pins=%10110110:return '2 shows
 three:pins=%10011110:return '3 shows
 four: pins=%11001100:return '4 shows
 five: pins=%11011010:return '5 shows
 six:  pins=%11111010:return '6 shows
 seven:pins=%00001110:return '7 shows
 eight:pins=%11111110:return '8 shows
 nine: pins=%11001110:return '9 shows

negtemps:'DS18B20 subzero negative temps routine + flashing -ve alert
for b3 = 1 to 2:pins=%10000000:pause 200:pins=%00000000:pause 200:next b3
b0 = b0 - 127:return 'b0 now correctly able to show subzero temps

aa:for b3 = 1 to 2:pins=%10000000:pause 200:pins=%00000000:pause 200:next b3 return

interrupt:
gg:    if pin1 = 1 then hh	'Decision command       
       goto gg
       
hh:    if pin1 = 0 then ii	'Decision command     
       goto hh
       
ii:    let b8 = b8 + 1	'Inc command
       if b8=1 then bb                   
       if b8=2 then cc
       if b8=3 then dd
       if b8=4 then ee
       if b8=5 then ff
       if b8>5 then temp28X 
       
setint %00000010,%00000010

return
 

MartinM57

Moderator
I see problems with jumping out of the interrupt routine without doing the setint/return statements - this will confuse
a) you, when trying to trace what's going on
b) the chip, since it will not respond to another interrupt, so you will (seem to) get stuck at b8=1

You need to increment b8 in the interrupt but make the decision on what to do with its value in the main code loop.

I can't understand how it will work after 5 button presses - b8 just keeps increasing....
 

pilko

Senior Member
I have a setint and a return in the interrupt sub. I also have a setint in each of the other subs.
I am doing something with b8 in the main code
 
Last edited:

MartinM57

Moderator
Manual 2 Page 181

When the interrupt occurs, the interrupt is permanently disabled. Therefore to
re-enable the interrupt (if desired) a SETINT command must be used within
the interrupt: sub-procedure itself. The interrupt will not be enabled until the
‘return’ command is executed.
Your interrupt code never does the 'return' - it jumps away before getting there
 

MartinM57

Moderator
OK - I see how you are handling b8 in the main loop.

Maybe just take the if..then's out of the interrupt routine?
 

pilko

Senior Member
Added returns in sub ii.--- still cannot get past sub bb. I don't understand how I can remove the if thens from interrupt sub.
 

MartinM57

Moderator
Can't see why this won't work...but untested

Code:
interrupt:
gg:   if pin1 = 1 then hh	'Decision command       
       goto gg
       
hh:   if pin1 = 0 then ii	        'Decision command     
       goto hh
       
ii:    let b8 = b8 + 1	        'Inc command
       
setint %00000010,%00000010
return
The interrupt routine is just changing b8, the main code is routing between the values to display based on b8

However you probably want to explicitly code the main loop to explicitly handle b8 = 0...sorry I don't have the time to look at this in detail

I might even do the following to keep the handling of b8 all in the same place
Code:
interrupt:
gg:   if pin1 = 1 then hh	'Decision command       
       goto gg
       
hh:   if pin1 = 0 then ii	        'Decision command     
       goto hh
       
ii:    let b8 = b8 + 1	        'Inc command
      if b8 = 6 then b8 = 0  

setint %00000010,%00000010
return
 
Top