Minimizing code....


Closed Thread
Results 1 to 7 of 7
  1. #1
    Join Date
    Feb 2009
    Posts
    41

    Default Minimizing code....

    My project uses non-standard hardware (a microwire port expander) so I could not use the LCDout function. I did manage to get my LCD working however with the following code.

    gosub LCD_HOME 'clear the LCD and set the cursor to 00

    For y=0 To 64
    Gosub modescreen1b 'software version

    OUT_BITS = ascii

    gosub ioxwriteb
    Pause 1
    gosub LCD_DATA_EN 'send the "Software Version" message

    Next y

    initscreenb:
    Lookup y,["Software Ver: DL1.00A "],ascii
    Return


    It works well, but I don't want to copy this block for ever screen I need to print. It would be a huge waste of code. I can't figure out how to minimize the code to just pass the menu to lookup to a sub.

    All comments greatly appreciated!

    Thanks,
    TR
    Last edited by TerdRatchett; - 11th February 2009 at 18:34. Reason: Accidently screwed up...

  2. #2
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Maybe I am missing something...

    Code:
    'Write to the Display
    GOSUB LCD_THINGY
    'Do Whatever
    'Write to the Display again
    GOSUB LCD_THINGY
    'Do Whatever again.....
    
    LCD_THINGY:
    gosub LCD_HOME 'clear the LCD and set the cursor to 00
    For y=0 To 64
    Gosub modescreen1b 'software version
    OUT_BITS = ascii
    gosub ioxwriteb
    Pause 1
    gosub LCD_DATA_EN 'send the "Software Version" message
    Next y
    initscreenb:
    Lookup y,["Software Ver: DL1.00A "],ascii
    Return
    Is something like that what you had in mind?
    Dave
    Always wear safety glasses while programming.

  3. #3
    Join Date
    Feb 2009
    Posts
    41


    Did you find this post helpful? Yes | No

    Default similar to this psuedocode....

    ' print message a
    GOSUB LCD_THINGY(messagea)

    ' print message a
    GOSUB LCD_THINGY(messageb)

    etc...

    messagea:
    Lookup y,["Message A"],ascii
    Return

    messageb:
    Lookup y,["Message B"],ascii
    Return


    Can you pass an argument to a sub like in Visual Basic?

  4. #4
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    No, but this might work for you..
    Code:
    ' print message a
    GOSUB messagea
    
    ' print messageb
    GOSUB messageb
    
    etc...
    
    messagea:
    Lookup y,["Message A"],ascii
    GOSUB LCD_THINGY
    Return
    
    messageb:
    Lookup y,["Message B"],ascii
    GOSUB LCD_THINGY
    Return
    Dave
    Always wear safety glasses while programming.

  5. #5
    Join Date
    Feb 2009
    Posts
    41


    Did you find this post helpful? Yes | No

    Default

    Hi Dave,

    Thanks again for your help.

    I have considered your idea but I can't figure out how to implement it because the GOSUB LCD_THINGY routine makes 64 lookups of the table in question.

    TR

  6. #6
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Might be a good time to post your code as it is right now, I am sure there is something I am missing.
    From the manual :
    An unlimited number of subroutines may be used in a program. Subroutines may also be nested. In other words, it is possible for a subroutine to call another subroutine. Such subroutine nesting should be restricted to no more than four levels deep (12 levels for 17Cxxx and 27 levels for 18Cxxx)
    So as long as the look up table block does not call a sub of a sub then you shoulde OK with 64 GOSUBS to the lookup block and back.
    Dave
    Always wear safety glasses while programming.

  7. #7
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    948


    Did you find this post helpful? Yes | No

    Default

    Hi Terd

    This is how I do it when I have a number of messages to either print or put out to a 7 segment display.

    Code:
    ' Thank DT for this Macro
    ASM
    GetAddress macro Label, Wout       ; Returns the Address of a Label as a Word
        CHK?RP Wout
        movlw low Label
        movwf Wout
        movlw High Label
        movwf Wout + 1
        endm
    ENDASM
    Address         var     word
    gr[0]             var     byte
    
    ' Examples of how to put your strings in memory
    prn_SetDate:       PokeCode "Date changed",0
    prn_SetTime:       PokeCode "Time changed",0
    prn_LogPrinted:    PokeCode "Log printed",0
    
    ' And this is how to use it
      @ GetAddress _prn_SetDate, _Address
      gosub Prt_puts   ' This is my routine to put the string to Printer.  
                             ' You could change this to your LCDout routine.
      return
    
    ' And this is My Prt_puts function
    ' Print an ASCIIZ string
    ' Input - Address points to the string
    Prt_puts:
      repeat
        peekcode Address, gr[0]             ' read a byte to GR[0] (general register 0)
        if gr[0] then                             ' if end of message (0) not found, 
          gosub Prt_putc                       ' print this character
          Address = Address+1               ' advance to the next position of input string
        endif
      until gr[0]=0                              ' go back if the message end is found
      return
    This is not adapted to your requirement, but, I think you can do that yourself.

Similar Threads

  1. Minimizing code space
    By Tobias in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 30th May 2009, 07:25
  2. Reading in Manchester code
    By brid0030 in forum Code Examples
    Replies: 0
    Last Post: - 10th March 2009, 21:55
  3. How much code space do PBP statements use.
    By Darrel Taylor in forum Code Examples
    Replies: 5
    Last Post: - 13th February 2009, 21:31
  4. Loop with two motor and 2 sensors
    By MrRoboto in forum mel PIC BASIC
    Replies: 4
    Last Post: - 8th December 2008, 23:40
  5. Making Program Code Space your playground...
    By Melanie in forum Code Examples
    Replies: 15
    Last Post: - 19th July 2008, 08:26

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