Martin, You're transferring the information the wrong way in the version that doesn't work. You probably want to say movwf INTCON ; transfer contents to W to INTCON rather than movf INTCON,W ; transfer contents of INTCON to W Cheers, Andy -----Original Message----- From: Martin McCormick [mailto:martin@DC.CIS.OKSTATE.EDU] Sent: 31 January 2000 14:39 To: PICLIST@MITVMA.MIT.EDU Subject: Correct Way to Set INTCON I made an interesting discovery while writing some 16C71 code using mpasm to write the code and mpsim to test it. I am using the TMR0 internal interrupt along with the prescaler. If I set INTCON as follows: bsf INTCON,GIE bcf INTCON,ADIE bsf INTCON,T0IE bcf INTCON,INTE the code works as expected in mpsim. I use e to execute it and it runs until tmr0 rolls over and then it goes to the interrupt vector as expected. To save a couple of program cycles, I tried movlw B'10100000' movf INTCON,w That produces an executable that runs with TMR0 rolling over and over without producing an interrupt. As I understand the documentation, the lower four bits of INTCON are flags that one reads to see what caused an interrupt in the first place and then clears to get ready for the next interrupt. Why does the two-step setup process kill the interrupts? At this time, the whole program is a skeleton that does nothing neat yet. Here is the whole main loop. main ;initialization code which only runs on power-up is here. bcf INTCON,T0IF ;Turn off TMR0 int flag. ;Safety, first. BSF STATUS, RP0 ; Select Bank 1 clrw ;Set w to 0 to make all outputs. ; initialize data direction movwf1 TRISB ;Macro contributed by Dwayne Reid. movlw B'10000000' movwf1 OPTION_REG ;This appears to have the proper effect. movlw samplespeedset movfw TMR0;Take a few counts off of TMR0. Appears to work correctly. bsf INTCON,GIE bcf INTCON,ADIE bsf INTCON,T0IE bcf INTCON,INTE ;Turn on the two enables needed here and make sure the other two are off. running;In subsequent loops, the forground loop goes back to here. ; remaining code goes here nop ;busy work goto running; continuous loop for main routine END ;That's all, folks. Is mpsim pretty faithful to the way a real PIC would have behaved? I am simply curious as to why the binary load of the INTCON worked differently than the individual setting of the bits. Martin McCormick