Help: how to assign assorted pins to one byte variable


Closed Thread
Results 1 to 9 of 9
  1. #1
    Join Date
    Oct 2009
    Location
    Utah, USA
    Posts
    427

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

    I'm sure this is a case of "can't see the forest for the trees". I have searched and read but can not for the life of me understand the following:

    I am designing a project for a Boy Scout electronics merit badge. I need to keep the circut wiring simple, therefore I want to use the pins of the 16F690 PIC as they are physically oriented on the PIC package.

    I want to use A1,A2,C0,C1,C2,B4,B5,B6 as the column of an 8x8 led matrix.
    How do I assign those unrelated pins to one 8 bit variable?
    I think it must have something to do with the use of ALIASES??

    Thanks in advance. I think there must be some thick fog in the old gray matter.
    (and the fact that I only dabble in programming)
    Dwight
    These PIC's are like intricate puzzles just waiting for one to discover their secrets and MASTER their capabilities.

  2. #2
    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? please

    Anybody??

    Or is it not possible??

    Mabie I should elaborate...

    I would hope it is possible to define which PIC pins are assigned to a column (or row for that matter) and in what order. Then just do a "CASE" type lookup of the various elements of whatever I want to display on the 8x8 LED matrix, and write them to the 8 bit Alias that is connected to the display.

    If It is not possible... then does one just have to individually set or clear each pin in the 8 bit word and then "turn on" the corresponding row or column to light up that part of whatever I want to display?

    I understand how to do it if I were to use the 8 bits sequentially of a given 8 bit port, like PortA, but I want to "mix and match" which pins represent each of the 8 bits and then define an Alias that I can write the code to.

    Any help would be greatly appreciated.
    (I wish the PBP manual had more real world examples, hint to ME labs for their next printing)
    Dwight
    These PIC's are like intricate puzzles just waiting for one to discover their secrets and MASTER their capabilities.

  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

    Congrats on your Efforts of working on your Eagle Scout !!

    You know it would help if I really read the question, the following is how I did an INPUT from a DIP Switch.

    I did this using a 12f683 -- needed the _MCR working otherwise GPIO.3 would of been handy.
    12f683 has 6 I/O pins

    Code:
    DIP_ =  (gpio & $07) + (GPIO.4 * $08)  ' Read GPIO.0.1.2.4 & MAKE IT BCD /hex4
    I was going to give you the code, but since it is for your Eagle project I will give you HINTS.
    ** If you are stumped then message me and I will gladly give you the code - you can do it in 3 lines **

    HINTS
    0. Store the final value you want in a BYTE VAR ... LED_OUT
    1. Extract the bits for each part using LED_OUT & %00000011 .... ???
    2. Shift the result up or down to where you need them; using ">>" [hint use parentheses to keep things tidy]

    Code:
    PORTx= LED_OUT &  %00000011 .... ???
    Last edited by ofuzzy1; - 6th March 2011 at 02:35.

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


    Did you find this post helpful? Yes | No

    Red face Re: Help: how to assign assorted pins to one byte variable

    NO, NO!!

    I am the one TEACHING the electronics merit badge. I have been doing electronics for many years as a hobby AND I work in electronics (mostly microwave communications)

    Alas, I am not the greatest programmer... I would love to spend more time programming and playing with the PIC micro's. But I have a day job and kids...

    The merit badge just requires the Scouts to build a simple electronic project. I really want to expose them to the wonderful world of microcontrollers. I realize they won't be able to understand all the programming at this point. But, if I can get them to heat up a soldering iron and build a neat scrolling text "necerchief slide" they might just get hooked on electronics and even a great career. I do plan on explaining the basics of the program, though.

    I need to keep the wiring simple... so I want to just use 8 pins on each side of the 16f690 in the order they come off the chip. So I need to be able to write an 8 bit word to the 8 somewhat unrelated port pins (as detailed above).

    Thanks for your reply... I will take time to decipher your hints...

    Question: does your suggestions apply to writing out to the pins as well as reading in from the pins? Please, more detail if possible.

    And others... please chime in here I need all the help I can get.

    I have not recieved the 8x8 LED matrix yet or I would post my schematic. I just need to figure out if it is possible to write an 8bit word to 8 mixed pins at one time.

    Thanks
    Dwight
    These PIC's are like intricate puzzles just waiting for one to discover their secrets and MASTER their capabilities.

  5. #5
    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 07:25.

  6. #6
    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
    *********************

  7. #7
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    657


    Did you find this post helpful? Yes | No

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

    Quote Originally Posted by Heckler View Post
    I need to keep the wiring simple... so I want to just use 8 pins on each side of the 16f690 in the order they come off the chip. So I need to be able to write an 8 bit word to the 8 somewhat unrelated port pins (as detailed above).
    Hmmm, why don't you use 8 pins from the same port (ex: PORTB.0, PORTB.1, ...., PORTB.7) and practice your wiring skills. If you are trying to etch a board, it is not that difficult to do if you use the right techniques.
    "No one is completely worthless. They can always serve as a bad example."

    Anonymous

  8. #8
    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

  9. #9
    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