activating i/o ports according to variable value


Closed Thread
Results 1 to 13 of 13

Hybrid View

  1. #1
    Join Date
    Jul 2010
    Posts
    6

    Default activating i/o ports according to variable value

    Hi all, I am trying to work out a way to generate a variable using a for .. to .. next loop and then send the i/o port (let's say b for arguments sake) corresponding to the numeric variable value high .. eg (for x=0 to 4: high portb.x: next x). Now this doesn't work one little bit but I was wondering if there was a way to do it ( different code ) same outcome....

    Cheers

  2. #2
    Join Date
    Nov 2004
    Posts
    61


    Did you find this post helpful? Yes | No

    Default

    Code:
    FOR x = 0 to 5
    HIGH PORTB.0[x]
    Pause 100
    Next x

  3. #3
    Join Date
    Jul 2010
    Posts
    6


    Did you find this post helpful? Yes | No

    Default Thanks..but still no go :)

    Thanks JEC .. gave it a whirl but got a comiling error...

  4. #4
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Did you declare X VAR BYTE? Should work fine otherwise. What error do you get?
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  5. #5
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default

    Here is a program I posted some time ago. It can be used as an example to do what you are trying to do.

    http://www.picbasic.co.uk/forum/show...highlight=port
    Charles Linquist

  6. #6
    Join Date
    Jul 2010
    Posts
    6


    Did you find this post helpful? Yes | No

    Smile I'll see what happens

    Thanks Charles, I haven't had time to run a test but maybe I've spotted my problem whilst checking your code.

    IF PortValue = 4 THEN
    HSEROUT [10,13,"Port A4 is Open Collector!",13,10]
    ENDIF
    ADCON1 = $FF
    TRISA.0(PortValue)= 0 'Make it an output
    PauseUs 20
    PORTA.0(PortValue) = 0 'Write a '0'
    GOTO StateCheck
    ENDIF


    My understanding, according to the code, is that I should use round brackets not square brackets as I misunderstood? JEC's code to show???? I'll try and see if it works

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