print macro


+ Reply to Thread
Results 1 to 7 of 7

Thread: print macro2523 days old

  1. #1
    Member Jezsmith's Avatar
    Join Date
    Sep 2004
    Posts
    211
    Thumbs Up
    Received: 7
    Given: 2
    Total Downloaded
    930.95 MB

    0 Not allowed!

    Default print macro

    hi,
    I have been using the dog160x104 lcd with a uc1610 controller for some time now. My issue is, as my programs get more complicated and long, the print routines I made clutter the code up something chronic. I think I am at the point I need to look at a suite of print command macro' s to keep thing readable. I have managed to do the drawing of lines and boxes so I can print a box or line with simple commands of e.g. drawbox(xs,ys,xf,yf) (see code) . The only problem with my draw box is that it must start on a lcd page rather than any line, which I can live with at the mo. However I have hit a wall on a text printing macro.

    Currently every time I want to print a text string or number, I have to do it as below rather than a simple command like (print at 18,130, dec Trk_Num). after a 1000's of lines of code most of it is made up of my long printing stuff.

    page_size = 1 'sets ffont size
    page_index = 114 'sets lcd page 1-26
    Lcd_column = 130 'set lcd column 1-160
    Str LcdStr= Str$(Dec TRK_Num ) 'loads null terminated byte array with string to print
    GoSub Lcd_SentString goes to dog_lcd macro to put it on the screen

    any pointers would be greatfuly received
    Jez

    Code:
     
     '*******************box vars*****************************   Dim x_start As Byte
       Dim x_finish As Byte
       Dim y_start As Byte
       Dim y_finish As Byte 
       '********************************************************** 
    
    
       GoTo over_macros
    
    
    
    
    drawbox Macro  P1, P2, P3, P4
    #if (Prm_Count > 4)
        #error "drawbox - Too many parameters"
    #else
        #if (Prm_Count < 4)
            #error "drawbox - Too few parameters"
        #else
            #if(Prm_1 != Byte) && (Prm_1 != Num8) && (Prm_1 != Num16) && (Prm_1 != Num32)
                #error "drawbox - y_start(Param1) Should be a Byte variable or number"
            #endif
            #if(Prm_2 != Byte) && (Prm_2 != Num8) && (Prm_2 != Num16) && (Prm_2 != Num32)
                #error "drawbox - y_finish(Param2) Should be a Byte variable or number"
            #endif
            #if(Prm_3 != Byte) && (Prm_3 != Num8) && (Prm_3 != Num16) && (Prm_3 != Num32)
                #error "drawbox - x_start(Param3) Should be a Byte variable or number"
            #endif
            #if(Prm_4 != Byte) && (Prm_4 != Num8) && (Prm_4 != Num16) && (Prm_4 != Num32)
                #error "drawbox - x_finish(Param4) Should be a Byte variable or number"
            #endif
            #if (Prm_1 == Byte)
                Byte_Byte P1, y_start
            #endif
            #if (Prm_1 == Num8)
                Num_Byte P1, y_start
            #endif
            #if (Prm_1 == Num16)
                Num_Byte P1, y_start
            #endif
            #if (Prm_1 == Num32)
                Num_Byte P1, y_start
            #endif
            #if (Prm_2 == Byte)
                Byte_Byte P2, y_finish
            #endif
            #if (Prm_2 == Num8)
                Num_Byte P2, y_finish
            #endif
            #if (Prm_2 == Num16)
                Num_Byte P2, y_finish
            #endif
            #if (Prm_2 == Num32)
                Num_Byte P2, y_finish
            #endif
            #if (Prm_3 == Byte)
                Byte_Byte P3, x_start
            #endif
            #if (Prm_3 == Num8)
                Num_Byte P3, x_start
            #endif
            #if (Prm_3 == Num16)
                Num_Byte P3, x_start
            #endif
            #if (Prm_3 == Num32)
                Num_Byte P3, x_start
            #endif
            #if (Prm_4 == Byte)
                Byte_Byte P4, x_finish
            #endif
            #if (Prm_4 == Num8)
                Num_Byte P4, x_finish
            #endif
            #if (Prm_4 == Num16)
                Num_Byte P4, x_finish
            #endif
            #if (Prm_4 == Num32)
                Num_Byte P4, x_finish
            #endif
            GoSub drawABox
        #endif
    #endif
    Endm
    
    
    drawABox:
    
    
    
    
    '*****************DRAWS TOP BOARDER LINE**********************
    DataByte = $03
    Page_Row = y_start
    xpos_start = x_start
    xpos_end = x_finish
    GoSub lcd_xy
    
    
    '****************DRAWS BOTTOM BOARDER LINE********************
    DataByte = $C0       ' pixel to set black
    Page_Row = y_finish   ' page row line           100
    xpos_start = x_start ' column starting point   95
    xpos_end = x_finish  ' column finsh point      155
    GoSub lcd_xy         ' draws the line
    
    
    '***************DRAWS LEFT BOARDER LINE***********************
    DataByte = $FF
    xpos_start = x_start
    xpos_end = x_start
    For Page_Row = y_start To y_finish
    GoSub lcd_xy
    Next
    '**************DRAWS RIGHT BOARDER LINE***********************
    DataByte = $FF
    xpos_start = x_finish
    xpos_end = x_finish
    For Page_Row = y_start To y_finish
    GoSub lcd_xy
    Next
    Return
    
    
    
    
    over_macros:
    Last edited by Jezsmith; 28th June 2013 at 18:55. Reason: better readability

  2. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  3. #2
    Fanatical Contributor Tim's Avatar
    Join Date
    Jan 2003
    Posts
    7,748
    Thumbs Up
    Received: 51
    Given: 96
    Total Downloaded
    1.32 GB

    0 Not allowed!

    Default Re: print macro

    I would not use macro's they were needed before Les implemented the pre-processor.

    I would also consider using cdata to hold your message. That way you can manage them with out having to search through loads of code looking for the strings.

    If you need help just ask
    Tim

  4. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  5. #3
    Member Jezsmith's Avatar
    Join Date
    Sep 2004
    Posts
    211
    Thumbs Up
    Received: 7
    Given: 2
    Total Downloaded
    930.95 MB

    0 Not allowed!

    Default Re: print macro

    Tim,
    I will have to a bit reading to grasp the preprocessor. Am I right in thinking its a way of writing a function to perform a task? looking at the help pdf. The print function would have to print variables not fixed string necessarily, ie A derived altitude from a 'calc_alt' function which is updated frequently.

    To do this at the moment, I set the following lcd x,y variables in code and send the dynamic Str_ LcdStr variable to the lcd code below which does the magic stuff.

    page_size = 1 'sets font size
    page_index = 114 'sets lcd page 1-26
    Lcd_column = 130 'set lcd column 1-160
    Str_LcdStr= Str$(Dec Altitude ) 'loads null terminated byte array with string to print
    GoSub Lcd_SentString 'goes to dog_lcd macro to put it on the screen

    Its just how an i get the above 5 lines of code into a single line instruction?
    regards
    jez

    SendBytes:


    If page_size = 3 Then GoSub LARGE_FONT ' 0-3 = 4 x four pixels = 4 page font
    If page_size = 1 Then GoSub Small_Font '0-1 = Normal 2 x four pixel = 2 page font


    For NibPos = 0 To page_size 'Font Page Size 2 Pages

    GoSub lcd_gotoxy 'Goto the x,y pos on screen
    '************************************************* ****************************** High CD 'Prepare to send data
    Low CS
    SHOut DTA,CLK, MsbFirst, [RowData[NibPos]]
    High CS
    Next NibPos
    Lcd_column = Lcd_column + 1 'advances each data byte one column
    Return


    '******************************SEND Big Font COLUMN BYTES TO LCD *******************************
    SendBytesBig:
    NibPos = 0 'stops page auto icrementing
    GoSub lcd_gotoxy 'Goto the x,y pos on screen
    High CD 'Prepare to send data
    Low CS
    SHOut DTA,CLK, LsbFirst, [DataByte] ' shouts the data to LCD
    High CS
    Lcd_column = Lcd_column + 1 'advances one column ready for next byte
    Return




    '**************************** GOTO X (Column),Y (Page) Pos on LCD **************
    ' Two 8bit commands are req for col bit shifting ensures MSB and LSB are joined
    '************************************************* ******************************
    lcd_gotoxy:
    LCD_Row = page_index + NibPos ' selects the row and one below it

    Col_MSB = Lcd_column >>4 'shift data in MSB 4 places to right
    Col_LSB = Lcd_column <<4
    Col_LSB = Col_LSB >>4
    Col_MSB = Col_MSB + 16 'need to add 16 as D4 is always 16
    Low CD 'pepare LCD for Command
    Low CS
    SHOut DTA,CLK,MsbFirst,[LCD_Row] ' selects the row and one below it
    High CS
    Low CS
    SHOut DTA,CLK, MsbFirst, [Col_LSB,Col_MSB] 'page addis 100 col=9=(9=lsb+16=msb)
    High CS
    High CD
    Return
    '************************************************* ******************************
    '************************************************* ******************************


    '===================================LCD SUBROUTINE=============================
    Lcd_SentChar:
    j=DataByte * 6 ' Does this increment through car cread line ??
    For i=0 To 5 ' Five bytes in the character
    DataByte=CRead Font+j+i ' Think its incrementing through cread table
    GoSub SendBytes ' Goto send byte routine
    LCD_Row = LCD_Row - 1 ' prevent inc row for each charachter byte sent
    Next
    Return
    '************************************************* ******************************
    Lcd_SentString:
    For k=0 To 26 ' Sets the max string lengh to equall LCD width
    DataByte=LcdStr[k] ' Loads char into string
    If DataByte=0 Then Break ' Stops at end
    GoSub Lcd_SentChar ' Sends char in turn to cread byte send routine
    Next
    Return
    '************************************************* ******************************

  6. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  7. #4
    Fanatical Contributor Tim's Avatar
    Join Date
    Jan 2003
    Posts
    7,748
    Thumbs Up
    Received: 51
    Given: 96
    Total Downloaded
    1.32 GB

    0 Not allowed!

    Default Re: print macro

    Hi

    This is a simple conversion of the multi statement example you gave

    Code:
    $define Print_2 (PPageSize, PPageIndex, PLcdColumn, PStrLcdStr) '    
        page_size = PPageSize '    
        page_index = PPageIndex '     
        Lcd_column = PLcdColumn '
        Str_LcdStr = PStrLcdStr '
        GoSub Lcd_SentString
    This would be it in use

    Print_2 (1, 114, 130, Str$(Dec Altitude )

    However when you compile it, the pre processor crashes

    So for now here is a slightly longer way of doing it

    Code:
        $define Print_2 (PPageSize, PPageIndex, PLcdColumn) '
        page_size = PPageSize '
        page_index = PPageIndex '
        Lcd_column = PLcdColumn '
        GoSub Lcd_SentString
        
    
    
        Str_LcdStr= Str$(Dec Altitude )
        Print_2 (1, 114, 130)

    I will see if I can make it work some other way
    Tim

  8. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  9. #5
    Fanatical Contributor Tim's Avatar
    Join Date
    Jan 2003
    Posts
    7,748
    Thumbs Up
    Received: 51
    Given: 96
    Total Downloaded
    1.32 GB

    2 Not allowed!

    Default Re: print macro

    OK found a fix!

    Ensure you have the right number of brackets

    Code:
        $define Print_2 (PPageSize, PPageIndex, PLcdColumn, PStrLcdStr) '    
        page_size = PPageSize '
        page_index = PPageIndex '
        Lcd_column = PLcdColumn '
        Str_LcdStr = PStrLcdStr '
        GoSub Lcd_SentString
        
    
    
        Print_2 (1, 114, 130, Str$(Dec Altitude ))
    Tim

  10. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  11. #6
    Member Jezsmith's Avatar
    Join Date
    Sep 2004
    Posts
    211
    Thumbs Up
    Received: 7
    Given: 2
    Total Downloaded
    930.95 MB

    0 Not allowed!

    Default Re: print macro

    Thankyou Tim,
    The pre-processor stuff appears more straight forward than I anticipated and tidies things up a treat.
    Much appreciated for your help.
    regards
    jez

  12. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  13. #7
    Fanatical Contributor Tim's Avatar
    Join Date
    Jan 2003
    Posts
    7,748
    Thumbs Up
    Received: 51
    Given: 96
    Total Downloaded
    1.32 GB

    0 Not allowed!

    Default Re: print macro

    Main thing to remember is the ' line continuation marker

    But not on the last line
    Tim

  14. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Similar Threads

  1. Macro?
    By towlerg in forum Proton Plus Compiler v3
    Replies: 0
    Last Post: 28th March 2018, 18:54
  2. Macro help please
    By towlerg in forum Proton Plus Compiler v3
    Replies: 4
    Last Post: 10th February 2018, 16:52
  3. Cannot place a user defined macro within a user defined macro?!?
    By DmitriK in forum Proton Plus Compiler v3
    Replies: 10
    Last Post: 19th August 2011, 02:24
  4. Macro calling another macro inside a library
    By pdgnr in forum Library Manager
    Replies: 2
    Last Post: 27th March 2008, 07:20
  5. [SOLVED !] Macro
    By gurolkalayci in forum Proton Plus Compiler v3
    Replies: 7
    Last Post: 26th March 2006, 17:41

Tags for this Thread

Posting Permissions

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