Variable


+ Reply to Thread
Results 1 to 6 of 6

Thread: Variable27 days old

  1. #1
    Junior Member twakkie's Avatar
    Join Date
    Nov 2019
    Posts
    2
    Thumbs Up
    Received: 0
    Given: 0
    Total Downloaded
    0

    0 Not allowed!

    Default Variable

    Hi
    Need help to setup an 8bit variable
    So that I can test and set each bit when an action happened
    Pic is 16f877a
    (If button was press set flag
    We
    Stephen Heugh

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 GAMBOA's Avatar
    Join Date
    Nov 2004
    Posts
    421
    Thumbs Up
    Received: 19
    Given: 0
    Total Downloaded
    203.73 MB

    0 Not allowed!

    Default Re: Variable

    Hi Twakkie,

    For example:

    Dim MyVar as Byte

    MyVar.0 = 0
    MyVar.1 = 1
    .......

    Regards
    Gamboa

  • 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
    Junior Member keytapper's Avatar
    Join Date
    Jun 2019
    Posts
    90
    Thumbs Up
    Received: 3
    Given: 3
    Total Downloaded
    308.02 MB

    0 Not allowed!

    Default Re: Variable

    One might alias any singular bit if needed.
    Code:
    Dim button as byte
    Dim menu as button.0
    Dim Up as button.1
    Dim Down as button.2
    
    Clear button        ' clearing all flags at once ;-)

  • 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 twakkie's Avatar
    Join Date
    Nov 2019
    Posts
    2
    Thumbs Up
    Received: 0
    Given: 0
    Total Downloaded
    0

    0 Not allowed!

    Default Re: Variable

    Thanks
    The variable must be 8 bits long
    This more or less what I need to setup
    Can anyone help
    Pic16f877 is used


    Dim myvar as byte
    Symbol button1 = porta.0
    Symbol button2 = porta.1

    If button1 is pressed set
    Myvar.1high ;flag to indicate it was pressed
    If Button2 is pressed check flags in myvar
    Flag is on for button1 so wait till flag is cleared.
    Stephen Heugh

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

    1 Not allowed!

    Default Re: Variable

    If it not clear exactly what you are trying to do.
    Are you trying to read PortA (buttons) into a Variable to act as flags indicating which switch(s) were pressed which you then read and clear?
    If so then first you have to read the data i.e.
    Code:
    Button_Variable = PortA   'Read button status
    The you need to test each bit in turn, see the get bit example from the manual, the for next loop test all 8 bits and then perform the appropriate actions, I personally would probably use Select Case (see manual) so something like...
    Code:
    Dim Index as Byte
    Dim Button_Status as bit
    For Index = 0 to 7     'Check each bit of the byte
    Button_Status = GetBit Button_Variable, Index     'Get the value (1 or 0) of the currently bit
    Select Index
    Case = 0     'Instructions if 1st button is pressed 
      If Button status = 1 then   'Assuming that 1 = pressed
      Do something
      Button_Variable.Index = 0     'or Clearbit Button_Variable.Index to clear the flag)
      EndIf
    Case = 1     'Instructions if 2nd button is pressed 
      If Button status = 1 then   'Assuming that 1 = pressed
      Do something
      Button_Variable.Index = 0     'or Clearbit Button_Variable.Index to clear the flag)
      EndIf
    End Case
    Up to Case = 7 if you are testing all 8 bits, or something like that. Although if you only have a couple of buttons then just a couple if simple If-Then statements may suffice, i.e....
    Code:
    Symbol button1 = PortA.0
    Symbol button2 = porta.1
    If Button 1 = 1 then
    Do something
    EndIf
    And repeat for button two.

    I suggest also reading the GetBit, Setbit & ClearBit sections of the manual.

    However, in both the examples above the button read is not synchronised with the button press so you are relaying being able read the button status fast enough to ensure a button press is detected. If your code is not to long and your Xtal frequency is quite high then it should be a problem however, a better approach if the device that pins with Interrupt On Change functions would be to consider connecting the buttons to those and using On Hardware Interrupt (see manual) to create an interrupt handler within which you read the button port to a variable (i.e. Variable = PortA) so that you can capture the buttons states at the time they were pressed and keep the loop that checks which buttons were pressed in you main code.

  • 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 John Drew's Avatar
    Join Date
    Feb 2002
    Posts
    2,795
    Thumbs Up
    Received: 87
    Given: 34
    Total Downloaded
    4.53 GB

    0 Not allowed!

    Default Re: Variable

    Helpful answer Steve, you explain things very clearly.
    I tried to give you a thumbs up but I might have done the reverse at which point I got confused and thought a note may be better
    John

  • 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. Selecting variable bit using another variable
      By ricardourio in forum Wish List / Product Feedback
      Replies: 2
      Last Post: 30th June 2017, 12:23
    2. Assignment Variable = AddressOf (Variable)
      By AlbertoFS in forum Wish List / Product Feedback
      Replies: 1
      Last Post: 13th March 2017, 11:01
    3. Toggle variable + Nibble variable
      By Oldhack in forum Wish List / Product Feedback
      Replies: 2
      Last Post: 21st September 2013, 22:18
    4. Variable assignment while defining a Variable
      By SELCUK in forum Proton Plus Compiler v3
      Replies: 1
      Last Post: 14th April 2010, 10:39
    5. Declaring variable over another variable
      By pdgnr in forum Proton Plus Compiler v3
      Replies: 5
      Last Post: 24th March 2006, 07:53

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts