PDA

View Full Version : Interrupts on 18F4220



BillW
- 8th January 2007, 21:57
Thanks for any help on this--I am new to PICs but cut my teeth some on stamp things....


I am having trouble getting a simple interrupt routine to run on an 18F4220. (I have some boards that we made earlier that I would like to reuse)

I started by using a sippet of code from Chuck Hellebuyck (Nuts and Volts June 2006) and a PIC 16F877

Circuit Stuff (on Protoboard)
LED on Pin PORTB.1
Switch on RB0
ISP for programming

My Version of his code

LED1 Var PortB.1

On Interrupt goto myint
OPTION_REG = %00111111
INTCON = %10010000

loop:
High LED1
Pause 100
Low LED1
Pause 100
Goto loop

DISABLE
myint:
Low LED1
Pause 500
INTCON.1=0
Resume
Enable

This runs fine on the 16F877 , When I swap in the 18F4220 and change the code to :

LED1 Var PortB.1

On Interrupt goto myint
INTCON2 = %00111111 '<---------change here
INTCON = %10010000

loop:
High LED1
Pause 100
Low LED1
Pause 100
Goto loop

DISABLE
myint:
Low LED1
Pause 500
INTCON.1=0
Resume
Enable


I never get the interrupt routine to run.

Any Ideas?

mister_e
- 8th January 2007, 22:22
PORTB have some analog stuff multiplexed with..
you need to add


ADCON1=$0F

at the top of your code to disable ADCs.

BUT you could also edit the config fuses as well.

BillW
- 9th January 2007, 14:45
Thanks!!!!

I made the changes this morning and the 18F4220 is getting the interrupt.

Thanks for the pointer. I am still learning about the config bits and often forget to look at them.

I still have a little clock speed issue, but I think that is probably config bits also.....

Thanks again.