PORT INDEX help-me


+ Reply to Thread
Results 1 to 14 of 14

Thread: PORT INDEX help-me720 days old

  1. #1
    Junior Member cassio_franquini's Avatar
    Join Date
    Aug 2010
    Posts
    7
    Thumbs Up
    Received: 0
    Given: 0
    Total Downloaded
    1.16 GB

    0 Not allowed!

    Default PORT INDEX help-me

    how can I index a port, with the effect below. the way it does it wrong, how can I solve it?


    symbol PORT = porta


    for A = 0 to 7
    port.A = 1
    next A




    Thank you

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
    Prolific Poster hadv215's Avatar
    Join Date
    Sep 2009
    Posts
    1,136
    Thumbs Up
    Received: 66
    Given: 26
    Total Downloaded
    3.61 GB

    0 Not allowed!

    Default Re: PORT INDEX help-me

    sorry for you, but you can't

  • 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 bill9399's Avatar
    Join Date
    Aug 2004
    Posts
    1,701
    Thumbs Up
    Received: 2
    Given: 0
    Total Downloaded
    1.13 GB

    0 Not allowed!

    Default Re: PORT INDEX help-me

    Quote Originally Posted by cassio_franquini View Post
    how can I index a port, with the effect below. the way it does it wrong, how can I solve it?


    symbol PORT = porta


    for A = 0 to 7
    port.A = 1
    next A




    Thank you

    Use comma (,) as separator for index value. Not period (.)

    Device = 16F877
    Declare Xtal = 4
    Symbol port = PORTD
    Dim A As Byte
    Output PORTD
    While 1=1
    For A = 0 To 7
    SetBit port,A ; note use of comma
    DelayMS 500
    Next A
    port = 0
    DelayMS 500
    Wend


    End
    This compiles ok in PDS and simulates in ISIS, using an 16f877.
    Note use of setbit command. Also check help manual for clearbit.
    A wise man may listen and say nothing. A fool may listen and have nothing to say. Which one are you???

  • 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
    Junior Member cassio_franquini's Avatar
    Join Date
    Aug 2010
    Posts
    7
    Thumbs Up
    Received: 0
    Given: 0
    Total Downloaded
    1.16 GB

    0 Not allowed!

    Default Re: PORT INDEX help-me

    Ok friend, thanks a lot for your answer

  • 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
    Fanatical Contributor top204's Avatar
    Join Date
    Feb 2002
    Posts
    3,480
    Thumbs Up
    Received: 314
    Given: 146
    Total Downloaded
    1.99 GB

    0 Not allowed!

    Default Re: PORT INDEX help-me

    See SetPin and ClearPin in the manual:

    Code:
        Device = 16F877
        Declare Xtal = 20
        
        Dim MyPortPin As Byte
    
        Low  PORTA 
        
        For MyPortPin = 0 To  7 
            SetPin MyPortPin        ' Set pins 0 to 7 of PORTA
            DelayMS  100 
        Next
        
        For MyPortPin = 0 To 7
            ClearPin MyPortPin       ' Clear pins 0 to 7 of PORTA
            DelayMS 100
        Next

  • 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
    Junior Member basiclover's Avatar
    Join Date
    Oct 2014
    Posts
    29
    Thumbs Up
    Received: 0
    Given: 0
    Total Downloaded
    2.84 GB

    0 Not allowed!

    Default Re: PORT INDEX help-me

    don't understand how you know that SetPin acts on PORTA in that example

  • 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 Stephen Moss's Avatar
    Join Date
    Jan 2006
    Posts
    526
    Thumbs Up
    Received: 31
    Given: 7
    Total Downloaded
    3.87 GB

    0 Not allowed!

    Default Re: PORT INDEX help-me

    I am sure I have seen this explained in a post somewhere although I cannot remember where. The manual says...
    Pin Number can be a variable or constant or expression that holds a value from 0 to the
    amount of I/O pins on the device. A value of 0 will be PORTA.0, if present, 1 will be PORTA.1,
    8 will be PORTB.0 etc…
    Therefore I believe values...
    0 - 7 = PortA (0-7 respectively)
    8 - 15 = PortB (0-7 respectively)
    16 - 23 = PortC (0-7 respectively) and so on as applicable to the number of ports in a particular device.

  • 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,299
    Thumbs Up
    Received: 17
    Given: 0
    Total Downloaded
    872.27 MB

    0 Not allowed!

    Default Re: PORT INDEX help-me

    I didn't know that!

    ClearPin and SetpPin are described in the help file
    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
    Junior Member basiclover's Avatar
    Join Date
    Oct 2014
    Posts
    29
    Thumbs Up
    Received: 0
    Given: 0
    Total Downloaded
    2.84 GB

    0 Not allowed!

    Default Re: PORT INDEX help-me

    Thanks Stephen, I didn't remember 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.

  • #10
    Prolific Poster hadv215's Avatar
    Join Date
    Sep 2009
    Posts
    1,136
    Thumbs Up
    Received: 66
    Given: 26
    Total Downloaded
    3.61 GB

    0 Not allowed!

    Default Re: PORT INDEX help-me

    It is mentioned in the manual but, frankly, I think this is really very confusing. In three years time when you have to modify the program you don't know what you have been doing.
    The least you should do is use symbols for all the values.

  • 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 joesaliba's Avatar
    Join Date
    Sep 2004
    Posts
    2,496
    Thumbs Up
    Received: 73
    Given: 31
    Total Downloaded
    6.55 GB

    0 Not allowed!

    Default Re: PORT INDEX help-me

    Quote Originally Posted by hadv215 View Post
    I think this is really very confusing.
    Yes agreed, but sometimes it is really necessary to use that method of SetPin / ClearPin where a just aliasing a symbol is impossible.
    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.

  • #12
    Fanatical Contributor top204's Avatar
    Join Date
    Feb 2002
    Posts
    3,480
    Thumbs Up
    Received: 314
    Given: 146
    Total Downloaded
    1.99 GB

    0 Not allowed!

    Default Re: PORT INDEX help-me

    Take a look in each device's .def file, and you'll find:

    Code:
    '-----------------------------------------------------------------------------------
    ' Pin Numbers for PORTA
    '
    $define Pin_A0 0
    $define Pin_A1 1
    $define Pin_A2 2
    $define Pin_A3 3
    $define Pin_A4 4
    $define Pin_A5 5
    $define Pin_A6 6
    $define Pin_A7 7
    '
    ' Pin Numbers for PORTB
    '
    $define Pin_B0 8
    $define Pin_B1 9
    $define Pin_B2 10
    $define Pin_B3 11
    $define Pin_B4 12
    $define Pin_B5 13
    $define Pin_B6 14
    $define Pin_B7 15
    '
    ' Pin Numbers for PORTC
    '
    $define Pin_C0 16
    $define Pin_C1 17
    $define Pin_C2 18
    $define Pin_C3 19
    $define Pin_C4 20
    $define Pin_C5 21
    $define Pin_C6 22
    $define Pin_C7 23
    '
    ' Pin Numbers for PORTD
    '
    $define Pin_D0 24
    $define Pin_D1 25
    $define Pin_D2 26
    $define Pin_D3 27
    $define Pin_D4 28
    $define Pin_D5 29
    $define Pin_D6 30
    $define Pin_D7 31
    '
    ' Pin Numbers for PORTE
    '
    $define Pin_E0 32
    $define Pin_E1 33
    $define Pin_E2 34
    $define Pin_E3 35
    $define Pin_E4 36
    $define Pin_E5 37
    $define Pin_E6 38
    $define Pin_E7 39
    '
    ' Pin Numbers for PORTF
    '
    $define Pin_F0 40
    $define Pin_F1 41
    $define Pin_F2 42
    $define Pin_F3 43
    $define Pin_F4 44
    $define Pin_F5 45
    $define Pin_F6 46
    $define Pin_F7 47
    '
    ' Pin Numbers for PORTG
    '
    $define Pin_G0 48
    $define Pin_G1 49
    $define Pin_G2 50
    $define Pin_G3 51
    $define Pin_G4 52
    $define Pin_G5 53
    $define Pin_G6 54
    $define Pin_G7 55
    '
    ' Pin Numbers for PORTH
    '
    $define Pin_H0 56
    $define Pin_H1 57
    $define Pin_H2 58
    $define Pin_H3 59
    $define Pin_H4 60
    $define Pin_H5 61
    $define Pin_H6 62
    $define Pin_H7 63
    '
    ' Pin Numbers for PORTJ
    '
    $define Pin_J0 64
    $define Pin_J1 65
    $define Pin_J2 66
    $define Pin_J3 67
    $define Pin_J4 68
    $define Pin_J5 69
    $define Pin_J6 70
    $define Pin_J7 71
    '
    ' Pin Numbers for PORTK
    '
    $define Pin_K0 72
    $define Pin_K1 73
    $define Pin_K2 74
    $define Pin_K3 75
    $define Pin_K4 76
    $define Pin_K5 77
    $define Pin_K6 78
    $define Pin_K7 79
    '
    ' Pin Numbers for PORTL
    '
    $define Pin_L0 80
    $define Pin_L1 81
    $define Pin_L2 82
    $define Pin_L3 83
    $define Pin_L4 84
    $define Pin_L5 85
    $define Pin_L6 86
    $define Pin_L7 87
    So you can use:

    Code:
        Dim MyPortPin As Byte
    
        Low  PORTA 
        
        For MyPortPin = Pin_A0 To Pin_A7
            SetPin MyPortPin        ' Set pins 0 to 7 of PORTA
            DelayMS 100
        Next
        
        For MyPortPin = Pin_A0 To Pin_A7
            ClearPin MyPortPin       ' Clear pins 0 to 7 of PORTA
            DelayMS  100 
        Next

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

  • #13
    Senior Member Stephen Moss's Avatar
    Join Date
    Jan 2006
    Posts
    526
    Thumbs Up
    Received: 31
    Given: 7
    Total Downloaded
    3.87 GB

    0 Not allowed!

    Default Re: PORT INDEX help-me

    Quote Originally Posted by hadv215 View Post
    It is mentioned in the manual but, frankly, I think this is really very confusing. In three years time when you have to modify the program you don't know what you have been doing.
    I thought that as well when I first noticed its implementation, sitting there trying to work out the number over using the High & Low commands initially seemed more trouble than it was worth, but it is better to have the command there if you need it but not use it than the other way around as one day it may come in handy.

    I think good commenting would be essential to know what was going on upon returning to it after a break, but then good commenting is always good practice regardless.

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

  • #14
    Fanatical Contributor top204's Avatar
    Join Date
    Feb 2002
    Posts
    3,480
    Thumbs Up
    Received: 314
    Given: 146
    Total Downloaded
    1.99 GB

    0 Not allowed!

    Default Re: PORT INDEX help-me

    You can pass a variable holding a Port's bit to a subroutine, so the subroutine can manipulate more than a single Port.Bit.

    Manipulating the Port's bit is slower using the variable, because a routine has to calculate what the value means, but it does mean you can have a single routine that can do a lot more.

    For example, to write the SPI data to several APA102 RGB LED strips using the same subroutine, you can use:

    Code:
        Device = 18F25K20
        Declare Xtal = 64
    '
    ' Create variables for the routine
    '
        Dim APA_bSPI_Index As Byte
        Dim APA_bDataPin   As Byte
        Dim APA_bClockPin  As Byte
        Dim APA_dBBGR      As Dword
    
    '----------------------------------------------------------------------------------
         GoTo Main                                   ' Jump to the start of the program 
    
    '----------------------------------------------------------------------------------
    ' Write 32-bits of data to an APA102 RGB LED device
    ' Input     : APA_dBBGR holds the data to write
    '           : pDataPin holds the pin to use for the data line
    '           : pClockPin holds the pin to use for the Clk line 
    ' Output    : None
    ' Notes     : Shift data out MSB first.
    '           : Clock idles low
    '           : Brightness is sent first, then blue, green, red
    '
    $define APA_Write32(pDataPin, pClockPin, pValue) '
        APA_bDataPin = pDataPin                      '
        APA_bClockPin = pClockPin                    '
        APA_dBBGR = pValue                           '
        _APA_Write32()
    
    Sub _APA_Write32()
        Low APA_bDataPin                            ' Make the data pin an output low before we start              
        Low APA_bClockPin                           ' Make the clock pin an output low before we start                        
        For APA_bSPI_Index = 31 To 0 Step -1        ' Create a loop for the bits of data
            ClearPin APA_bDataPin                   ' \
            If APA_dBBGR.31 = 1 Then                ' | Put the current outgoing bit on the data pin
                SetPin APA_bDataPin                 ' |
            EndIf                                   ' /
            SetPin APA_bClockPin                    ' Set the Clock pin high
            APA_dBBGR = APA_dBBGR << 1              ' Shift the next bit into MSB
            ClearPin APA_bClockPin                  ' Pull the Clock pin low
        Next
    EndSub
    
    '----------------------------------------------------------------------------------
    Main:
        APA_Write32(Pin_B0, Pin_B1, $0F7FFF7F)      ' Write to an APA102 strip using pins PORTB.0 for data and PORTB.1 for clock
        APA_Write32(Pin_B2, Pin_B3, $0F7FFF7F)      ' Write to an APA102 strip using pins PORTB.2 for data and PORTB.3 for clock
    Last edited by top204; 5th September 2018 at 10:09.

  • 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. List index out of bounds
      By geoff_c in forum In Circuit Debugger
      Replies: 2
      Last Post: 15th August 2014, 04:21
    2. pic controlled index head
      By C_Moore in forum The Lounge
      Replies: 2
      Last Post: 11th February 2013, 17:30
    3. Index with sub-indexes
      By pic-ignorant in forum Proton Plus Compiler v3
      Replies: 5
      Last Post: 8th October 2012, 13:36
    4. Help file index
      By See_Mos in forum Wish List / Product Feedback
      Replies: 1
      Last Post: 23rd March 2011, 10:53
    5. Index in a Byte Variable
      By laserline in forum Proton Plus Compiler v3
      Replies: 2
      Last Post: 29th April 2008, 16:39

    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