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?
PIC18 Interrupts
Started by ●August 5, 2005
Reply by ●August 5, 20052005-08-05
1. shawnb_...@yahoo.com Aug 5, 10:53 am show options Newsgroups: comp.arch.embedded From: shawnb_...@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 by ●August 5, 20052005-08-05
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 <p18f452.h> /* for the special function register declarations */ #include <portb.h> /* 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 by ●August 5, 20052005-08-05
On 5 Aug 2005 11:02:17 -0700, the renowned StephensDigital@gmail.com wrote:> >1. shawnb_...@yahoo.com Aug 5, 10:53 am show options >Newsgroups: comp.arch.embedded >From: shawnb_...@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 StephensAlso get yourself a copy of the "PICmicro� 18C MCU Family Reference Manual", which presents the information slightly differently and in more detail relative to the datasheets. It's a bit more complex than the lower end PICs because of the multiple priority interrupts, but it is still pretty straightforward once you understand it. By the way, I don't much like your idea of triggering an interrupt off of a switch unless you really need to do it (for example to come out of sleep on change). I'd rather see you polling the switch from a timer-driven periodic interrupt. Best regards, Spehro Pefhany -- "it's the network..." "The Journey is the reward" speff@interlog.com Info for manufacturers: http://www.trexon.com Embedded software/hardware/analog Info for designers: http://www.speff.com