How to use the preprocessor to change LCD port declares


+ Reply to Thread
Results 1 to 11 of 11
  1. #1
    Prolific Poster See_Mos's Avatar
    Join Date
    Feb 2004
    Posts
    1,285
    Thumbs Up
    Received: 17
    Given: 0
    Total Downloaded
    872.27 MB

    0 Not allowed!

    Default How to use the preprocessor to change LCD port declares

    Help please. I thought I had done this some time ago but today I cannot make it work.

    Basically I have an 18F25K22 developement board where I can unplug the LCD and buttons and move them from one port to another. I use an INC file for the initial setup, oscillator, register names etc. What I would like is to be able to change one line in the main programme to use LCD_PORTB or LCD_PORTC and code the declares in the INC file using the preprocessor. I have tried a few different thing but either I get compilation errors or the LCD does not work.
    My RAM is failing

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.

  • #2
    Senior Member AlbertoFS's Avatar
    Join Date
    Apr 2005
    Posts
    688
    Thumbs Up
    Received: 91
    Given: 2
    Total Downloaded
    4.62 GB

    0 Not allowed!

    Default Re: How to use the preprocessor to change LCD port declares

    Something like this?
    Comment or uncomment this line.
    $Define _LCD_PORTB_


    $ifdef _LCD_PORTB_
    Declare LCD_DTPin = PORTB.4 ' LCD's Data lines (D4 to D7)
    Declare LCD_ENPin = PORTB.3 ' LCD's EN line
    Declare LCD_RSPin = PORTB.2 ' LCD's RS line
    $else
    Declare LCD_DTPin = PORTC.4 ' LCD's Data lines (D4 to D7)
    Declare LCD_ENPin = PORTC.3 ' LCD's EN line
    Declare LCD_RSPin = PORTC.2 ' LCD's RS line
    $endif

    Declare LCD_Interface = 4 ' 4-bit interface to LCD
    Declare LCD_Lines = 2 ' LCD contains 2 lines
    Declare LCD_DataUs = 50 ' Time to wait after print a data To LCD
    Declare LCD_CommandUs = 2000 ' Time to wait after print a command to LCD
    Declare LCD_Type = Alphanumeric ' LCD type is alphanumeric
    73's de Alberto ea3agv

  • 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
    Prolific Poster See_Mos's Avatar
    Join Date
    Feb 2004
    Posts
    1,285
    Thumbs Up
    Received: 17
    Given: 0
    Total Downloaded
    872.27 MB

    0 Not allowed!

    Default Re: How to use the preprocessor to change LCD port declares

    Thanks Alberto, that works. I would also like to add the option of PORTA. I am puzzled why this does not work?

    '$define _LCD_PORTA_
    '$define _LCD_PORTB_
    $define _LCD_PORTC_

    Then

    $ifdef _LCD_PORTA_
    Declare LCD_DTPin = PORTA.4 ' LCD's Data lines (D4 to D7)
    Declare LCD_RSPin = PORTA.3 ' LCD's RS line
    Declare LCD_ENPin = PORTA.2 ' LCD's EN line
    $endif

    $ifdef _LCD_PORTB_
    Declare LCD_DTPin = PORTB.4 ' LCD's Data lines (D4 to D7)
    Declare LCD_RSPin = PORTB.3 ' LCD's RS line
    Declare LCD_ENPin = PORTB.2 ' LCD's EN line
    $endif

    $ifdef _LCD_PORTC_
    Declare LCD_DTPin = PORTC.4 ' LCD's Data lines (D4 to D7)
    Declare LCD_RSPin = PORTC.3 ' LCD's RS line
    Declare LCD_ENPin = PORTC.2 ' LCD's EN line
    $endif

    note EN and RS have been swapped to match my hardware.
    My RAM is failing

  • 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.

  • #4
    Senior Member AlbertoFS's Avatar
    Join Date
    Apr 2005
    Posts
    688
    Thumbs Up
    Received: 91
    Given: 2
    Total Downloaded
    4.62 GB

    0 Not allowed!

    Default Re: How to use the preprocessor to change LCD port declares

    It is absolutely correct if a single $Define is activated.
    What is the port that fails?
    Are you sure to have put all the ports as digital?
    Have you another peripheral activated on PORTC?
    Could the internal pull-up resistors in the PORTB be a problem?

    It could also be written in another way. 0 => PORTA, 1 => PORTB, 2 => PORTC
    Code:
    $Define _LCDPORT_ 0
    
    $if _LCDPORT_ = 0
    
    Declare LCD_DTPin = PORTA.4 ' LCD's Data lines (D4 to D7)
    Declare LCD_RSPin = PORTA.3 ' LCD's RS line
    Declare LCD_ENPin = PORTA.2 ' LCD's EN line
    
    $elseif _LCDPORT_ = 1
    
    Declare LCD_DTPin = PORTB.4 ' LCD's Data lines (D4 to D7)
    Declare LCD_RSPin = PORTB.3 ' LCD's RS line
    Declare LCD_ENPin = PORTB.2 ' LCD's EN line
    $endif
    
    $elseif _LCDPORT_ = 2
    
    Declare LCD_DTPin = PORTC.4 ' LCD's Data lines (D4 to D7)
    Declare LCD_RSPin = PORTC.3 ' LCD's RS line
    Declare LCD_ENPin = PORTC.2 ' LCD's EN line
    
    $endif
    73's de Alberto ea3agv

  • 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
    Prolific Poster towlerg's Avatar
    Join Date
    Mar 2012
    Posts
    2,208
    Thumbs Up
    Received: 74
    Given: 180
    Total Downloaded
    5.15 GB

    0 Not allowed!

    Default Re: How to use the preprocessor to change LCD port declares

    I am puzzled why this does not work?
    I know it's stating the obvious but if your ever in any doubt about outcome of preprocessor statements just look at the asm/lst.
    George.

  • 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.

  • #6
    Prolific Poster See_Mos's Avatar
    Join Date
    Feb 2004
    Posts
    1,285
    Thumbs Up
    Received: 17
    Given: 0
    Total Downloaded
    872.27 MB

    0 Not allowed!

    Default Re: How to use the preprocessor to change LCD port declares

    Thanks Alberto but that didn’t work either.

    All_Digital = true, using FOSC = INTIO67, no peripherals activated and all port pins are set to output for the purpose of this test so that I can cut the power and move the LCD plug to whichever port I want to test.

    If I put your code into the main programme PortA or PortB work but not PortC which defaults to B. If I put the port pins into three separate $if………..$endif that does work.

    When I moved the code to the .inc file and just have $Define _LCDPort_ 0 ,or 1, or 2 in the main file the compiler throws up an error ‘unrecognised or incorrect operator syntax’.

    The aim it to move all reusable declares, code etc. into the .inc file. I have a workaround but it’s not as neat as I wanted. I created three .inc files “LCD_Port_A.inc”, “LCD_Port_B.inc” and “LCD_Port_C.inc” and just edit A, B, or C as required.
    My RAM is failing

  • 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
    Senior Member tumbleweed's Avatar
    Join Date
    May 2011
    Posts
    484
    Thumbs Up
    Received: 59
    Given: 0
    Total Downloaded
    330.54 MB

    0 Not allowed!

    Default Re: How to use the preprocessor to change LCD port declares

    In alberto's post there's an extra $endif under the "=1" section. Remove that.

  • 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.

  • #8
    Prolific Poster See_Mos's Avatar
    Join Date
    Feb 2004
    Posts
    1,285
    Thumbs Up
    Received: 17
    Given: 0
    Total Downloaded
    872.27 MB

    0 Not allowed!

    Default Re: How to use the preprocessor to change LCD port declares

    I spotted that but wasn't sure so I tried removing it and tried other variations without success
    My RAM is failing

  • 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
    Senior Member AlbertoFS's Avatar
    Join Date
    Apr 2005
    Posts
    688
    Thumbs Up
    Received: 91
    Given: 2
    Total Downloaded
    4.62 GB

    0 Not allowed!

    Default Re: How to use the preprocessor to change LCD port declares

    I have tested this configuration on the Proteus (PIC18F25K22) with 3 LCDs and everything works fine. I changed the nibble of the PORTA in the lower part because a Xtal is used in RA6 / RA7.
    Code:
    $define _LCD_PORT_ 0
    
        $if _LCD_PORT_ = 0
    
        Declare LCD_DTPin = PORTA.0 ' LCD's Data lines (D4 to D7)
        Declare LCD_RSPin = PORTA.4 ' LCD's RS line
        Declare LCD_ENPin = PORTA.5 ' LCD's EN line
        Declare LCD_Interface = 4           ' 4-bit interface to LCD
        Declare LCD_Lines = 2               ' LCD contains 2 lines
        Declare LCD_DataUs = 50             ' Time to wait after print a data To LCD
        Declare LCD_CommandUs = 2000        ' Time to wait after print a command to LCD
        Declare LCD_Type = Alphanumeric     ' LCD type is alphanumeric
    
        $elseif _LCD_PORT_ = 1
    
        Declare LCD_DTPin = PORTB.4 ' LCD's Data lines (D4 to D7)
        Declare LCD_RSPin = PORTB.3 ' LCD's RS line
        Declare LCD_ENPin = PORTB.2 ' LCD's EN line
        Declare LCD_Interface = 4           ' 4-bit interface to LCD
        Declare LCD_Lines = 2               ' LCD contains 2 lines
        Declare LCD_DataUs = 50             ' Time to wait after print a data To LCD
        Declare LCD_CommandUs = 2000        ' Time to wait after print a command to LCD
        Declare LCD_Type = Alphanumeric     ' LCD type is alphanumeric
    
        $elseif _LCD_PORT_ = 2
        
        Declare LCD_DTPin = PORTC.4 ' LCD's Data lines (D4 to D7)
        Declare LCD_RSPin = PORTC.3 ' LCD's RS line
        Declare LCD_ENPin = PORTC.2 ' LCD's EN line
        Declare LCD_Interface = 4           ' 4-bit interface to LCD
        Declare LCD_Lines = 2               ' LCD contains 2 lines
        Declare LCD_DataUs = 50             ' Time to wait after print a data To LCD
        Declare LCD_CommandUs = 2000        ' Time to wait after print a command to LCD
        Declare LCD_Type = Alphanumeric     ' LCD type is alphanumeric
    
        $endif
    Last edited by AlbertoFS; 7th April 2017 at 20:26.
    73's de Alberto ea3agv

  • 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.

  • #10
    Prolific Poster joesaliba's Avatar
    Join Date
    Sep 2004
    Posts
    2,456
    Thumbs Up
    Received: 71
    Given: 26
    Total Downloaded
    6.08 GB

    0 Not allowed!

    Default Re: How to use the preprocessor to change LCD port declares

    Within these $define I would also include TRIS and any other things to change to digital for each individual port. In that case you do not need to go thorough your main program to change them each time.
    Regards

    Joseph

  • 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
    Prolific Poster See_Mos's Avatar
    Join Date
    Feb 2004
    Posts
    1,285
    Thumbs Up
    Received: 17
    Given: 0
    Total Downloaded
    872.27 MB

    0 Not allowed!

    Default Re: How to use the preprocessor to change LCD port declares

    Thanks Alberto, Your replies in post 4 and post 9 both work. It was so obvious once I spotted the error, the ‘unrecognised or incorrect operator syntax’ error was because in the main code I put the $Define after including the .inc file instead of before it.

    Good idea Joseph, I'll do that.
    My RAM is failing

  • 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. [SOLVED !] Help with RB Port Change Interrupt on 18F2620
      By juppetup in forum Proton Plus Compiler v3
      Replies: 4
      Last Post: 28th December 2014, 20:36
    2. 12F609 Port pins inadvertently change logic states
      By gdesantis in forum WIKI Discussion
      Replies: 6
      Last Post: 6th July 2014, 19:46
    3. SERIN causing an I/O port to change state
      By Drpepper50 in forum Serial / Ethernet
      Replies: 1
      Last Post: 8th November 2012, 23:14
    4. Change On Port Interrupt Pitfalls
      By canipus in forum Proton Plus Compiler v3
      Replies: 3
      Last Post: 26th April 2011, 15:03
    5. [SOLVED !] 16F690 LCD on Port-B vs. Port-C
      By albertus0214 in forum Proton Plus Compiler v3
      Replies: 4
      Last Post: 17th July 2007, 07:23

    Members who have read this thread : 35

    Actions :  (Set Date)

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

    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