Today 14:15
Forum: Absolute Beginners Section
Starter: amod
Views: 0
Replies: 29
Today 14:11
Forum: The Lounge
Starter: pic-ignorant
Views: 0
Replies: 2
Today 09:28
Forum: Website / Forum Issues
Starter: rcurl
Views: 0
Replies: 4
Yesterday 21:12
Forum: Proton Plus Compiler v3
Starter: Dave-S
Views: 0
Replies: 3
+ Reply to Thread
Results 1 to 8 of 8

Thread: Remapping port pins and 16 bit port320 days old

  1. #1
    Prolific Poster RGV250's Avatar
    Join Date
    Aug 2005
    Posts
    2,199
    Thumbs Up
    Received: 29
    Given: 7
    Total Downloaded
    456.72 MB

    0 Not allowed!

    Default Remapping port pins and 16 bit port

    Hi,
    Hopefully the title explains what I am trying to do.
    I believe Les posted how to do this a while ago but I cannot find it.
    In the instance I am thinking of here I believe there was a request to make a "virtual" 16 bit port on an 8bit device and map the pins so they were sequential.
    I am looking at the "LOL shield" https://solarbotics.com/product/39260/ which has 126 LED's and uses 12 pins and charlieplexing to control them.
    I will be using the Amicus18 board and hope to make Port B & C a 16bit port so I can write to it in one go. I am only just looking at the board now but I may need to alter the sequence of the pins on the fly, not sure on that yet.

    Regards,
    Bob

  2. #2
    Fanatical Contributor Les's Avatar
    Join Date
    Feb 2002
    Posts
    3,017
    Thumbs Up
    Received: 309
    Given: 114
    Total Downloaded
    1.51 GB

    1 Not allowed!

    Default Re: Remapping port pins and 16 bit port

    Combining 2 8-bit variables into a 16-bit variable is possible, and because ports are, essentially, SFR variables, the same principle applies. Below is a simple demo showing how to combine PORTB and PORTC into a 16-bit pseudo port. Remember, Input, Output, Low, and High only work on 8-bit ports, so I have created simple defines to operate them.

    To Set or Clear bits of the 16-bit port, you can use the Set, Clear, SetBit, or Clearbit commands, and GetBit etc to read them. Or if it is a constant bit value, use Port16.Bit

    Hopefully, you will get the idea of it from the example below:

    Also, remember, you can do the same with TRISB and TRISC, and maybe call the defines Tris16.

    The beauty of using the defines is that they do not make code overheads, so accessing Port16 is the same as accessing PORTB or PORTC.

    Code:
        Device = 18F25K20
        Declare Xtal= 64 
        
        Dim bIndex As Byte  ' Create a variable for the demo  
    '
    ' Create a 16-bit port from PORTB and PORTC
    '    
        Dim U_Port16 As PORTB           ' Create the underlying low port
        Dim U_Port16H As PORTC          ' Create the underlying high port       
        Dim Port16 As U_Port16.Word     ' Combine them into a single 16-bit variable
    '
    ' Create some defines to seperate each 8-bit port
    '
    $define Low_Port16 PORTB
    $define High_Port16 PORTC
    
    '-----------------------------------------------------
    ' Set the 16-bit port to input
    '
    $define Input16()    '
        Input Low_Port16 '
        Input High_Port16
        
    '-----------------------------------------------------
    ' Set the 16-bit port to output
    '
    $define Output16()    '
        Output Low_Port16 '
        Output High_Port16
          
    '-----------------------------------------------------
    ' Set the 16-bit port to output low
    '
    $define Low16()    '
        Low Low_Port16 '
        Low High_Port16
           
    '-----------------------------------------------------
    ' Set the 16-bit port to output high
    '
    $define High16()    '
        High Low_Port16 '
        High High_Port16 
        
    '-----------------------------------------------------    
    ' A simple demo of the above
    '
    Main:
        Low16()                     ' Make the 16-bit port output low
    '
    ' Set the pins high, sequentially
    '    
        For bIndex = 0 To  15 
            SetBit Port16, bIndex  ' Make each pin high  
            DelayMS  100 
        Next   
    '
    ' Set the pins low, sequentially
    '    
        For bIndex =  0  To  15 
            ClearBit Port16, bIndex  ' Make each pin low  
            DelayMS  100 
        Next 
    '
    ' Set the pins using a constant bit value
    '
          Set Port16.0
        Set Port16.1
        Set Port16.2
        Set Port16.3
        Set Port16.4
    '
    ' Alter pins of the port
    '
        Port16 = % 0000111100001111
    Last edited by joesaliba; 4th January 2018 at 21:09.
    For more example programs for Proton and Proton24 or updates, please visit: Proton WIKI or Proton Files

  3. #3
    Prolific Poster RGV250's Avatar
    Join Date
    Aug 2005
    Posts
    2,199
    Thumbs Up
    Received: 29
    Given: 7
    Total Downloaded
    456.72 MB

    0 Not allowed!

    Default Re: Remapping port pins and 16 bit port

    Hi Les,
    just the job, thanks.

    Bob

  4. #4
    Fanatical Contributor Les's Avatar
    Join Date
    Feb 2002
    Posts
    3,017
    Thumbs Up
    Received: 309
    Given: 114
    Total Downloaded
    1.51 GB

    0 Not allowed!

    Default LOL Shield interfacing on an Amicus18 board

    You're very welcome Bob

    Did you see the Wiki article I wrote for the LOL shield? It's a neat board, but it does have problems with illumination sometimes, because Charlieplexing is a method of getting as much out of a few pins as possible, and it does have its efficiency issues because of the multiplexing that is constantly going on. But it's fun to use.

    LOL Shield interfacing on an Amicus18 board
    For more example programs for Proton and Proton24 or updates, please visit: Proton WIKI or Proton Files

  5. #5
    Prolific Poster RGV250's Avatar
    Join Date
    Aug 2005
    Posts
    2,199
    Thumbs Up
    Received: 29
    Given: 7
    Total Downloaded
    456.72 MB

    0 Not allowed!

    Default Re: Remapping port pins and 16 bit port

    Hi Les,
    Thanks for the link, I had not thought of looking.
    I am a little disappointed as I had looked forward to the challenge especially after you has said about copy and pasting other peoples code.
    Anyway, I am sure it would not have been as neat as yours or if it would have worked at all. I had a different approach for the lookup table for the LEDs, I planned to have a Dword for each LED, the first 16 bits would be the Tris and the second 16 would be the direction.


    Example for LED 13 & 14
    Tris register -------------- Direction register
    11111111 11111111 / 00000000 00000000, all inputs so LED off
    /
    /
    11011111 11111011 / 10000000 00000000, Make B.2 and C.5 outputs / Set B.2 LED 13 = On
    11011111 11111011 / 00000000 00000001, Make B.2 and C.5 outputs / Set C.5 LED 14 = On
    /
    /
    And so on.

    I might still try to see if it would have worked as planned.

    Regards,
    Bob

  6. #6
    Fanatical Contributor Les's Avatar
    Join Date
    Feb 2002
    Posts
    3,017
    Thumbs Up
    Received: 309
    Given: 114
    Total Downloaded
    1.51 GB

    0 Not allowed!

    Default Re: Remapping port pins and 16 bit port

    As long as the code gives you ideas Bob, that's the main thing. Using the library to create your own projects is fun, and by all means, add to the library, or change the way it works etc... Because I always add a lot of comments in my code, hopefully, it will give you an idea as to how it works, so the library file can be improved.

    How about creating a Pacman game on the LED matrix, or other games etc... Then it becomes both instructive and fun!

    Everyday life involves a form of copying and pasting in most things. Even learning does. LOL. So as long as the whole thing is not copied and pasted, then broadcast as "look what I've done", which seems to be the common thing now on social media sites, using the code as a learning tool and adapting things to suit, is normal. Not that you would, or any other user on this forum, but it seems to be the normal state of things in both the commercial world, and youtube is full of exactly the same things done by different people using the same code and hardware, with "look what I've done, aren't I clever and creative", yet they've copied and pasted 100% and actually done very little. Also, not everything I write is the correct way of doing things, so learning from the code and understanding the hardware is 100% OK. Then hopefully making the library better or more features added.

    Anyway Rant over, and future rants curbed. LOL and get into the LOL shield and learn about charlieplexing. It's a very clever concept, but does have some flaws, but is so fun to work with.
    Last edited by Les; 5th January 2018 at 16:52.
    For more example programs for Proton and Proton24 or updates, please visit: Proton WIKI or Proton Files

  7. #7
    Prolific Poster joesaliba's Avatar
    Join Date
    Sep 2004
    Posts
    2,359
    Thumbs Up
    Received: 85
    Given: 23
    Total Downloaded
    4.03 GB

    1 Not allowed!

    Default Re: Remapping port pins and 16 bit port

    The code submitted by Les in post #2 is now in the Wiki area so it does not get lost: -

    Port Expander
    Regards

    Joseph

  8. #8
    Fanatical Contributor Les's Avatar
    Join Date
    Feb 2002
    Posts
    3,017
    Thumbs Up
    Received: 309
    Given: 114
    Total Downloaded
    1.51 GB

    0 Not allowed!

    Default Re: Remapping port pins and 16 bit port

    Thanks Joseph.

    Here's a really nice board for the Amicus Bob for charlieplexing, and it is not the standard LOL shield, because it is a whole less expensive and uses different pins etc for the charlieplexing. At only 2.95 for the board, the LEDs, and the connectors, it is a bargain! OK, you have to wait a few weeks for delivery from China, but for the money it is amazing!

    It would be great to see a library for that board so we can show future users what they can really do with Proton and an Amicus board.

    DIY Kit Blue light LOL Shield Matrix Lots LEDs

    leds matrix.jpg
    Last edited by Les; 5th January 2018 at 20:26.
    For more example programs for Proton and Proton24 or updates, please visit: Proton WIKI or Proton Files

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Similar Threads

  1. Alias port pins
    By RGV250 in forum Proton Plus Compiler v3
    Replies: 5
    Last Post: 12th August 2017, 18:21
  2. Replies: 4
    Last Post: 2nd May 2016, 15:10
  3. Port pins changing - RFM12B
    By Dave-S in forum Proton Plus Compiler v3
    Replies: 0
    Last Post: 16th April 2013, 18:15
  4. Non-contiguous port pins and array addressing
    By Don Stratton in forum Proton Plus Compiler v3
    Replies: 7
    Last Post: 28th June 2008, 17:20
  5. Alpha LCD Port pins
    By Jamil in forum Proton Plus Compiler v3
    Replies: 2
    Last Post: 7th March 2008, 00:36

Members who have read this thread since 31st October 2018, 13:50 : 0

Actions :  (Set Date)  (Clear Date)

You do not have permission to view the list of names.

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