Indexing Port Pins


Results 1 to 7 of 7

Threaded View

  1. #7
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,154


    Did you find this post helpful? Yes | No

    Default Re: Indexing Port Pins

    Update: Cleaned up logic so LEDs always get same current no matter how many are in use.

    When you need to blink a lot of LEDs:

    Here's the results of a current test using 32 LEDs on a 18F44K22 using internal oscillator at 64MHz.

    Code:
    portLedA    var     PORTA       ' Define Ports
    portLedB    var     PORTB
    portLedC    var     PORTC
    portLedD    var     PORTD
    portLedE    var     PORTE
    
    byteLoop    VAR     byte        ' Define variables
    byteDelay   VAR     byte
    
    byteActiveA var     byte        ' Define active pins
    byteActiveB var     byte
    byteActiveC var     byte
    byteActiveD var     byte
    byteActiveE var     byte
    
    byteRXA     var     byte        ' Define RX data
    byteRXB     var     byte
    byteRXC     var     byte
    byteRXD     var     byte
    byteRXE     var     byte
    
        portLedA = %00000000        ' Initialize Leds off
        portLedB = %00000000
        portLedC = %00000000
        portLedD = %00000000
        portLedE = %00000000
    
     byteActiveA = %11111110        ' Determine Active pins     Pin A.0 not used
     byteActiveB = %11111111
     byteActiveC = %00111111                                  ' RX / TX in use
     byteActiveD = %11111111
     byteActiveE = %00000111                                  ' MCLR input only
    
         byteRXA = %11111110        ' RX data from Master PIC
         byteRXB = %11111111                                    
         byteRXC = %00111111
         byteRXD = %11111111
         byteRXE = %00000111
    
    byteDelay    = 35               ' Tweak this value to control current and frequency
    
    ' 1 LED active        668 Hz     2.7 mA LED    14.2 mA circuit
    ' 32 LEDs active      668 Hz     2.7 mA LED    99.0 mA circuit
    
    ' Using 2N2222 NPN transistor, 4K7 base with 680K pull-down,
    '       LED direct to collector from 5VDC.
    
    mainloop:
    
        For byteLoop = 0 to 7                       ' Go through 8 bits
            if byteActiveA.0[byteLoop] = 1 then     ' Check if pin is used
                portLedA.0[byteLoop] = byterxA.0[byteLoop]
                PAUSEUS byteDelay
                portLedA = %00000000                ' Faster than setting bit to 0
            endif
            if byteActiveB.0[byteLoop] = 1 then
                portLedB.0[byteLoop] = byterxB.0[byteLoop]
                PAUSEUS byteDelay
                portLedB = %00000000
            endif
            if byteActiveC.0[byteLoop] = 1 then
                portLedC.0[byteLoop] = byterxC.0[byteLoop]
                PAUSEUS byteDelay
                portLedC = %00000000
            endif
            if byteActiveD.0[byteLoop] = 1 then
                portLedD.0[byteLoop] = byterxD.0[byteLoop]
                PAUSEUS byteDelay
                portLedD = %00000000
            endif
            if byteActiveE.0[byteLoop] = 1 then
                portLedE.0[byteLoop] = byterxE.0[byteLoop]
                PAUSEUS byteDelay
                portLedE = %00000000
            endif
        Next byteLoop
    
        Goto mainloop           ' Go back to loop and blink LEDs forever
    Use byteActiveA-E variables to determine which bits you want toggled.

    Use byteRXA-E variables to receive bits from a Master PIC.

    Use byteDelay variable to tweak current and LED brightness.


    For my testing, MCLR (can only be input), RX/TX (needed) and A0 (unused) were disabled.

    Robert

    Last edited by Demon; - 6th January 2014 at 05:48. Reason: picture and updated code

Similar Threads

  1. Pointers To Port Pins ?
    By BitHead in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 23rd December 2009, 20:38
  2. Change On Interrupt, PIC16F884
    By elec_mech in forum mel PIC BASIC Pro
    Replies: 17
    Last Post: - 14th November 2008, 17:25
  3. Another question RE port line indexing
    By muddy0409 in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 7th August 2007, 15:23
  4. Microcontroller with 2 way paging application problem
    By oneohthree in forum mel PIC BASIC Pro
    Replies: 30
    Last Post: - 20th April 2007, 17:27
  5. PIC PORT 'special' pins
    By barkerben in forum General
    Replies: 1
    Last Post: - 18th January 2005, 21:40

Members who have read this thread : 3

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