MPLAB and PIC Help

Discussion in 'Programmer's Corner' started by ndhtx, Jan 12, 2012.

  1. ndhtx

    Thread Starter New Member

    Aug 11, 2011
    4
    0
    I'm new to PIC programming and trying to work through book examples. Working on Example7 (appendix B Examples)Using macros and debounce routine. I get a Error (Error[113] C:\DOCUMENTS AND SETTINGS\HP_ADMINISTRATOR\MY DOCUMENTS\PROGRAMMING\PIC\MICROCHIP\44-PIN DEMO BOARD\SAMPLE\BUTTON.INC 15 : Symbol not previously defined (PORT)) when trying to build.
    I have looked this up and read and find no answer so could someone please help. Thank you
    I'm using MPLAB IDE v8.60 and PIC 2 Kit with 16F887
    The error is in the macro button.asm Below is the code. When I click on error it goes to the first btfsc. Thank you


    Here is the site for examples working on #7

    http://www.mikroe.com/eng/chapters/view/12/appendix-b-examples/


    Code ( (Unknown Language)):
    1.  
    2. *************************************************************************
    3. *************************************************************************
    4. button MACRO     port,pin,hilo,label;
    5.        local       Pressed1        ; All labels are local
    6.        local       Pressed2
    7.        local       Exit1
    8.        local       Exit2
    9.        
    10.        IFNDEF      debouncedelay   ; Enables debounce time to be defined
    11.                                    ; in main program
    12.        #define     debouncedelay .10
    13.        ENDIF
    14.        
    15.        IF (hilo == 0)              ; If pull-up used
    16.        btfsc       port, pin       ; If "1", push-button is pressed
    17.        goto        Exit1
    18.        pausems     debouncedelay   ; Wait for 10ms debounce
    19. Pressed1
    20.        btfss       port, pin
    21.        goto        Pressed1
    22.        pausems     debouncedelay   ; Wait until released and
    23.        goto        label           ; jump to specified address
    24. Exit1
    25.        ELSE                        ; If pull-down used
    26.        btfss       port, pin
    27.        goto        Exit2           ; If "0", push-button is released
    28.        pausems     debouncedelay   ; Wait for 10ms debounce
    29. Pressed2
    30.        btfsc       port, pin
    31.        goto        Pressed2
    32.        pausems     debouncedelay   ; Wait until released and
    33.        goto        label           ; jump to specified address
    34. Exit2
    35.        ENDIF
    36.        
    37.        ENDM
    38.  
     
    Last edited by a moderator: Jan 13, 2012
  2. stahta01

    Member

    Jun 9, 2011
    133
    21
    You do realize that leading spaces are important in doing PIC Asm.
    You need to post using code tags so someone can confirm if that it is not a spacing issue.

    Tim S.
     
  3. stahta01

    Member

    Jun 9, 2011
    133
    21
    Found the error cause; not sure of solution.

    I changed this code from
    Code ( (Unknown Language)):
    1.  
    2. Loop
    3.        button       PORT,0,0,Increment
    4.        button       PORT,1,0,Decrement
    5.  
    To the below code. I guessed that it should be PORTB. It might be a different port.
    Code ( (Unknown Language)):
    1.  
    Code ( (Unknown Language)):
    1.  
    2. Loop
    3.        button       PORTB,0,0,Increment
    4.        button       PORTB,1,0,Decrement
    5.  
    Note: I found out if you comment out the include line that includes the macro file that the error messages is easier to understand in this exact case.

    Tim S.
     
  4. ndhtx

    Thread Starter New Member

    Aug 11, 2011
    4
    0
    Sorry about not putting in code box first post.

    How do you add code box
     
  5. ndhtx

    Thread Starter New Member

    Aug 11, 2011
    4
    0
    Below is the code for the project with both Macros. Also I have a question about does the Macros have to be in the main program file or just .inc files in the header?
    I don't think that this is PORTB if you look at Main Program but what do I know at this point not feeling like much. I have done 6 other samples that work but these Macros. Final project will be a scoreboard that counts up/down and from 0-21 with reset.

    Code ( (Unknown Language)):
    1. ; *******************************************************************
    2. ; PICkit 2 Lesson 7 - "1stscoreboard"
    3. ;
    4. ; This counts on the 44-Pin Demo Board.
    5. ;
    6. ; *******************************************************************
    7. ; *    See 44-pin Demo Board User's Guide for Lesson Information    *
    8. ; *******************************************************************
    9.  list     p=16F887
    10.  #include <p16F887.inc>
    11.     __CONFIG    _CONFIG1, _LVP_OFF & _FCMEN_OFF & _IESO_OFF & _BOR_OFF & _CPD_OFF & _CP_OFF & _MCLRE_OFF & _PWRTE_ON & _WDT_OFF & _INTRC_OSC_NOCLKOUT
    12.     __CONFIG    _CONFIG2, _WRT_OFF & _BOR21V
    13.  
    14. ;************* DEFINING VARIABLES *************************
    15.  
    16.        cblock      0x20            ; Block of variables starts at address 20hex
    17.        
    18.        HIcnt
    19.        LOcnt
    20.        LOOPcnt
    21.        cnt
    22.        endc                        ; End of block of variables
    23. ;**********************************************************************
    24.        ORG         0x000           ; Reset vector
    25.        nop
    26.        goto        main            ; Go to program start (label "main")
    27. ;**********************************************************************
    28.  
    29.        include    "pause.inc"
    30.        include    "button.inc"
    31.  
    32. ;**********************************************************************
    33.  main
    34.        banksel      ANSEL          ; Selects bank containing ANSEL
    35.        clrf         ANSEL          ; All pins are digital
    36.        clrf         ANSELH
    37.  
    38.        banksel      TRISB
    39.        bsf          TRISA, 0
    40.        bsf          TRISA, 1
    41.        clrf         TRISB
    42.        
    43.        banksel      PORTB
    44.        clrf         cnt      
    45.  Loop
    46.        button       PORT,0,0,Increment
    47.        button       PORT,1,0,Decrement
    48.        goto         Loop
    49.        
    50.  Increment
    51.        incf         cnt, f
    52.        movf         cnt, w
    53.        movwf        PORTB
    54.        goto         Loop
    55.  Decrement
    56.        decf         cnt, f
    57.        movf         cnt, w
    58.        movwf        PORTB
    59.        goto         Loop
    60.        end                         ; End of program
    61.  
    62.  
    63. ;********************************************Macro "pausems" ************************
    64.  pausems MACRO arg1
    65.        local        Loop1
    66.        local        dechi
    67.        local        Delay1ms
    68.        local        Loop2
    69.        local        End
    70.  
    71.        movlw        High(arg1)     ; Higher byte of argument is moved
    72.                                    ; to HIcnt
    73.        movwf        HIcnt
    74.        movlw        Low(arg1)      ; Lower byte of argument is moved
    75.                                    ; to LOcnt
    76.        movwf        LOcnt
    77.  Loop1
    78.        movf         LOcnt, f       ; Decrements HIcnt and LOcnt while
    79.        btfsc        STATUS, Z      ; needed and calls subroutine Delay1ms
    80.        
    81.        goto         dechi
    82.        call         Delay1ms
    83.        decf         LOcnt, f
    84.        goto         Loop1
    85.  dechi
    86.        movf         HIcnt, f
    87.        btfsc        STATUS, Z
    88.        goto         End
    89.        call         Delay1ms
    90.        decf         HIcnt, f
    91.        decf         LOcnt, f
    92.        goto         Loop1
    93.  Delay1ms:                          ; Delay1ms provides delay of
    94.        movlw        .100           ; 100*10us=1ms
    95.        movwf        LOOPcnt        ; LOOPcnt<-100
    96.  Loop2:
    97.        nop
    98.        nop
    99.        nop
    100.        nop
    101.        nop
    102.        nop
    103.        nop
    104.        decfsz      LOOPcnt, f
    105.        goto        Loop2           ; Execution time of Loop2
    106.        return                      ; is 10 us
    107.  End
    108.        ENDM
    109.  
    110.  
    111. ;****************************Macro "button" ***********************************************
    112.  
    113.  button MACRO    pin,port,hilo,label
    114.        local       Pressed1        ; All labels are local
    115.        local       Pressed2
    116.        local       Exit1
    117.        local       Exit2
    118.        
    119.        IFNDEF      debouncedelay   ; Enables debounce time to be defined
    120.                                    ; in main program
    121.        #define     debouncedelay .10
    122.        ENDIF
    123.        
    124.        IF (hilo == 0)              ; If pull-up used
    125.        btfsc       port, pin       ; If "1", push-button is pressed
    126.        goto        Exit1
    127.        pausems     debouncedelay   ; Wait for 10ms debounce
    128.  Pressed1
    129.        btfss       port, pin
    130.        goto        Pressed1
    131.        pausems     debouncedelay   ; Wait until released and
    132.        goto        label           ; jump to specified address
    133.  Exit1
    134.        ELSE                        ; If pull-down used
    135.        btfss       port, pin
    136.        goto        Exit2           ; If "0", push-button is released
    137.        pausems     debouncedelay   ; Wait for 10ms debounce
    138.  Pressed2
    139.        btfsc       port, pin
    140.        goto        Pressed2
    141.        pausems     debouncedelay   ; Wait until released and
    142.        goto        label           ; jump to specified address
    143.  Exit2
    144.        ENDIF
    145.        
    146.        END
     
  6. stahta01

    Member

    Jun 9, 2011
    133
    21
    The way I add code tags is click on "go advanced" button on bottom of post window. Then, I click on the "#" button on top of post window.

    This inserts these tags "[ CODE ]" and "[/ CODE ]" neither tags has spaces between the square brackets. You can just type the tags in by hand.

    NOTE: If you put the macros and code all in one file; then, the macros must be before the code that uses the macro.
    And, the delay macro must be before the other macro since it is used by the other macro.

    Tim S.
     
  7. ndhtx

    Thread Starter New Member

    Aug 11, 2011
    4
    0
    Did you see that I got the Info in there. Can you please take a look at it .

    Thank you

    Nick
     
  8. stahta01

    Member

    Jun 9, 2011
    133
    21
    I have no idea what you are asking.

    Tim S.
     
  9. AlexR

    Well-Known Member

    Jan 16, 2008
    735
    54
    Your button macro expects to see parameters passed to it in the order specified by the macro definition. So it expects to see "pin" followed by "port" followed by "hilo" followed by "label".
    In your main program you are passing port first then pin. Also you do not specify the port to use when you are passing the port to the macro.
    I have no idea of what your program is actually doing but if the buttons are on port A the loop code should be as follows to match the macro code.
    Obviously if they are on port B you would change PORTA to PORTB in the example below.
    Code ( (Unknown Language)):
    1.  
    2. Loop
    3.        button       0,PORTA,0,Increment
    4.        button       1,PORTA,0,Decrement
    5.        goto         Loop
    6.  
    Whether you put the macro in the include file or the main file a matter of programming style, either will work since the contents of the .inc file automatically gets added to the start of the main file by the assembler.
     
Loading...