PIC18 Interrupts

Hello all. I'm a newbie in the realm of micro programming. I'm using MPLAB C18 with the PIC18F452 and PICDEMO 2 Plus board. I can't, for the life of me, figure out how to do an interrupt routine! I've used the buzzer interrupt sample that came with the ICD2 software, but have been unable to modify it to suit my needs. What I want to do is wait for a button to be pressed to start my routine. Can someone please help?

Reply to
shawnb_usn
Loading thread data ...
  1. shawnb snipped-for-privacy@yahoo.com Aug 5, 10:53 am show options Newsgroups: comp.arch.embedded From: shawnb snipped-for-privacy@yahoo.com - Find messages by this author Date: 5 Aug 2005 10:53:59 -0700 Local: Fri, Aug 5 2005 10:53 am Subject: PIC18 Interrupts Reply | Reply to Author | Forward | Print | Individual Message | Show original | Report Abuse

Hello all. I'm a newbie in the realm of micro programming. I'm using MPLAB C18 with the PIC18F452 and PICDEMO 2 Plus board. I can't, for the life of me, figure out how to do an interrupt routine! I've used the buzzer interrupt sample that came with the ICD2 software, but have been unable to modify it to suit my needs. What I want to do is wait for a button to be pressed to start my routine. Can someone please help?

Well, the PIC18XX family has a wealth of interrupt sources including interrupt on PORT(B?) value change which would probably work for your button press. CHeck out Microchip's website. There are scads of application notes on stuff like this.

Bob Stephens

Reply to
StephensDigital

I've been trying, but I guess I don't know what to look for. I feel like the code I'm writing should work. Would you take a look and tell me why it doesn't?

This program is simple...wait for the button press, then turn on all of PORTC.

#include /* for the special function register declarations

*/ #include /* for the RB0/INT0 interrupt */

#pragma config OSC = HS #pragma config WDT = OFF #pragma config LVP = OFF #pragma config DEBUG = ON

void toggle_light (void);

#pragma code HIGH_INTERRUPT_VECTOR = 0x8 void high_ISR(void) { _asm goto toggle_light _endasm } #pragma code

#pragma interrupt toggle_light void toggle_light (void) { TRISC=0; PORTC=255; }

void EnableHighInterrupts (void) { RCONbits.IPEN = 1; /* enable interrupt priority levels */ INTCONbits.GIEH = 1; /* enable all high priority interrupts */ }

void main(void){ EnableHighInterrupts(); OpenRB0INT (PORTB_CHANGE_INT_ON & /* enable the RB0/INT0 interrupt */ PORTB_PULLUPS_ON & /* configure the RB0 pin for input

*/ FALLING_EDGE_INT); /* trigger interrupt upon S3 button depression */ CCP1CON = 0x0F; while(1); }
Reply to
shawnb_usn

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.