One thing I think I see here is return instead of retfie might be misunderstanding because of the many snip's Peter ----- Original Message ----- From: "adastra" To: Sent: Wednesday, June 23, 2004 10:49 PM Subject: [PIC]: Mysterious INTCON troubles with PIC16F877 (RP / better font) > Wise Ones: > > > > I am a moderately experienced programmer, but I am completely puzzled by > the behavior of this code fragment. > > I've been stuck on this all day. I'm obviously overlooking something. > Can anybody help? > > > > This is inside an ISR and is intended to set a flag and clear a register > after counting down a number of TMR0 overflows. > > > > Inter > > (snip) > > > > decfsz ir_cnt ;counts down 8.9ms > > return ;return if not yet counted down to 0 > > irtst nop ;test point for IR countdown > > movlw b'01110000' ;clear any latent external interrupt > (from IR detector) > > movwf INTCON ; and re-enable external interrupt > > nop > > bsf flags_5,1 ;set this flag denoting end of > 8.9ms period > > clrf ir_dat > > return > > > > ======================================================== > > > > This is what happens, as seen by single-stepping in MPLAB IDE v5.61: > > > > irtst nop ;test point for IR countdown > > > > When the program reaches this point, watch window shows INTCON = > b'01100110' > > > > movlw b'01110000' ;clear any latent external interrupt > (from IR detector) > > movwf INTCON ; and re-enable external interrupt > > > > SURPRISINGLY after the movwf the watch-window shows INTCON = b'11110100' > > > How can b2 (TOIF) still be set ? > > > > nop > > > > SURPRISINGLY after executing this NOP, the watch-window shows INTCON = > b'11110110' > > Now b1, (INTF) is ALSO set, even if I (temporarily) physically strap the > RB0/INT pin HIGH > > in order to be sure that no external interrupt can occur ! > > > > clrf ir_dat > > return > > > > I just don't understand how this can be happening. > > > > ======================================================== > > > > Here are my INTCON and OPTION_REG setups: > > > > INTCON setup > > movlw b'11110000' ; GIE=on TOIE=on (peripheral AND > timer0 overflow > > movwf INTCON ; AND ext-int set up) > > > > ; x------- ; 7, GIE: Global Internet Enable (1 = > ints enabled) > > ; -x------ ; 6, PEIE: Peripheral Interupt Enable > (1 = p. ints enabled) > > ; --x----- ; 5, TOIE: TMR0 Overflow Interrupt > Enable (1 enables interrupt) > > ; ---x---- ; 4, INTE: RB0/INT Ext. int (1 enables > ext ints) > > ; ----x--- ; 3, RBIE: RB Change Interrupt Enable > (1 enables port change int) > > ; -----x-- ; 2, TOIF: TMR0 Overflow Interrupt > Flag (1 = overflowed) > > ; ------x- ; 1, INTF: RB0/INT External Interrupt > Flag (1=external int.) > > ; -------x ; 0, RBIF: RB Port Change Interrupt > Flag (at least one of RB7:RB4 > > ; has changed if this > flag is set > > > > OPTION_REG setup > > movlw b'00001000' > > movwf OPTION_REG ; load data into OPTION_REG > > ; > > ; x------- ; 7, 0=enable, 1=disable, portb > pullups > > ; -x------ ; 6, 1=/, int edge select bit > 0=falling > > ; --x----- ; 5, timer0 source, 0=internal clock, > 1=ext pin. > > ; ---x---- ; 4, timer0 ext edge, 1=\ > > ; ----x--- ; 3, prescaler assign, 1=wdt, 0=timer0 > > ; -----x-- ; 2,1,0, timer0 prescaler rate select > > ; ------x- ; 000=2, 001=4, 010=8, 011=16, etc. > > ; -------x ; > > ; Note! We set the prescaler to the > wdt, so timer0 overflows > > ; every 256 instructions > to make an interrupt every 102.4 uS > > ; (for 10 MHz clock) > > > > TRISB is set for all outputs, except for RBO/INT which is used as an > external interrupt > > > > =========================================================== > > > > Obviously I have to be able to clear the TOIF and INTF flags, but I > can't seem to do it. > > I have tried different '877's on the off chance that the chip was bad, > but no joy. > > Power Supply voltage looks good, with appropriate 0.1uF bypass at chip > pins > > Interrupt context-saving is implemented > > > > I would be so thankful if someone can tell me what I am missing here. > > > > Thanks, > > > > Foster > > > > > -- > http://www.piclist.com#nomail Going offline? Don't AutoReply us! > email listserv@mitvma.mit.edu with SET PICList DIGEST in the body > -- http://www.piclist.com#nomail Going offline? Don't AutoReply us! email listserv@mitvma.mit.edu with SET PICList DIGEST in the body