Pointers To Port Pins ?


Closed Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    Dec 2009
    Posts
    5

    Default Pointers To Port Pins ?

    LET'S PRETEND I'm trying to control the brightness of SIX 'AC line' lights the 'Pic port to optocoupler at zero-crossing time' way. The assembler in me says 'load a byte from a look-up table of duty-cycle-bytes and with each transition of the AC line, rotate thru carry, with carry going to the appropriate PORTC bit, for each of PORTC's pins, and then wait.
    I'd like to try to do it the high-level PicBasic 'increment the pointer' way.
    I.e.,
    1) Use a pointer byte (PortPtr) to select the duty-cycle bytes from an array variable (DutyCycle VAR BYTE(6) - (1 per pin) ).
    2) Use another pointer byte (BitPtr) to point to the bits in those bytes and then...
    3) Set PORTC's pins using PortPtr.

    Kind of like if ...
    PORTC.PortPtr = DutyCycle(PortPtr).BitPtr
    ... worked.

    OF course, I'm here for a reason.;-)
    How would YOU do that without using individual port pin statements?

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    This might help ...

    Indexing Port Pins (Bruce)
    http://www.picbasic.co.uk/forum/showthread.php?t=3753
    DT

  3. #3
    Join Date
    Dec 2009
    Posts
    5


    Did you find this post helpful? Yes | No

    Default Pointers To Port Pins - YES!

    Thanks Darrel!

    For those who just want to know now, the essential elements revealed by Bruce in that link are...
    __________
    SYMBOL PORT_PIN = PORTB

    FOR X = 0 TO 15 ' 16-bits total
    PORT_PIN.0[X] = 1 ' Set all portb, and portc pins high
    NEXT X
    __________

    which I'll translate to...

    SYMBOL PORT_PIN = PORTC
    X VAR BYTE
    DCB VAR BYTE ;for 'Duty Cycle Bit' from AC line 0-Xing counter.
    DCM VAR BYTE ;for Duty Cycle Mask - bit discriminator.
    ;(DutyCycle(0-5) previously loaded with desired values.)
    ;(On AC line 0-Xing : DCB=((DCB+1) && $07)

    Lookup DCB,[$01,$02,$04,$08,$10,$20,$40,$80],DCM

    FOR X = 0 TO 5 ' 6-pins - RC0-RC5
    IF DCM || DutyCycle(X) THEN
    ;Is 'NOT ZERO = TRUE' implied? Or do I have to spell it out with a ' <> 0 ' ?
    PORT_PIN.0[X] = 1 ' Set portc pin high
    ELSE ;(Yes - I have PBPro)
    PORT_PIN.0[X] = 0 ' Set portc pin low
    ENDIF
    NEXT X

    Qualifier - I haven't tried it yet - just whipped this up in the middle of responding. If anyone knows something - like a more efficient means of doing the 'bit test', feel free to speak up.:-)

Similar Threads

  1. Indexing Port Pins
    By Bruce in forum Code Examples
    Replies: 6
    Last Post: - 5th January 2014, 08:31
  2. Change On Interrupt, PIC16F884
    By elec_mech in forum mel PIC BASIC Pro
    Replies: 17
    Last Post: - 14th November 2008, 17:25
  3. Aliasing a port with arbitrary I/O pins?
    By Jayhovah in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 19th May 2008, 15:09
  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 : 1

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