PIR1.0 stays ever 1 ?!


Results 1 to 8 of 8

Threaded View

  1. #1
    Join Date
    Jan 2005
    Posts
    72

    Default 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 16:33.
    i know it's only microcontrolling, but i like it!

Similar Threads

  1. Thermo 7 segments - little problem
    By fratello in forum mel PIC BASIC Pro
    Replies: 49
    Last Post: - 27th July 2013, 07:31
  2. RS485 bus - starting probem
    By wurm in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 27th January 2010, 13:35
  3. 32 bit square root
    By Charles Linquis in forum mel PIC BASIC Pro
    Replies: 20
    Last Post: - 6th May 2009, 03:37
  4. one line led light make image
    By bioul in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 13th February 2008, 12:19
  5. HSERIN doesn´t work
    By wurm in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 29th July 2007, 14:23

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts