Port Variables act like Constants


Closed Thread
Results 1 to 5 of 5

Hybrid View

  1. #1


    Did you find this post helpful? Yes | No

    Default Re: Port Variables act like Constants

    Hi MOUNTAIN747.. why not just use GOTO statements? I think it's easier to do...
    Code:
            DS1       VAR PortA.1   ;dip switch 
                     
            start:  
             If  DS1=1 then
    	   goto tx_usb
             Else
    	  goto tx_rs485
             EndIF
    
            tx_usb:
              Serout portc.6, 84 ["Transmitting USB"]
              goto start
       
            tx_rs485:
              Serout2 portc.5, 84 ["Transmitting RS485"]
              goto start
    Adding PAUSE's can help...

  2. #2
    Join Date
    Jan 2009
    Location
    Alabama,USA
    Posts
    232


    Did you find this post helpful? Yes | No

    Default Re: Port Variables act like Constants

    Thank you for your reply Olan,
    The program has to print out 12 or more different messages when it uploads 30 days of stored data. I’ve run out of EEprom so the messages are at a high cost in code space. If I can use only one message for both USB, which is the primary port, and RS485, which is used only occasionally, it will save 1800 words of code space.

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


    Did you find this post helpful? Yes | No

    Default Re: Port Variables act like Constants

    Look in the .bas file for the chip you are using.
    If it's a 16F877A then open c:\pbp\16f877a.bas

    The PORTL and PORTH aliases are used for the PIN numbers (0-15)
    PORTL is 0-7 and PORTH is 8-15.
    Code:
    PORTL   VAR     PORTB
    PORTH   VAR     PORTC
    TRISL   VAR     TRISB
    TRISH   VAR     TRISC
    If PORTH is aliased to PORTC then you don't need to do anything.
    If it's not, change it to PORTC, and change TRISH to alias TRISC.

    Then you can use the PIN numbers to access the pins with a variable.
    Code:
        If DS1=1 then
    	ComVar=14   ; PORTC.6
    	Else
    	ComVar=13   ; PORTC.5
        EndIF
    
        Serout2 ComVar, 84, [“  Com is PIN - ”, DEC ComVar,13,10]
    DT

  4. #4
    Join Date
    Jan 2009
    Location
    Alabama,USA
    Posts
    232


    Did you find this post helpful? Yes | No

    Default Re: Port Variables act like Constants

    Darrel,
    Thanks again, you make it look so easy! After two days of working with this I now know I was searching for the wrong topics. I haven’t found anything about the .bas file in the manual. I think this subject deserves a WiKi along side your other documents.

    By the way, to those who had a hand in creating the Wiki and those who maintain it, ITS GREAT!

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