PIR1.0 stays ever 1 ?!
		
		
				
				
		
			
				
					hello all
i work with a timer1 on a 16f876 at 20 mhz. i used such a snippet some other times succesful. on this other cases i've ever immedeatly start timer1. probaply so i never found this problem...
the problem is that i fall immeadetly to the interupt handler.
i have a longer while-wend in the pre loop to wait for some user inputs. timer1 should not start until end of pre loop.
i've tested also with the ICD, where i saw that PIR1.0 is set to 1 on boot up and also after reset in interrupt handler it goes back very (too) fast. i've also try with PIR1.0 = 0 at the begin of the code. no success
probaply i search on the wrong end, but i think from there is coming up the problem.
thanks for any hint. cheers, mischl
	Code:
	 				... init
'-- PRE LOOP ----------------------------------------------------           
              
              while not ((buto = 3) and (dezi = 1))     
                
                .... stays longer here
                
              wend
                                       
              
              T1CON = %00000000           ' set timer1 prescaler as 1:1. stop timer1 
              PIR1.0 = 0                  ' clear timer1 overflow flag                      
              PIE1 = %00000001            ' enable interrupt on timer1 overflow 
              INTCON.6 = 1                ' enable peripheral (unmasked) interrupts
              INTCON.7 = 1                ' enable global interrupts 
             
              
              gosub SetTimer              ' start timer1
              
              on interrupt goto handler   ' handling interrupt              
'-- MAIN LOOP ---------------------------------------------------
main:         
              ... do something
              GOTO main
               
'-- INTERRUPT SERVICE ROUTINE ----------------------------------      
              disable interrupt           ' disable interrupts in handler
handler:      
              gosub SetTimer
              
              fram = fram + 1
              if fram > 24 then 
                fram = 0
                seco = seco + 1
                if seco > 59 then 
                  seco = 0
                  minu = minu + 1
                  if minu > 39 then
                    minu = 0
                    seco = 0
                    fram = 0
                  endif  
                endif
              endif  
              fcnt = fcnt + 1             ' inc frame counter 
              frsh = 1                    ' set refresh lcd flag
              
              resume main
              
 
SetTimer:
              T1CON.0 = 0                 ' stop timer1
              TMR1H = $63                 ' load with 25536 = 65536 - 40000
              TMR1L = $c0                 
              
              PIR1.0 = 0                  ' clear timer1 overflow flag 
              T1CON.0 = 1                 ' start timer1
              return
              
                                     
              enable interrupt            ' enable interrupts after handler 
'-- SUB --------------------------------------------------------
 
				
			 
			
		 
			
			
			
				
					Last edited by mischl; - 4th March 2006 at 17:33.
				
				
			
			
			
                        	
		        
			
			i know it's only microcontrolling, but i like it!
			
			
		 
	
Bookmarks