Port control code Yelp!!


Closed Thread
Results 1 to 5 of 5
  1. #1
    andyf's Avatar
    andyf Guest

    Default Port control code Yelp!!

    ' I am sure someone will know this answer and likely laugh a lot at my code, the variables are all declared and the long winded code works great but its very long code.


    mainloop:
    HSERIN [WAIT("**"),STR in_ctl\11\"!"]
    if (in_ctl[0]) = "B" then goto SWB
    goto mainloop



    SWB:
    PIN = in_ctl[1] ' 0 - 7
    STATE = in_ctl[2] ' H or L

    if PIN="0" and STATE = "H" then HIGH PortB.0
    if PIN="0" and STATE = "L" then LOW PortB.0

    if PIN="1" and STATE = "H" then HIGH PortB.1
    if PIN="1" and STATE = "L" then LOW PortB.1

    if PIN="2" and STATE = "H" then HIGH PortB.2
    if PIN="2" and STATE = "L" then LOW PortB.2

    'And so on

    Goto mainloop



    ' Here's the question
    ' Using PBP pro 2.45 is there a neater way to do this with less code, I expected to be able to do something like the following to reduce 16 lines of code down to just 2:

    SWB:
    PIN = in_ctl[1] ' 0 - 7
    STATE = in_ctl[2] ' H or L

    if STATE = "H" then PortB.[PIN]=1
    if STATE = "L" then PortB.[PIN]=0

    Goto mainloop

  2. #2
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166


    Did you find this post helpful? Yes | No

    Default

    Andyf, Use this syntax to accomplish your task:

    SWB:
    PIN = in_ctl[1] ' 0 - 7
    STATE = in_ctl[2] ' H or L

    if STATE = "H" then PortB.0[PIN]=1
    if STATE = "L" then PortB.0[PIN]=0

    Goto mainloop

    actually if you send a "0" or a "1" decimal for the state you can save another line of code by using the syntax:

    SWB:
    PIN = in_ctl[1] ' 0 - 7
    STATE = in_ctl[2] ' H or L

    PortB.0[PIN] = state - 48

    Goto mainloop

    Infact if you don't need to save the "state" for later reference you don't even need it at all by using the syntax:

    SWB:
    PIN = in_ctl[1] ' 0 - 7

    PortB.0[PIN] = in_ctl[2] - 48

    Goto mainloop

    Dave Purola,
    N8NTA

  3. #3
    andyf's Avatar
    andyf Guest


    Did you find this post helpful? Yes | No

    Default

    Thanks dave for the answer, tried the code, compiled it without errors but the bit does not change in the pic as in the longer version.

    is it possible I need to put some brackets or quotes?
    PortA.0([PIN]="1")

  4. #4
    andyf's Avatar
    andyf Guest


    Did you find this post helpful? Yes | No

    Post

    Just had a thought while making a coffee,

    are the declarations correct to do it your way?

    ' Variable Defs
    ' ------------

    SerData var byte
    PIN var byte
    STATE var byte
    in_ct var BYTE[10] 'In coming control arrey


    if STATE = "H" then PortA.[PIN]=1
    if STATE = "L" then PortA.[PIN]=0

  5. #5
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166


    Did you find this post helpful? Yes | No

    Default

    Andyf, Sorry I haven't returned a reply before this but I just got back from a wedding of one of my sisters kids. The wedding was in Traverse city which is about 4 hours away. I left Friday at noon and just got back Sunday at about 5:00pm. You have it right. the expression needs a Boolean operator to work so if you use one of the predefined keywords ie HIGH or LOW or 1 or 0 or a variable that would be set to 1 or 0 that would work. No need for brackets after the equals sign unless you have some kind of equation that requires hierarchal order. If that doesn't work I would check the Tris register for being setup properly.

    Dave Purola,
    N8NTA

Similar Threads

  1. Reading in Manchester code
    By brid0030 in forum Code Examples
    Replies: 0
    Last Post: - 10th March 2009, 21:55
  2. Making Program Code Space your playground...
    By Melanie in forum Code Examples
    Replies: 15
    Last Post: - 19th July 2008, 08:26
  3. How to set TMRO & TMR3 as Counter?.
    By NatureTech in forum mel PIC BASIC Pro
    Replies: 21
    Last Post: - 18th May 2007, 08:52
  4. Re-Writing IF-THEN-AND-ENDIF code?
    By jessey in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 18th August 2006, 17:23
  5. Replies: 2
    Last Post: - 31st July 2006, 16:06

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