Wrapping code


Closed Thread
Results 1 to 14 of 14

Thread: Wrapping code

  1. #1
    Join Date
    Oct 2005
    Location
    New Jersey
    Posts
    425

    Default Wrapping code

    If I have a line of code that's 150 characters long, is there a way to continue that code onto the next line so all of the code can be viewed on my screen without scrolling to the right?

  2. #2


    Did you find this post helpful? Yes | No

    Default Re: Wrapping code

    Hi there,

    yes there is...

    just use the _ to break the line.

    Check this example:

    Code:
    Lookup y, [$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,_
    $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,_
    $00,$00,$10,$08,$00,$00,$00,$00,$80,$80,$90,$00,$20,$1C,$2C,$30,_
    $18,$18,$1C,$1C,$3E,$2E,$2A,$08,$2C,$10,$18,$18,$08,$00,$00,$00,_
    $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,_
    $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,_
    $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$F0,_
    $F0,$02,$02,$04,$04,$04,$04,$00,$00,$00,$00,$00,$01,$00,$00,$00,_
    $00,$00,$00,$00,$00,$80,$80,$80,$80,$40,$40,$40,$20,$20,$10,$10,_
    $10,$08,$88,$88,$4C,$44,$C4,$A4,$02,$00,$00,$00,$FC,$8C,$C4,$00,_
    $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,_
    $00,$00,$00,$00,$00,$00,$20,$68,$68,$38,$00,$00,$00,$00,$00,$E0,_
    $20,$10,$B0,$68,$C8,$00,$00,$80,$30,$C8,$08,$00,$00,$00,$00,$00,_
    $00,$00,$00,$00,$00,$FE,$01,$11,$C1,$A8,$88,$88,$54,$D4,$00,$00,_
    $00,$00,$00,$00,$00,$00,$02,$14,$01,$0D,$0A,$6A,$10,$00,$00,$00,_
    $F7,$39,$18,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,_
    $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$4E,_
    $00,$00,$00,$03,$EE,$01,$01,$03,$01,$F3,$45,$C3,$60,$D7,$BE,$46,_
    $00,$00,$00,$00,$00,$00,$00,$00,$00,$3F,$00,$14,$2C,$8A,$4A,$56,_
    $19,$06,$00,$00,$00,$00,$00,$00,$00,$00,$00,$01,$02,$0C,$02,$00,_
    $00,$80,$00,$00,$02,$01,$03,$00,$00,$00,$00,$00,$00,$00,$00,$00,_
    $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$80,$00,_
    $80,$80,$00,$31,$00,$00,$00,$00,$FF,$00,$00,$00,$00,$DE,$39,$38,_
    $08,$6B,$FC,$32,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,_
    $00,$02,$01,$00,$00,$00,$00,$00,$00,$80,$80,$40,$40,$40,$20,$20,_
    $20,$10,$10,$18,$08,$04,$05,$01,$00,$00,$00,$00,$00,$00,$00,$00,_
    $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,_
    $00,$00,$02,$05,$06,$03,$00,$00,$08,$10,$10,$20,$20,$20,$24,$56,_
    $5C,$80,$80,$81,$83,$89,$00,$00,$00,$00,$80,$C0,$50,$48,$28,$2C,_
    $12,$12,$10,$08,$08,$08,$04,$04,$02,$02,$03,$01,$01,$00,$00,$00,_
    $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,_
    $00,$00,$00,$00,$00,$00,$00,$00] ,LcdReg
    regards
    Rui

  3. #3
    Join Date
    Oct 2004
    Posts
    440


    Did you find this post helpful? Yes | No

    Default Re: Wrapping code

    Quote Originally Posted by ruijc View Post
    Hi there,

    yes there is...

    just use the _ to break the line.

    Check this example:

    Code:
    Lookup y, [$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,_
    $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,_
    $00,$00,$10,$08,$00,$00,$00,$00,$80,$80,$90,$00,$20,$1C,$2C,$30,_
    $18,$18,$1C,$1C,$3E,$2E,$2A,$08,$2C,$10,$18,$18,$08,$00,$00,$00,_
    $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,_
    $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,_
    $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$F0,_
    $F0,$02,$02,$04,$04,$04,$04,$00,$00,$00,$00,$00,$01,$00,$00,$00,_
    $00,$00,$00,$00,$00,$80,$80,$80,$80,$40,$40,$40,$20,$20,$10,$10,_
    $10,$08,$88,$88,$4C,$44,$C4,$A4,$02,$00,$00,$00,$FC,$8C,$C4,$00,_
    $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,_
    $00,$00,$00,$00,$00,$00,$20,$68,$68,$38,$00,$00,$00,$00,$00,$E0,_
    $20,$10,$B0,$68,$C8,$00,$00,$80,$30,$C8,$08,$00,$00,$00,$00,$00,_
    $00,$00,$00,$00,$00,$FE,$01,$11,$C1,$A8,$88,$88,$54,$D4,$00,$00,_
    $00,$00,$00,$00,$00,$00,$02,$14,$01,$0D,$0A,$6A,$10,$00,$00,$00,_
    $F7,$39,$18,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,_
    $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$4E,_
    $00,$00,$00,$03,$EE,$01,$01,$03,$01,$F3,$45,$C3,$60,$D7,$BE,$46,_
    $00,$00,$00,$00,$00,$00,$00,$00,$00,$3F,$00,$14,$2C,$8A,$4A,$56,_
    $19,$06,$00,$00,$00,$00,$00,$00,$00,$00,$00,$01,$02,$0C,$02,$00,_
    $00,$80,$00,$00,$02,$01,$03,$00,$00,$00,$00,$00,$00,$00,$00,$00,_
    $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$80,$00,_
    $80,$80,$00,$31,$00,$00,$00,$00,$FF,$00,$00,$00,$00,$DE,$39,$38,_
    $08,$6B,$FC,$32,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,_
    $00,$02,$01,$00,$00,$00,$00,$00,$00,$80,$80,$40,$40,$40,$20,$20,_
    $20,$10,$10,$18,$08,$04,$05,$01,$00,$00,$00,$00,$00,$00,$00,$00,_
    $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,_
    $00,$00,$02,$05,$06,$03,$00,$00,$08,$10,$10,$20,$20,$20,$24,$56,_
    $5C,$80,$80,$81,$83,$89,$00,$00,$00,$00,$80,$C0,$50,$48,$28,$2C,_
    $12,$12,$10,$08,$08,$08,$04,$04,$02,$02,$03,$01,$01,$00,$00,$00,_
    $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,_
    $00,$00,$00,$00,$00,$00,$00,$00] ,LcdReg
    regards
    Rui
    I'm not sure that works on anything other than the example.

    Norm

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


    Did you find this post helpful? Yes | No

    Default Re: Wrapping code

    Quote Originally Posted by Normnet View Post
    I'm not sure that works on anything other than the example.

    Norm
    Maybe you could phrase that the other way around, and suggest a scenario where it doesn't work?
    DT

  5. #5
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,516


    Did you find this post helpful? Yes | No

    Default Re: Wrapping code

    I thought the maximum allowed number of constants for LOOKUP was 255, it looks to be way more than that it the list - has that changed?
    Never the less, it does show the "line continuation".

    /Henrik.

  6. #6
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,516


    Did you find this post helpful? Yes | No

    Default Re: Wrapping code

    OK, I'll do my best to clarify that myself.....
    Previously the limit was 255 or 256 but in version 2.5C the limit for PIC18 parts was increased to 1024 entities. The PBP3 manual (which of course is the correct place to look when in doubt) says 1024 for PIC18 parts while the online help in MCSP 5.0.0.3 doesn't mention that, it says 256 for 18C parts though.

    /Henrik.

  7. #7
    Join Date
    Dec 2010
    Posts
    409


    Did you find this post helpful? Yes | No

    Default Re: Wrapping code

    Quote Originally Posted by Darrel Taylor View Post
    Maybe you could phrase that the other way around, and suggest a scenario where it doesn't work?
    While the manual doesn't say a lot about how to use the line extension character, from experience you need to extend from an operator and not just anywhere in the line.
    For example:
    myvariable31 = myvariable1 + myvariable2 + myvariable3 +_
    myvariable4 + myvariable5
    should work.

    However;
    myvariable31 = myvariable1 + myvariable2 + myvar_
    iable3 + myvariable4 + myvariable5
    will not.

    It's called a line extension, but it's really statement extension to include terms and operators on the following line. You can't just jam it anywhere in the line of text and have the next line pick up exactly where the first left off.

  8. #8
    Join Date
    Oct 2004
    Posts
    440


    Did you find this post helpful? Yes | No

    Default Re: Wrapping code

    Quote Originally Posted by Darrel Taylor View Post
    Maybe you could phrase that the other way around, and suggest a scenario where it doesn't work?
    My bad. Pleased to see it works OK.

    Norm

  9. #9
    Join Date
    Oct 2005
    Location
    New Jersey
    Posts
    425


    Did you find this post helpful? Yes | No

    Default Re: Wrapping code

    Maybe you could phrase that the other way around, and suggest a scenario where it doesn't work?
    I have one.

    I can't code wrap when the characters extend past column 255 even though we're given 1024.

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


    Did you find this post helpful? Yes | No

    Default Re: Wrapping code

    Could you explain what you mean by that.
    This code which goes out to column 333 compiles just fine with PBP3.

    Code:
    I     VAR WORD
    value VAR WORD
    
    LOOKUP I, [$45,$35,$67,$7E,$45,$35,$67,$7E,$45,$35,$67,$7E,$45,$35,$67,$7E,$45,$35,$67,$7E,$45,$35,$67,$7E,$45,$35,$67,$7E,$45,$35,$67,$7E,$45,$35,$67,$7E,$45,$35,$67,$7E,$45,$35,$67,$7E,$45,$35,$67,$7E,$45,$35,$67,$7E,$45,$35,$67,$7E,$45,$35,$67,$7E,$45,$35,$67,$7E,$45,$35,$67,$7E,$45,$35,$67,$7E,$45,$35,$67,$7E,$45,$35,$67,$7E,_
    $8F,$00,$0F,$C0,_
    $EF,$55,$01,$00], value
    It wraps in the forums code box, but you should get the idea.
    DT

  11. #11
    Join Date
    Oct 2005
    Location
    New Jersey
    Posts
    425


    Did you find this post helpful? Yes | No

    Default Re: Wrapping code

    What happens when you try to compile this code?

    Code:
    HSEROUT ["iVBORw0KGgoAAAANSUhEUgAAACEAAAAkCAYAAAAHKVPcAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAArtSURBVFhHVVhpb1XXFfVfaACPb579bGYwHvBsP9vPfp6NzGDjCcJghkClpKSIUmVom1aKKqVRUtqilhZwmANUplUSNUOhqIRIQYKUqimhUMKPWF1rn3fd5MN9w7nn7",_
    "nHttfe5BQFfCXylhSgrWYIyfgf1n79DZYV2+UsWI+Avht9XjJLixQj5eb+siFehffvzv/Ws31dke7Wu/wFeYe3ht3TovtbtHuXpW3sL7AEK9Ba8Db5SGsKNft2jUd8U4hkdpkFSYJcMpqxSGi0Dy/i81oNU7CvV+hJTrHvOGN6XgVwrcMp58cay8ti3LBzMtlJA3hgKichT/tcV5jNBKvxpf9Z+",_
    "B3hfUXMRXIKgKXGetjfWIhQopTOLbe3F2RkXzXxUCmThkf07EeYmGRMOliHIkAZpYUCecnOYys/um8KpTAPme1pweO1yRIsW4RdVK/GnjhacymUQ4f+/",_
    "PjeO8z2NmG9bjxNtDWaY5CmFumSAIqNIRLgeDpaafEaCG2lAeSyE8kTYLD5MS20tGbHNIVp8elMvHk0P4el4H25PDuBMWx2ut9fjK659NDOKBPFyqa0WD2cG8HhzD66PdOP1nZNmRJqyo6EyRlnKS1FBueXxsMmW4wWyyuW7GCEuet4LYHYpBQzjq001+HQgi/sbe3FxpBMJGn+hdT1uTg/",_
    "XibVX6mVPtMoHvzotJcMCrfzp2Bbp97K+POKB7WvEOxPa9oc9//AEEBNtPX0IZcAAAAAElFTkSuQmCC",34,"/>"]

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


    Did you find this post helpful? Yes | No

    Default Re: Wrapping code

    Compiling that code ... generates a "FATAL ERROR: Internal: Locate could not find nCmd = 32174784"

    But it has nothing to do with "Line Continuation" and the "_" underscore.
    There are simply too many characters in the HSEROUT command.

    If you break that into 2 HSEROUT statements, it compiles fine ...
    Code:
    HSEROUT ["iVBORw0KGgoAAAANSUhEUgAAACEAAAAkCAYAAAAHKVPcAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAArtSURBVFhHVVhpb1XXFfVfaACPb579bGYwHvBsP9vPfp6NzGDjCcJghkClpKSIUmVom1aKKqVRUtqilhZwmANUplUSNUOhqIRIQYKUqimhUMKPWF1rn3fd5MN9w7nn7",_
    "nHttfe5BQFfCXylhSgrWYIyfgf1n79DZYV2+UsWI+Avht9XjJLixQj5eb+siFehffvzv/Ws31dke7Wu/wFeYe3ht3TovtbtHuXpW3sL7AEK9Ba8Db5SGsKNft2jUd8U4hkdpkFSYJcMpqxSGi0Dy/i81oNU7CvV+hJTrHvOGN6XgVwrcMp58cay8ti3LBzMtlJA3hgKichT/tcV5jNBKvxpf9Z+",_
    "B3hfUXMRXIKgKXGetjfWIhQopTOLbe3F2RkXzXxUCmThkf07EeYm"]
    
    HSEROUT ["GRMOliHIkAZpYUCecnOYys/um8KpTAPme1pweO1yRIsW4RdVK/GnjhacymUQ4f+/",_
    "PjeO8z2NmG9bjxNtDWaY5CmFumSAIqNIRLgeDpaafEaCG2lAeSyE8kTYLD5MS20tGbHNIVp8elMvHk0P4el4H25PDuBMWx2ut9fjK659NDOKBPFyqa0WD2cG8HhzD66PdOP1nZNmRJqyo6EyRlnKS1FBueXxsMmW4wWyyuW7GCEuet4LYHYpBQzjq001+HQgi/sbe3FxpBMJGn+hdT1uTg/",_
    "XibVX6mVPtMoHvzotJcMCrfzp2Bbp97K+POKB7WvEOxPa9oc9//AEEBNtPX0IZcAAAAAElFTkSuQmCC",34,"/>"]
    If you add a single character to the first HSEROUT ... it will fail.
    Because there are already 512 characters. Apparently, the maximum it can handle.
    DT

  13. #13
    Join Date
    Oct 2005
    Location
    New Jersey
    Posts
    425


    Did you find this post helpful? Yes | No

    Default Re: Wrapping code

    If you break that into 2 HSEROUT statements, it compiles fine ...
    I know. That's what I've been doing but now it's becoming a problem because there are so many HSEROUT statements. A 2kB image takes up 17kB of code space. Is there a better way to send an image that doesn't take up so much code space with HSEROUT statements?

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


    Did you find this post helpful? Yes | No

    Default Re: Wrapping code

    Quote Originally Posted by Christopher4187 View Post
    I know.
    Really!

    ... it's becoming a problem because there are so many HSEROUT statements.
    You could have an HSEROUT statement for every character, and it wouldn't use a single word more than putting everything in a single HSEROUT.
    That's just the way HSEROUT works.
    It calls a macro for each character, it doesn't matter which HSEROUT statement calls the macro.

    A 2kB image takes up 17kB of code space. Is there a better way to send an image that doesn't take up so much code space with HSEROUT statements?
    Store it in FLASH ... a 2kB image will use 2kB (on 18Fs).
    Read it back with READCODE.
    DT

Similar Threads

  1. Working code but my layman approach uses too much code space
    By Christopher4187 in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 14th December 2012, 21:44
  2. Code: Why is this code greater than 2000 words?
    By DrDreas in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 1st June 2007, 20:51

Members who have read this thread : 1

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