PDA

View Full Version : interrupt on PICDEM2 +



khoog
- 12th January 2005, 20:35
I think I've done everything right. Spelling, punctuation, etc., but it still won't interrupt. Did I miss something dumb and obvious?

Using picdem2+ board, 18F452, 4mHz, rb0=pb switch to gnd.

led var PORTB.3

On Interrupt Goto MYINT1 ' Define interrupt handler
INTCON = $90 ' Enable INTE interrupt
INTCON2.7 = 0 ' Enable PORTB pullups
loop:
High led ' Turn LED on
Goto loop ' Do it forever

' Interrupt handler
Disable ' No interrupts past this point
MYINT1:
low led
pause 500 ' Wait .5 seconds
INTCON.1 = 0 ' Clear interrupt flag
Resume ' Return to main program
Enable

mister_e
- 12th January 2005, 21:17
what about if you move your code lines like this


led var PORTB.3
INTCON2.7 = 0 ' Enable PORTB pullups
INTCON = $90 ' Enable INTE interrupt

On Interrupt Goto MYINT1 ' Define interrupt handler


loop:
High led ' Turn LED on
Goto loop ' Do it forever

mister_e
- 12th January 2005, 21:37
Forget about above, your code is working. i just try it... must be a hardware or programming problem here.

Be sure you set oscillator to XT.

khoog
- 12th January 2005, 22:52
Thanks Steve for your quick reply. I'm glad that the code is working somewhere. What I posted is the entire program, there is no other programming. The LED at rb3 lights up fine.

I'm assuming, first of all, that grounding the rb0 pin will result in the interrupt routine being executed (but it's not). The schematic for the picdem2+ board is available at:

http://ww1.microchip.com/downloads/en/DeviceDoc/51275b.pdf

As shown in the schematic rb0 also has an LED attached, but neither the LED nor the pullup should have any effect on the interrupt (at least as far as I see it).

What exactly do you mean by "set oscillator to XT"?

Thanks
Klaus

mister_e
- 12th January 2005, 23:19
hi Klaus,


What exactly do you mean by "set oscillator to XT"?

wich kind of programmer do you use :PICSTART, EPIC or else ?
When you compile your code with PBP, here are the default osc setting you'll find the the pic18F452.inc file

__CONFIG _CONFIG1H, _OSCS_OFF_1H & _XT_OSC_1H

These mean that you'll use XT oscillator (4mhz in your case) and you disable the oscillator switching mode (don't care for your app now)

BUT i heard that some PIC programmer don't refresh those setting when you use the .HEX file for programming you PIC. So they will use their own default.. sometime RC-OSC as RA6. In this case you have chance if anything is working.

In your programmer program you must have some place to set the "configuration bit" or "configuration fuse". Be sure to have XT OSC as oscillator setting. If anything is properly set, it will work.

Case not try another program like simple Blink, keep Pull-up enable on PORTB, remove any interrupt stuff and do the blink while your push button is hold. that way you'll know that everything is working.



TRISB=%11110111
LED VAR PORTB.3
start:
while PORTB.0=0
toggle LED
pause 500
wend
goto start



Be sure MCLR pin is set to 5Volt with pull-up resistors. And the last one be sure that you have capacitor (10-22pf) on each pin of your crystal to the ground.

i can't say more than this :)

khoog
- 13th January 2005, 00:30
Steve,

I'm using ICD2. The picdem2+ came with the ICD2 so I assume they are made to work with each other (or maybe the folks at Microchip have more of a sense of humor than we give them credit for). I did add "Define osc 4" just for good measure.

I commented out the interrupt statements as you suggested and added a goto in the middle of the loop:

if portb0.0 = 0 then goto myint1

Works like a charm.

Put the interrupt back in and ran in debug mode. The animation shows clearly portb.0 going form 1 to 0 when the button is pressed, but intcon.7 stays at 0.

Time for a beer break.

Klaus

khoog
- 13th January 2005, 02:34
Had some clip leads laying around so I attached an LED to portC, disabled the portB Leds, and changed the code to blink rc.7.

Everything is interrupting just great now. I guess the LED and pullup on rb0 were just too confusing for the interrupt to work.

Thanks again for your help Steve.

Klaus

Bruce
- 13th January 2005, 15:08
Try it with INCLUDE "ICDDEFS4.BAS" in the top section of your code to reserve space for ICD vars.

ICDDEFS4.BAS is for the - 18F252/258/452/458

khoog
- 14th January 2005, 02:00
Bruce,

Thanks for your input. I was finally able to get the interrupt working by disabling (diconnecting) the LEDs on rb0-rb3. It was a hardware problem after all.

You bring up an interesting point, though. Just how much overhead does the ICD require?

Best Regards,
Klaus

Bruce
- 14th January 2005, 08:00
Hi Klaus,

> how much overhead does the ICD require?

Not too much. The PBP header file ICDDEFS4.BAS reserves a few bytes for the "debug executive" ; ICDRESERVED12 VAR BYTE(12) $5f4, and the ICD2 uses & limits a few options like WDT, LVP, etc, but your ICD2 docs will give you a beter idea of the resources needed.

It's pretty handy. I use the PICDEM 2 Plus, ICD2 & PBP all the time.