Announcement

Collapse
No announcement yet.

user command with multiple input parameters

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • user command with multiple input parameters

    some years ago I asked dt how this is done his answer :-
    Yes, you can pass more than 1 parameter.
    For each additional parameter, another letter is added to the macro name.

    If you used this line in your program ...
    CRCC MyArray, 10

    It would call the CRCC?BC macro.

    I'm not sure what you mean by "Optional Parameters".
    If a macro exists for the number of parameters used, it will call that macro.
    So you can have commands that can accept any number of parameters, it just gets very complicated with too many of them.

    A command with 1 parameter takes 7 macros, 1 for each type.
    A command with 2 parameters takes 7*7=49 macros.
    3 parameters ... 7*7*7=343 macros.
    but I never really followed up and got it working I hoping now its not too late and somebody can explain this for me

    I want a command line " glcd x,y,chr " where x and y are constants and chr is a byte at least to start with x,y being bytes or constants would be good

    relevant macro is this for x

    Code:
    GLCDC?C  macro Cin
         movlw    Cin
        CHK?RP    _x    
        MOVWF     _x
      ??  does this macro need to call GLCDC?CC  ?
            endm
    accordingly the next macro is

    Code:
     GLCDC?CC  macro   ?? what goes here     Cin   fails CCin fails too
         movlw     ??             what goes here     Cin   fails
        CHK?RP    _y    
        MOVWF     _y
            endm
    I'm totally lost can't get anywhere near the third parameter

  • #2
    Richard,

    Maybe this will help.
    This is a simple Usercommand that takes (2) constants as inputs and them stores them into (2) pre-defined byte variables.
    Just to simply show the parameters in the macro and how to pass them.

    This shows only 1 of the "7" macros which is just to support 2 constant parameters.

    Hope this helps.

    Code:
    '****************************************************************
    '*  Name    : LOADME  .BAS                                      *
    '*  Author  : TABSoft                                           *
    '*  Notice  :                                                   *
    '*          :                                                   *
    '*  Date    : 6/13/2015                                         *
    '*  Version : 1.0                                               *
    '*  Notes   :                                                   *
    '*          :                                                   *
    '****************************************************************
    ;----[16F887 Hardware Configuration]--------------------------------------------
    #IF __PROCESSOR__ = "16F887"
      #DEFINE MCU_FOUND 1
    #CONFIG
    cfg1 = _EC_OSC                ; XT oscillator: Crystal/resonator on RA6/OSC2/CLKOUT and RA7/OSC1/CLKIN
    cfg1&= _WDT_OFF               ; WDT disabled and can be enabled by SWDTEN bit of the WDTCON register
    cfg1&= _PWRTE_OFF             ; PWRT disabled
    cfg1&= _MCLRE_ON              ; RE3/MCLR pin function is MCLR
    cfg1&= _CP_OFF                ; Program memory code protection is disabled
    cfg1&= _CPD_OFF               ; Data memory code protection is disabled
    cfg1&= _BOR_ON                ; BOR enabled
    cfg1&= _IESO_ON               ; Internal/External Switchover mode is enabled
    cfg1&= _FCMEN_ON              ; Fail-Safe Clock Monitor is enabled
    cfg1&= _LVP_OFF               ; RB3 pin has digital I/O, HV on MCLR must be used for programming
    cfg1&= _DEBUG_OFF             ; In-Circuit Debugger disabled, RB6/ICSPCLK and RB7/ICSPDAT are general purpose I/O pins
      __CONFIG _CONFIG1, cfg1
    
    cfg2 = _BOR40V                ; Brown-out Reset set to 4.0V
    cfg2&= _WRT_OFF               ; Write protection off
      __CONFIG _CONFIG2, cfg2
    
    #ENDCONFIG
    
    #ENDIF
    
    ;----[Verify Configs have been specified for Selected Processor]----------------
    ;       Note: Only include this routine once, after all #CONFIG blocks
    #IFNDEF MCU_FOUND
      #ERROR "No CONFIGs found for [" + __PROCESSOR__ +"]"
    #ENDIF
    
    DEFINE  OSC 20
    
    '*****16F887 Settings*****
    OSCCON     = %01110000	'<6:4> 111=8Mhz, 110=4Mhz, 101=2Mhz, 100=1Mhz, ClkSrc = CONFIG1
    OPTION_REG = %01000000  'RBPU=En, INTEDG=Rising, T0CS=Fosc/4, T0SE=Low2High, PSA=Timer0, PS=1:2
    ANSEL      = %00000000  ' All Digital
    CM1CON0    = %00000000  ' Disable Cmp 1
    CM2CON0    = %00000000  ' Disable Cmp 2
    
    ;----[Change these to match your hardware]----------------------------------
    '*****Define LCD registers and bits*****
    DEFINE LCD_BITS      4
    define LCD_LINES     2
    Define LCD_DREG      PORTD
    Define LCD_DBIT      4
    Define LCD_RSREG     PORTE
    Define LCD_RSBIT     0
    Define LCD_EREG      PORTE
    Define LCD_EBIT      1
    define LCD_RWREG     PORTE
    define LCD_RWBIT     2
    define LCD_COMMANDUS 1500
    define LCD_DATAUS    44
    
    xByte var byte
    yByte var byte
    
    goto Over_MyCommand
    USERCOMMAND "LOADME"
    
    asm
    ;----[Constant]-------------------------------------------------------------
    LOADME?CC macro Xin,Yin
            movlw   Xin
            CHK?RP  _xByte
            movwf   _xByte
            movlw   Yin
            CHK?RP  _yByte
            movwf   _yByte
            endm
    endasm
    
    Over_MyCommand:
    
    LCDrw VAR PORTE.2
    
    main:
        'Preload random values in xByte & yByte
        xByte = $FF
        yByte = $FF
        
        LCDOUT $FE,1
        LCDOUT $FE, $80, "BEFORE"
        LCDOUT $FE, $C0, "x:", ihex2 xByte, " y:", ihex2 yByte
        
        pause 2000
       
       ' Load the new values into xByte and yByte via the USERCOMMAND
        LOADME $45, $63
        
        LCDOUT $FE,1
        LCDOUT $FE, $80, "AFTER"
        LCDOUT $FE, $C0, "x:", ihex2 xByte, " y:", ihex2 yByte
        
        pause 2000
        
        goto main
        
        
    end

    Comment


    • #3
      thanks tabsoft , works like a dream

      Comment


      • #4
        Originally posted by richard View Post
        thanks tabsoft , works like a dream
        Glad it helped.
        What Darrel was referring to in his statements about the number of macros is 7 for each parameter comes from the fact that you need a USERCOMMAND to be able to accept or reject each type of input possible for each parameter.
        1. Byte
        2. Word
        3. Long
        4. Constant
        5. String
        6. Label
        7. Bit

        So for each USERCOMMAND we need to create a macro for every combination of possible parameter types for each parameter.

        Code:
        MyCommand?BBB macro Xin, Yin, Zin  ; all Params Byte
            Yada
            Yada
            Yada
          endm
        
        MyCommand?WWW macro Xin, Yin, Zin  ; all Params Word
            Yada
            Yada
            Yama
          endm
        
        MyCommand?LLL macro Xin, Yin, Zin  ; all Params Long
            Yada
            Yada
            Yada
          endm
        
        MyCommand?WBB macro Xin, Yin, Zin  ; 1st Param Word, 2nd & 3rd Param Byte
            Yada
            Yada
            Yada
          endm
        
        .........
        
        MyCommand?CLC macro Xin, Yin, Zin  ; 1st Param Constant, 2nd Param Long, 3rd Param Constant
            Yada
            Yada
            Yada
          endm
        
        Etc, etc, etc
        So 3 parameters requires 343 macros for the USERCOMMAND.

        Here is the link to the USERCOMMAND over ire if you don't have it.
        http://support.melabs.com/threads/89...ht=USERCOMMAND

        Hope this helps.

        Comment


        • #5
          don't suppose you know what the String macro does ?
          I can't find any docs or examples anywhere for user command other than this and the link you attached

          Comment


          • #6
            Originally posted by richard View Post
            don't suppose you know what the String macro does ?
            I can't find any docs or examples anywhere for user command other than this and the link you attached
            Yeah, there are no docs I have ever found.

            The string is just a parameter.
            The macro that handles the String type parameter and it's functionality is up to the user.
            One place to look at examples of using string parameters would be to look at the libraries in the PBP3 directory.
            PBPPIC14.lib
            PBPPIC18.lib

            Comment


            • #7
              I realise The string is just a parameter, I assume its the start address label of a null terminated string but a search for ?S in the piclib files has no hits at all

              Comment


              • #8
                looks like its only for constant Strings , a byte array calls the same macro as a byte var

                Comment


                • #9
                  About what I thought.
                  The String parameter type will allow you to pass an ASCII string in quotes to the command.

                  No String variable type support in PBP.
                  Not even under the covers.

                  Comment


                  • #10
                    to complete the story , usercmd strings work like this , with one limitation the string needs to be at least 2 chrs else it's treated as a constant (even with quotes)

                    thanks go to pedja089 who worked this out

                    Code:
                    usrcmd?S  macro Cin    ; local TheString, OverStr ; define local labels so you can call macro multiple times
                     goto OverStr ; goto over string stored in FLASH, so processor can't execute that
                    TheString ;label to get address of your string
                     data Cin, 0 ;add string to flash at TheString address and end string with 0
                    OverStr
                     MOVE?CW TheString, _the_str_Addr ;move addres of string to word variable, don't know how it would work with device that have more than 65535K of FLASH???
                     L?CALL _your_code
                     endm

                    Comment

                    Working...
                    X