Searching \ for '[PIC]:Interrupt Problem in ICD -Newbie' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page:
Search entire site for: 'Interrupt Problem in ICD -Newbie'.

Exact match. Not showing close matches.
PICList Thread
'[PIC]:Interrupt Problem in ICD -Newbie'
2001\04\28@115545 by Wendy Olend

I'm sorry if this is a duplicate post for some of you, but I forgot the ':'
after [PIC] in my initial post, so it got shunted off to "Other"...

A few months ago, I was informed that my project team would be needing me to
write some firmware for the PIC 16f877.  Since I won't be taking my
"Introduction to Microcontrollers" class until this summer, I began to teach
myself about assembler, the chip and MPLAB.  After running around in circles for
quite awhile, I found a copy of Myke's book and finally started making some real
progress. (THANKS MYKE!!!)

Earlier this week, I finally felt comfortable enough to start writing some
code(included at end of post).  My team leader has advised me to become very
familiar with interrupts, so  I decided to design an 8-bit binary counter,
utilizing an interrupt routine.  The algorithm is simple:

    All necessary registers are initialized
    The program waits in MAIN for TMR1 to overflow, setting TMR1IF
    The value in COUNTER is written to PORTC (connected to a bank ofLEDs)
    The COUNTER is incremented and the whole thing starts again.

I spent a few days stomping bugs using MPLAB SIM.  Once I got everything
working, I loaded my demo board and used MPLAB ICD to see it in action.  I
expected everything to work perfectly (silly me).  However, while watching the
SFR window, I have noticed a problem.

TMR1 appears to roll over from 0xFFFE.  What I am seeing is TMR1 set to 0xFFFE,
then I step again and the next value is 0x0000.  TMR1IF is set by the overflow,
but the program does not go to the Interrupt vector.  When I modified the code
into a perpetual loop ("goto Interrupt" as the only line in Main and "goto Main"
replacing retfie) the counter works fine.  However, the reason for this whole
exercise was to get familiar with Interrupts.

I have reproprammed the chip several times.  Everytime the same thing happens.
Does anyone have any suggestions?


;*               cntrdemo.asm
;*    A demonstration program for the PIC 16f877
;*                Wendy Olend
;*               24 April 2001

  list p=16f877                   ;include files

COUNTER   equ  0x2d      ;register declaration

  org         0x00
  goto        Initialize

  org         0x04
  movf        COUNTER,w ;copy counter value and
  movwf  PORTC          ;send it to PORTC
  incf        COUNTER,f ;increment counter
  bcf         PIR1,0         ;reset TMR1IF
  movlw       0xf0      ;TEST ONLY
  movwf  TMR1L          ;will let TMR1 count from 0-FFFF
  movlw       0xff      ;in actual execution
  movwf  TMR1H

  clrf        T1CON          ;disables TMR1 until initialized
  clrf        PORTC          ;make sure PORTC is clear

  movlw       0xf0      ;TEST ONLY
  movwf  TMR1L          ;will let TMR1 count from 0-FFFF
  movlw       0xff      ;in actual execution
  movwf  TMR1H

  bcf         PIR1,0         ;clr TMR1 overflow flag
  movlw       0x01      ;initialize counter
  movwf  COUNTER

  bsf         STATUS,RP0     ;switch to bank1
  bsf         PIE1,0         ;EN TMR1 interrupt
  clrf        TRISC          ;PORTC all outputs
  bsf         INTCON,7  ;EN GIE
  bsf         INTCON,6  ;EN peripherial interrupts

  bcf         STATUS,RP0     ;return to bank0
  movlw       b'00000101'    ;TMR1 setup prescaler 1:1,
  movwf  T1CON          ;internal clock, timer EN

 goto         Main      ;wait for TMR1 to overflow
                   ;then handle interrupt

-- hint: The list server can filter out subtopics
(like ads or off topics) for you. See

More... (looser matching)
- Last day of these posts
- In 2001 , 2002 only
- Today
- New search...