A question for the Macro experts....


Closed Thread
Results 1 to 17 of 17

Hybrid View

  1. #1
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Good job guy. i just want to remind you something. Every time a macro is called, that duplicate his whole code. so, by using the following
    Code:
    asm
    TX_Sample macro index
    	MOVE?WW index, TXIndex
        L?CALL TXnow
    	endm
    TXnow
        ENDASM
    	TXData = TXArray[TXIndex]
    	Hserout [TXData / 100, TXData // 100]
        RETURN
    this will generate less code everytime you call the macro.

    Here's another method to send a specific index of Word array var.
    Code:
    DEFINE LOADER_USED 1
    DEFINE OSC 20
    DEFINE HSER_RCSTA 90h
    DEFINE HSER_TXSTA 24h
    DEFINE HSER_SPBRG 129 ' 9600 Bauds
    
    TXData  var WORD SYSTEM   
    aVar    var word[4] SYSTEM
    
    avar[0]=0
    avar[1]=100
    avar[2]=1000
    avar[3]=10000
    goto start
    
    asm
    Usend macro index
    	MOVE?WW aVar + (index*2) , TXData
        L?CALL TXnow
    	endm
    TXnow
        ENDASM
    	Hserout [dec TXData,13,10]
        RETURN
    start:
          @ Usend 0
          @ Usend 1
          @ Usend 2
          @ Usend 3
          pause 500
          goto start
    there's probably tons of way like using AOUT?xxx macro too.. well still unsure of that one AOUT?xxx
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Macro's can be usefull.  But, they're not always the best choice.
    Code:
    TRANSMIT:
        Temp = Sample_Array(Index)
        HSEROUT [Temp / 100, Temp // 100]
    RETURN
    
    Index = 2 : GOSUB TRANSMIT
    <br>
    DT

  3. #3
    forgie's Avatar
    forgie Guest


    Did you find this post helpful? Yes | No

    Default

    Yes, I was aware of that after reading one of your earlier posts. I am sitting slightly under 50% of my available code space (on an 18f452), and on top of that the data sending routines are used in a part of the code where speed is preferable (but not critical). To use the fastest method I would have to find out what macros HSEROUT calls, and call them directly somehow.... and the smallest code version would be something along the same lines using gosubs. Anyway if the timing becomes more important or code space is an issue then I will rewrite the macro. But for the meantime, I have improved readability by a large degree. Thanks for the ideas/wisdom guys, it's great to know that there's such a concentrated pool of knowledge in this forum to ask when I have a tough PBP question.....

  4. #4
    forgie's Avatar
    forgie Guest


    Did you find this post helpful? Yes | No

    Red face

    Also.... the macro method makes me feel like my code is more 'modular,' and more like a functional language, which makes me feel warm inside

  5. #5
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    If you want to shrink your code, the best way is to see if you can use the internal ressource instead of the PBP pre-made function.

    By example, instead of using ADCIN, write/read directly to the register, same for HSEROUT, HSERIN and how much others.

    For a simple HSEROUT
    Code:
    DEFINE LOADER_USED 1
    DEFINE OSC 20
    RCSTA =$90
    TXSTA =$24
    SPBRG= 129 ' 9600 Bauds
    
    aVar    var BYTE[7]
    a       var byte
    
    avar[0]="H"
    avar[1]="E"
    avar[2]="L"
    avar[3]="L"
    avar[4]="O"
    AVAR[5]=13
    AVAR[6]=10
    A=0
    start:
        REPEAT
            TXREG=AVAR[A]
            NotEmpty: if TXSTA.1=0 then notempty
            A=A+1
            UNTIL A=7
            A=0
            PAUSE 500  
          goto start
    compile 89 words

    Code:
    DEFINE LOADER_USED 1
    DEFINE OSC 20
    RCSTA =$90
    TXSTA =$24
    SPBRG= 129 ' 9600 Bauds
    
    aVar    var BYTE[7]
    
    avar[0]="H"
    avar[1]="E"
    avar[2]="L"
    avar[3]="L"
    avar[4]="O"
    AVAR[5]=13
    AVAR[6]=10
    
    start:
        HSEROUT[STR AVAR]
        PAUSE 500  
        goto start
    compile 103 words.

    Code:
    DEFINE LOADER_USED 1
    DEFINE OSC 20
    DEFINE HSER_RCSTA 90h
    DEFINE HSER_TXSTA 24h
    DEFINE HSER_SPBRG 129 ' 9600 Bauds
    
    aVar    var BYTE[7]
    
    avar[0]="H"
    avar[1]="E"
    avar[2]="L"
    avar[3]="L"
    avar[4]="O"
    AVAR[5]=13
    AVAR[6]=10
    
    start:
        HSEROUT[STR AVAR]
        PAUSE 500  
        goto start
    almost the same as the previous but using PBP DEFINE HSER compile 95 words

    No big improvement so far... i should find a better example next time

    BTW it's always case by case. Scroll your program and look wich statement you call the most, do a SUB with them and TADA. Just be sure to avoid too much nested gosub and it should gives you good results.

    BUT there's always a midpoint between a readable code, and a tight one. Choose your own comfort zone and work with.
    Last edited by mister_e; - 30th August 2005 at 16:59.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

Similar Threads

  1. PBPro error "Macro USBINIT? not found in macro file"
    By Bonxy in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 4th October 2011, 09:06
  2. Replies: 6
    Last Post: - 4th November 2009, 13:36
  3. Really simple question for you experts :)
    By lew247 in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 4th June 2008, 01:43
  4. Please answer my first question
    By John_001 in forum Off Topic
    Replies: 1
    Last Post: - 15th September 2006, 06:49
  5. Passing an array as a macro argument?
    By forgie in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 5th September 2005, 17:09

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts