Interrupt - PIC18F4550 - error in _asm GOTO high_isr _endasm

Discussion in 'Embedded Systems and Microcontrollers' started by Veeramani.T, May 1, 2014.

  1. Veeramani.T

    Thread Starter New Member

    May 1, 2014
    1
    0
    I want to use the interrupt in PIC 18F4550 by the following code:

    Code ( (Unknown Language)):
    1.  
    2. #include <p18f4550.h>
    3.  
    4. void interrupt_at_high_vector(void);
    5. void high_isr(void);
    6.  
    7. #pragma config PLLDIV = 4, CPUDIV = OSC1_PLL2, FOSC = HS, FCMEN = OFF, IESO = OFF, PWRT = OFF, BOR = ON, BORV = 3, WDT = OFF, WDTPS = 32768
    8. #pragma config MCLRE = OFF, LPT1OSC = OFF, PBADEN = ON, CCP2MX = ON, STVREN = ON, LVP = OFF, XINST = OFF, VREGEN = OFF, ICPRT = OFF, DEBUG = ON
    9. #pragma config CP0 = OFF, CP1 = OFF, CP2 = OFF, CP3 = OFF, CPB = OFF, CPD = OFF, WRT0 = OFF, WRT1 = OFF, WRT2 = OFF, WRT3 = OFF
    10. #pragma config WRTB = OFF, WRTC = OFF, WRTD = OFF, EBTR0 = OFF, EBTR1 = OFF, EBTR2 = OFF, EBTR3 = OFF, EBTRB = OFF
    11.  
    12. #pragma code high_vector=0x08
    13. void interrupt_at_high_vector(void)
    14. {
    15. [COLOR="Red"]_asm GOTO high_isr _endasm[/COLOR]
    16. }
    17. #pragma code /* return to the default code section */
    18. #pragma interrupt high_isr
    19. void high_isr(void)
    20. {
    21. LATC = 1; //RC0 HIGH
    22. INTCONbits.TMR0IF = 0; //CLEAR TMR0 INT FLAG
    23. }
    24.  
    25. void main(void){
    26. TRISC = 0;
    27. LATC = 0;
    28. INTCON = 0xA0; //GIE AND TMR0IE
    29. T0CON = 0x85; //16-BIT, TMRON, PRESCALER 1:128
    30. while (1); //wait for interrupt
    31. }
    32.  
    -----------------

    But i got the error in

    Warning [335] D:\ME (ES)\SEM VI\gsm\just_1.c; 11.1 unknown pragma "code"
    Error [195] D:\ME (ES)\SEM VI\gsm\just_1.c; 14.1 expression syntax
    Error [312] D:\ME (ES)\SEM VI\gsm\just_1.c; 15.1 ";" expected
    Warning [335] D:\ME (ES)\SEM VI\gsm\just_1.c; 16.1 unknown pragma "code"
    Warning [335] D:\ME (ES)\SEM VI\gsm\just_1.c; 17.1 unknown pragma "interrupt"
    (908) exit status = 1

    How i clear this error ?
     
    Last edited by a moderator: May 1, 2014
  2. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,395
    1,607
    So the compiler doesn't know what "#pragma code" means. That is a fairly well defined term for the C18 compiler. You seem to have followed the example code well.

    It is a bit difficult to match compiler errrors to specific lines without knowing the line numbers. So if you post again please indicate which lines are the problem. Also use code tags (that # icon) so your formatting gets preserved.

    Are you using that compiler? The complete build spew of information notes which compiler it is using.

    One thing C oft does is report an error on a line when it is the previous line that has a typo or such. I'm very curious where the missing ";" is.

    And welcome to the forums!
     
  3. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    Take a look at this example from PICKIT 3 debug express. It should be correct. I do not use your compiler so I can not help much more. But here is the manual for PICKIT 3 debug express. It use the same compiler as you do
    http://ww1.microchip.com/downloads/en/DeviceDoc/51795B.pdf
    code
    http://savedonthe.net/download/484/PICkit-3-Debug-Express-Lessons.html
    Code ( (Unknown Language)):
    1.  //******************************************************************************
    2. //Software License Agreement                                        
    3. //                                                                    
    4. //The software supplied herewith by Microchip Technology            
    5. //Incorporated (the "Company") is intended and supplied to you, the  
    6. //Company’s customer, for use solely and exclusively on Microchip    
    7. //products. The software is owned by the Company and/or its supplier,
    8. //and is protected under applicable copyright laws. All rights are  
    9. //reserved. Any use in violation of the foregoing restrictions may  
    10. //subject the user to criminal sanctions under applicable laws, as  
    11. //well as to civil liability for the breach of the terms and        
    12. //conditions of this license.                                        
    13. //                                                                    
    14. //THIS SOFTWARE IS PROVIDED IN AN "AS IS" CONDITION. NO WARRANTIES,  
    15. //WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED  
    16. //TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A      
    17. //PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE COMPANY SHALL NOT,  
    18. //IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR        
    19. //CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.      
    20. // *******************************************************************
    21. // PIC18F45K20 PICkit 3 Debug Express Lesson 8 - Interrupts
    22. //
    23. // This lesson goes over using interrupts to process external and
    24. // peripheral events.  The switch activates external interrupt INT0
    25. // when pressed, and Timer0 is now serviced in an interrupt when it
    26. // overflows.  Functionally, the program works the same as lesson 07.
    27. //
    28. // *******************************************************************
    29. // *    See included documentation for Lesson instructions           *
    30. // *******************************************************************
    31. /** C O N F I G U R A T I O N   B I T S ******************************/
    32. #pragma config FOSC = INTIO67, FCMEN = OFF, IESO = OFF                      // CONFIG1H
    33. #pragma config PWRT = OFF, BOREN = OFF, BORV = 30                           // CONFIG2L
    34. #pragma config WDTEN = OFF, WDTPS = 32768                                    // CONFIG2H
    35. #pragma config MCLRE = ON, LPT1OSC = OFF, PBADEN = ON, CCP2MX = PORTC       // CONFIG3H
    36. #pragma config STVREN = ON, LVP = OFF, XINST = OFF                          // CONFIG4L
    37. #pragma config CP0 = OFF, CP1 = OFF, CP2 = OFF, CP3 = OFF                   // CONFIG5L
    38. #pragma config CPB = OFF, CPD = OFF                                         // CONFIG5H
    39. #pragma config WRT0 = OFF, WRT1 = OFF, WRT2 = OFF, WRT3 = OFF               // CONFIG6L
    40. #pragma config WRTB = OFF, WRTC = OFF, WRTD = OFF                           // CONFIG6H
    41. #pragma config EBTR0 = OFF, EBTR1 = OFF, EBTR2 = OFF, EBTR3 = OFF           // CONFIG7L
    42. #pragma config EBTRB = OFF                                                  // CONFIG7H
    43. /** I N C L U D E S **************************************************/
    44. #include "p18f45k20.h"
    45. #include "08 Interrupts.h"  // header file
    46. /** V A R I A B L E S *************************************************/
    47. #pragma udata   // declare statically allocated uinitialized variables
    48. unsigned char LED_Display;  // 8-bit variable
    49. LEDDirections Direction = LEFT2RIGHT;   // global now to access in Interrupts
    50. /** I N T E R R U P T S ***********************************************/
    51. //----------------------------------------------------------------------------
    52. // High priority interrupt vector
    53. #pragma code InterruptVectorHigh = 0x08
    54. void InterruptVectorHigh (void)
    55. {
    56.   _asm
    57.     goto InterruptServiceHigh //jump to interrupt routine
    58.   _endasm
    59. }
    60. //----------------------------------------------------------------------------
    61. // Low priority interrupt vector
    62. #pragma code InterruptVectorLow = 0x18
    63. void InterruptVectorLow (void)
    64. {
    65.   _asm
    66.     goto InterruptServiceLow //jump to interrupt routine
    67.   _endasm
    68. }
    69. /** D E C L A R A T I O N S *******************************************/
    70. #pragma code    // declare executable instructions
    71. void main (void)
    72. {
    73.     LED_Display = 1;            // initialize
    74.    // Init I/O
    75.     TRISD = 0b00000000;      // PORTD bits 7:0 are all outputs (0)
    76.  TRISAbits.TRISA0 = 1;  // TRISA0 input
    77.  INTCON2bits.RBPU = 0;  // enable PORTB internal pullups
    78.  WPUBbits.WPUB0 = 1;   // enable pull up on RB0
    79.     // ADCON1 is now set up in the InitADC() function.
    80.     TRISBbits.TRISB0 = 1;       // PORTB bit 0 (connected to switch) is input (1)
    81.     // Init Timer0
    82.     Timer0_Init();              // now enables interrupt.
    83.     // Init ADC
    84.     ADC_Init();
    85.     // Set up switch interrupt on INT0
    86.     INTCON2bits.INTEDG0 = 0;    // interrupt on falling edge of INT0 (switch pressed)
    87.     INTCONbits.INT0IF = 0;      // ensure flag is cleared
    88.     INTCONbits.INT0IE = 1;      // enable INT0 interrupt
    89.     // NOTE: INT0 is ALWAYS a high priority interrupt
    90.     // Set up global interrupts
    91.     RCONbits.IPEN = 1;          // Enable priority levels on interrupts
    92.     INTCONbits.GIEL = 1;        // Low priority interrupts allowed
    93.     INTCONbits.GIEH = 1;        // Interrupting enabled.
    94.  
    95.     while (1)
    96.     { // we update the port pins in our "background" loop while the interrupts
    97.       // handle the switch and timer.
    98.         LATD = LED_Display;         // output LED_Display value to PORTD LEDs
    99.     }
    100.  
    101. }
    102. void Timer0_Init(void)
    103. {
    104.     // Set up Interrupts for timer
    105.     INTCONbits.TMR0IF = 0;          // clear roll-over interrupt flag
    106.     INTCON2bits.TMR0IP = 0;         // Timer0 is low priority interrupt
    107.     INTCONbits.TMR0IE = 1;          // enable the Timer0 interrupt.
    108.     // Set up timer itself
    109.     T0CON = 0b00000001;             // prescale 1:4 - about 1 second maximum delay.
    110.     TMR0H = 0;                      // clear timer - always write upper byte first
    111.     TMR0L = 0;
    112.     T0CONbits.TMR0ON = 1;           // start timer
    113. }
    114. void ADC_Init(void)
    115. { // initialize the Analog-To-Digital converter.
    116.  ANSEL = 0; //turn off all other analog inputs
    117.  ANSELH = 0;
    118.   ANSELbits.ANS0 = 1; // turn on RA0 analog
    119.     ADCON2 = 0b00111000;
    120.     ADCON0 = 0b00000001;
    121. }
    122. unsigned char ADC_Convert(void)
    123. { // start an ADC conversion and return the 8 most-significant bits of the result
    124.     ADCON0bits.GO_DONE = 1;             // start conversion
    125.     while (ADCON0bits.GO_DONE == 1);    // wait for it to complete
    126.     return ADRESH;                      // return high byte of result
    127. }
    128.  
    129. // -------------------- Iterrupt Service Routines --------------------------
    130. #pragma interrupt InterruptServiceHigh  // "interrupt" pragma also for high priority
    131. void InterruptServiceHigh(void)
    132. {
    133.     // Check to see what caused the interrupt
    134.     // (Necessary when more than 1 interrupt at a priority level)
    135.     // Check for INT0 interrupt
    136.     if (INTCONbits.INT0IF)
    137.     {
    138.         // clear (reset) flag
    139.         INTCONbits.INT0IF = 0;
    140.         // change directions
    141.         if (Direction == LEFT2RIGHT)
    142.         {
    143.             Direction = RIGHT2LEFT;     // change direction
    144.         }
    145.         else // (Direction == RIGHT2LEFT)
    146.         {
    147.             Direction = LEFT2RIGHT;     // change direction
    148.         }
    149.  
    150.     }
    151.     // Check for another interrupt, examples:
    152.     // if (PIR1bits.TMR1IF)     // Timer 1
    153.     // if (PIR1bits.ADIF)       // ADC
    154. }  // return from high-priority interrupt
    155. #pragma interruptlow InterruptServiceLow// "interruptlow" pragma for low priority
    156. void InterruptServiceLow(void)
    157. {
    158.     // Check to see what caused the interrupt
    159.     // (Necessary when more than 1 interrupt at a priority level)
    160.     // Check for Timer0 Interrupt
    161.     if  (INTCONbits.TMR0IF)
    162.     {
    163.         INTCONbits.TMR0IF = 0;          // clear (reset) flag
    164.         // Take an ADC conversion and use it to set Timer0
    165.         TMR0H = ADC_Convert();      // MSB from ADC
    166.         TMR0L = 0;                  // LSB = 0
    167.         // update display variable
    168.         if (Direction == LEFT2RIGHT)
    169.         {
    170.             LED_Display <<= 1;          // rotate display by 1 from 0 to 7
    171.             if (LED_Display == 0)
    172.                 LED_Display = 1;        // rotated bit out, so set bit 0
    173.         }
    174.         else // (Direction == RIGHT2LEFT)
    175.         {
    176.             LED_Display >>= 1;          // rotate display by 1 from 7 to 0
    177.             if (LED_Display == 0)
    178.                 LED_Display = 0x80;     // rotated bit out, so set bit 7
    179.         }
    180.  
    181.     }
    182.     // Check for another interrupt, examples:
    183.     // if (PIR1bits.TMR1IF)     // Timer 1
    184.     // if (PIR1bits.ADIF)       // ADC
    185. }
     
  4. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,395
    1,607
    I just dropped the code into MPLAB and hit compile. Guess what?

    Code ( (Unknown Language)):
    1. ----------------------------------------------------------------------
    2. Release build of project `C:\1346_Timer\Q files\Q1.mcp' started.
    3. Language tool versions: mpasmwin.exe v5.54, mplink.exe v5.00, mcc18.exe v3.47, mplib.exe v5.00
    4. Thu May 01 12:14:58 2014
    5. ----------------------------------------------------------------------
    6. Make: The target "C:\1346_Timer\Q files\Q.o" is out of date.
    7. Executing: "C:\Program Files (x86)\Microchip\mplabc18\v3.47\bin\mcc18.exe" -p=18F4550 "Q.c" -fo="Q.o" -Ou- -Ot- -Ob- -Op- -Or- -Od- -Opa-
    8. MPLAB C18 3.47 (evaluation)
    9. Copyright 2000-2011 Microchip Technology Inc.
    10. Days remaining until evaluation becomes feature limited:  19
    11. WARNING:  Running the compiler in extended mode will not be supported when the evaluation becomes feature limited.
    12. Make: The target "C:\1346_Timer\Q files\Q1.cof" is out of date.
    13. Executing: "C:\Program Files (x86)\Microchip\mplabc18\v3.47\bin\mplink.exe" /p18F4550 /l"C:\Program Files (x86)\Microchip\mplabc18\v3.47\lib" "Q.o" /u_CRUNTIME /z__MPLAB_BUILD=1 /o"Q1.cof" /M"Q1.map" /W
    14. MPLINK 5.00, LINKER
    15. Device Database Version 1.17
    16. Copyright (c) 1998-2013 Microchip Technology Inc.
    17. Errors    : 0
    18. MP2HEX 5.00, COFF to HEX File Converter
    19. Copyright (c) 1998-2013 Microchip Technology Inc.
    20. Errors    : 0
    21. Loaded C:\1346_Timer\Q files\Q1.cof.
    22. ----------------------------------------------------------------------
    23. Release build of project `C:\1346_Timer\Q files\Q1.mcp' succeeded.
    24. Language tool versions: mpasmwin.exe v5.54, mplink.exe v5.00, mcc18.exe v3.47, mplib.exe v5.00
    25. Thu May 01 12:15:00 2014
    26. ----------------------------------------------------------------------
    27. BUILD SUCCEEDED
    The last two words are relevant here. :D

    So the next question is what compiler in what IDE are you using? Something in the tool chain needs adjustment.
     
Loading...