A question for the Macro experts....


Closed Thread
Results 1 to 17 of 17

Hybrid View

  1. #1
    forgie's Avatar
    forgie Guest

    Default A question for the Macro experts....

    Hi there.
    On my current project I am sending data out to my PC by using HSEROUT. I am sending data from a 12-bit ADC, so to transmit it I use:
    <code>
    HSEROUT [Data / 100, Data // 100]
    </code>

    I use this method so that I can reserve numbers above 100 for communication messages. I'm wondering if it is possible to write a macro that does the above that I could use like this:
    <code>
    @ TRANSMIT _Data
    </code>

    Any tips from the masters would be much appreciated. (I have written a few simple macros, some fully asm, some a mix of asm and PBP, but I could never work out how to use an argument with a macro and then use that argument with a PBP command inside the macro)

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


    Did you find this post helpful? Yes | No

    Default

    Hi forgie,

    Give this a try...
    Code:
    Data  VAR  WORD
    Temp  VAR  WORD
    
    @TRANSMIT  macro Variable
    @   MOVE?WW  Variable, _Temp    
        HSEROUT [Temp / 100, Temp // 100]
    @ endm
    
    @ TRANSMIT _Data
    DT

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


    Did you find this post helpful? Yes | No

    Default

    OR, this one will use less Code Space on each use of the TRANSMIT macro.
    Code:
    Data  VAR  WORD
    Temp  VAR  WORD
    
    TX_Code:
        HSEROUT [Temp / 100, Temp // 100]
    RETURN
    
    ASM
    TRANSMIT  macro Variable
        MOVE?WW  Variable, _Temp    
        L?CALL   _TX_Code
      endm
    ENDASM
    
    @ TRANSMIT _Data
    DT

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


    Did you find this post helpful? Yes | No

    Default

    Sorry, i'm not an expert but you could try something like
    Code:
    DEFINE OSC 20
    
    DEFINE HSER_RCSTA 90h
    DEFINE HSER_TXSTA 24h
    DEFINE HSER_SPBRG 129 ' 9600 Bauds
    
    wData   var word SYSTEM
    ADCData var word SYSTEM
    xyzData var word SYSTEM
    
    GOTO START
    
    ASM
    TRANSMIT macro ToSend
             MOVE?WW ToSend, wData
             L?CALL UTransmit
             endm
    
    UTransmit 
             endasm  
             HSEROUT [wdata / 100, wdata // 100]
             return
    
    START:
          adcdata=1024
          @ TRANSMIT ADCData
          xyzdata = 500
          @ TRANSMIT xyzData
          
          PAUSE 500
          GOTO START
    Steve

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

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


    Did you find this post helpful? Yes | No

    Default

    OUPS!!! didn't see ya Darrel... Sorry.

    mm it looks quite the same BTW... i still learn
    Steve

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

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


    Did you find this post helpful? Yes | No

    Default

    No Problem,

    That's what happens when both our brains are grinding at the same time.

    It also gives forgie some confirmation that they will probably work, since 2 people came up with almost the same thing independantly.


    <br>
    DT

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


    Did you find this post helpful? Yes | No

    Default

    Hehe, i agree.

    Just a question. Is there any possible problem by using
    Code:
    wData   var word SYSTEM
    against
    Code:
    wData   var word
    Steve

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

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


    Did you find this post helpful? Yes | No

    Default

    Well, can't say for sure, but I've never had any problems with SYSTEM.

    PBP tries to protect against duplicate variable names by adding an underscore "_" in front of everything that's specified by the user.

    The only thing that "SYSTEM" does, is prevent that underscore from being added.

    It could cause a Naming Conflict with other things being used at the ASM level, but when that happens, the compiler will let you know.

    It does make things look nicer without all those _'s. &nbsp;&nbsp;But then, those _'s can make it easier to differentiate between what's PBP and what's ASM variables, when it's debugging time.

    It's hard to say which way is better.
    <br>
    Last edited by Darrel Taylor; - 29th August 2005 at 07:01.
    DT

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