Help: how to assign assorted pins to one byte variable


Closed Thread
Results 1 to 9 of 9

Hybrid View

  1. #1
    Join Date
    Feb 2011
    Posts
    26


    Did you find this post helpful? Yes | No

    Default Re: Help: how to assign assorted pins to one byte variable

    Heckler, bless your heart.
    Like I said, it would help if I read a bit better --- should go to bed.

    Since your the Teacher then here:

    Question: does your suggestions apply to writing out to the pins as well as reading in from the pins
    From the same pins? Yes, you would read what you set AND any INPUTs -- all assuming the TRIS[a,b,c] are set properly
    If you need to write to other pins and maintain the LEDs then see
    "OTHER_PIN_STATES"

    Yes, these will write directly to the ports.

    Using this order for what you want displayed in a byte
    A1,A2,C0,C1,C2,B4,B5,B6

    And the final value is stored in the LED_OUT a VAR BYTE

    You will need to take care of the TRIS registers.

    Code:
    PortA = (LED_OUT & %00000011) << 1     ' get bits a1, a2 and shift UP 1 to PORTA.1.2
    PortC = (LED_OUT & %00011100) >> 2     ' get bits C0,C1,C2 and shift DOWN 2 to PORTC.0.1.2
    PortB = (LED_OUT & %11100000) >> 1      ' get bits B4,B5,B6 and shift DOWN 1 to PORTB.4.5.6
    "OTHER_PIN_STATES"
    If you need to keep other pins 'On or off' then use
    Code:
     
    PortB = OTHER_PIN_STATES + (LED_OUT & %11100000) >> 1
    Input would be the the reverse.
    Try this for an INPUT
    Using this order
    A1,A2,C0,C1,C2,B4,B5,B6
    Code:
    KEY_8x8 = ((PortA & $06) >> 1) + ((PortC & $07) << 2) + ((PortB & $70) << 1)
    or
    KEY_8x8 = (PortA & %00000110) >> + ((PortC & %00000111) << 2) + ((PortB & %01110000)  << 1)
    PortA.1.2 are extracted and shifted down one to bits %xxxxxxAA
    PortC.0.1.2 are extracted and shifted to up two bits %xxxxBBBxx
    PortB.4.5.6 are extracted and shifted to up one bit %CCCxxxxxx


    OTHER hints be sure to set the -- I keep forgetting then spending to much time finding that goof.
    Code:
     
    
    ' setup the registers and IO PINS
    '— COMPARATOR CONTROL REGISTER -- choose the correct one for your chip :o)
       CMCON = $07  'CMCON — COMPARATOR CONTROL REGISTER  ALL DIGITAL
    'or
    '   CMCON0 = $07  'ALL DIGITAL 12f683 & chips with a2d — COMPARATOR CONTROL REGISTER
    '
    '	ADCON1 = %01100000	' Set a2d convert at clk/6 [slowest]
    '	ADCON1 = %00000000	' Set a2d convert at clk/2 [fastest]
    	ANSEL  = %00000000  ' AN0/RA0 as analog input     1=ANALOG
    	ADCON0 = %00000000	' .7=10bits left justify result!! / .0 1=a2d ON
    and Pull-up the _MCLR PIN !!!!
    Last edited by ofuzzy1; - 6th March 2011 at 06:25.

  2. #2
    Join Date
    Aug 2005
    Posts
    42


    Did you find this post helpful? Yes | No

    Default Re: Help: how to assign assorted pins to one byte variable

    What about this?

    Code:
    YourByte var byte
    YourByte=Value you set
    
    portA.1 = YourByte.Bit0
    portA.2 = YourByte.Bit1
    PortC.0 = YourByte.Bit2
    PortC.1 = YourByte.Bit3
    PortC.2 = YourByte.Bit4
    PortB.4 = YourByte.Bit5
    PortB.5 = YourByte.Bit6
    PortB.6 = YourByte.Bit7
    Cheers

    Sean.
    *********************
    http://www.cncdudez.co.uk
    *********************

  3. #3
    Join Date
    Feb 2011
    Posts
    26


    Did you find this post helpful? Yes | No

    Default Re: Help: how to assign assorted pins to one byte variable

    Quote Originally Posted by sean-h View Post
    What about this?

    Code:
    YourByte var byte
    YourByte=Value you set
    
    portA.1 = YourByte.Bit0
    portA.2 = YourByte.Bit1
    PortC.0 = YourByte.Bit2
    PortC.1 = YourByte.Bit3
    PortC.2 = YourByte.Bit4
    PortB.4 = YourByte.Bit5
    PortB.5 = YourByte.Bit6
    PortB.6 = YourByte.Bit7
    Cheers

    Sean.

    Now that was to easy! Dooh!

    I was wondering this morning how to do the .bit thing

  4. #4
    Join Date
    Oct 2009
    Location
    Utah, USA
    Posts
    427


    Did you find this post helpful? Yes | No

    Default Re: Help: how to assign assorted pins to one byte variable

    I guess the real answer is... NO. There is no way in PBP to define a Variable Aliase that represents the mixed pins of different ports, and then be able to write one word to that aliase and have it go out to the pins. Similar to what you can do with a statement like...

    Code:
    PortC = % 10101010
    Comments to each of the posters in order of reply...

    @ ofuzzy1: Thanks for your persistance... I figured it may come down to brute force programming and shifting / and-ing of bits to get them all set.

    @ sean-h: That looks clean... I wonder if it is any slower or faster than fuzzy's method?

    @ rsocor01: Initially I was planning on using "stripboard or veroboard" so I wanted to minimize the wiring and cutting of traces. I may actually end up making a PCB board and if that is the case I'll surely just use Port C that has all 8 bits.

    thanks everyone...

    This is why I REALLY, REALLY wish that the PBP manual had more "real world" examples. Many of the code syntax definitions are so bare that it is hard to understand the use of them.

    I guess if the manual was TOO GOOD there would be no need for a GREAT forum like this one.

    The Scout Camp is this July... I will be putting together the project in the next few months and when I get it done I'll come back here and post code and pictures.

    Here are a couple of excellent examples I have found:

    http://www.instructables.com/id/Mini...-with-built-i/

    Watch the youtube video!

    http://tinkerlog.com/howto/64pixels/


    Others... please post more ideas if you have them
    Dwight
    These PIC's are like intricate puzzles just waiting for one to discover their secrets and MASTER their capabilities.

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