MPLAB and PIC Help

Thread Starter

ndhtx

Joined Aug 11, 2011
4
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/


Rich (BB code):
*************************************************************************
*************************************************************************
button MACRO     port,pin,hilo,label;
       local       Pressed1        ; All labels are local
       local       Pressed2
       local       Exit1
       local       Exit2
       
       IFNDEF      debouncedelay   ; Enables debounce time to be defined
                                   ; in main program
       #define     debouncedelay .10
       ENDIF
       
       IF (hilo == 0)              ; If pull-up used
       btfsc       port, pin       ; If "1", push-button is pressed
       goto        Exit1
       pausems     debouncedelay   ; Wait for 10ms debounce
Pressed1
       btfss       port, pin
       goto        Pressed1
       pausems     debouncedelay   ; Wait until released and
       goto        label           ; jump to specified address
Exit1
       ELSE                        ; If pull-down used
       btfss       port, pin
       goto        Exit2           ; If "0", push-button is released
       pausems     debouncedelay   ; Wait for 10ms debounce
Pressed2
       btfsc       port, pin
       goto        Pressed2
       pausems     debouncedelay   ; Wait until released and
       goto        label           ; jump to specified address
Exit2
       ENDIF
       
       ENDM
 
Last edited by a moderator:

stahta01

Joined Jun 9, 2011
133
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.
 

stahta01

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

I changed this code from
Rich (BB code):
Loop
       button       PORT,0,0,Increment
       button       PORT,1,0,Decrement
To the below code. I guessed that it should be PORTB. It might be a different port.
Rich (BB code):
Rich (BB code):
Loop
       button       PORTB,0,0,Increment
       button       PORTB,1,0,Decrement
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.
 

Thread Starter

ndhtx

Joined Aug 11, 2011
4
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.

Rich (BB code):
; *******************************************************************
; PICkit 2 Lesson 7 - "1stscoreboard"
;
; This counts on the 44-Pin Demo Board.
;
; *******************************************************************
; *    See 44-pin Demo Board User's Guide for Lesson Information    *
; *******************************************************************
 list     p=16F887
 #include <p16F887.inc>
    __CONFIG    _CONFIG1, _LVP_OFF & _FCMEN_OFF & _IESO_OFF & _BOR_OFF & _CPD_OFF & _CP_OFF & _MCLRE_OFF & _PWRTE_ON & _WDT_OFF & _INTRC_OSC_NOCLKOUT
    __CONFIG    _CONFIG2, _WRT_OFF & _BOR21V

;************* DEFINING VARIABLES *************************

       cblock      0x20            ; Block of variables starts at address 20hex
       
       HIcnt
       LOcnt
       LOOPcnt
       cnt
       endc                        ; End of block of variables
;**********************************************************************
       ORG         0x000           ; Reset vector
       nop
       goto        main            ; Go to program start (label "main")
;**********************************************************************

       include    "pause.inc"
       include    "button.inc"

;**********************************************************************
 main
       banksel      ANSEL          ; Selects bank containing ANSEL
       clrf         ANSEL          ; All pins are digital
       clrf         ANSELH
 
       banksel      TRISB
       bsf          TRISA, 0
       bsf          TRISA, 1
       clrf         TRISB
       
       banksel      PORTB
       clrf         cnt       
 Loop
       button       PORT,0,0,Increment
       button       PORT,1,0,Decrement
       goto         Loop
       
 Increment
       incf         cnt, f
       movf         cnt, w
       movwf        PORTB
       goto         Loop
 Decrement
       decf         cnt, f
       movf         cnt, w
       movwf        PORTB
       goto         Loop
       end                         ; End of program


;********************************************Macro "pausems" ************************
 pausems MACRO arg1
       local        Loop1
       local        dechi
       local        Delay1ms
       local        Loop2
       local        End

       movlw        High(arg1)     ; Higher byte of argument is moved
                                   ; to HIcnt
       movwf        HIcnt
       movlw        Low(arg1)      ; Lower byte of argument is moved
                                   ; to LOcnt
       movwf        LOcnt
 Loop1
       movf         LOcnt, f       ; Decrements HIcnt and LOcnt while
       btfsc        STATUS, Z      ; needed and calls subroutine Delay1ms
       
       goto         dechi
       call         Delay1ms
       decf         LOcnt, f
       goto         Loop1
 dechi
       movf         HIcnt, f
       btfsc        STATUS, Z
       goto         End
       call         Delay1ms
       decf         HIcnt, f
       decf         LOcnt, f
       goto         Loop1
 Delay1ms:                          ; Delay1ms provides delay of
       movlw        .100           ; 100*10us=1ms
       movwf        LOOPcnt        ; LOOPcnt<-100
 Loop2:
       nop
       nop
       nop
       nop
       nop
       nop
       nop
       decfsz      LOOPcnt, f
       goto        Loop2           ; Execution time of Loop2
       return                      ; is 10 us
 End
       ENDM


;****************************Macro "button" ***********************************************

 button MACRO    pin,port,hilo,label
       local       Pressed1        ; All labels are local
       local       Pressed2
       local       Exit1
       local       Exit2
       
       IFNDEF      debouncedelay   ; Enables debounce time to be defined
                                   ; in main program
       #define     debouncedelay .10
       ENDIF
       
       IF (hilo == 0)              ; If pull-up used
       btfsc       port, pin       ; If "1", push-button is pressed
       goto        Exit1
       pausems     debouncedelay   ; Wait for 10ms debounce
 Pressed1
       btfss       port, pin
       goto        Pressed1
       pausems     debouncedelay   ; Wait until released and
       goto        label           ; jump to specified address
 Exit1
       ELSE                        ; If pull-down used
       btfss       port, pin
       goto        Exit2           ; If "0", push-button is released
       pausems     debouncedelay   ; Wait for 10ms debounce
 Pressed2
       btfsc       port, pin
       goto        Pressed2
       pausems     debouncedelay   ; Wait until released and
       goto        label           ; jump to specified address
 Exit2
       ENDIF
       
       END
 

stahta01

Joined Jun 9, 2011
133
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.
 

AlexR

Joined Jan 16, 2008
732
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.
Rich (BB code):
Loop
       button       0,PORTA,0,Increment
       button       1,PORTA,0,Decrement
       goto         Loop
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.
 
Top