PDA

View Full Version : Pointers To Port Pins ?



BitHead
- 23rd December 2009, 02:08
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?

Darrel Taylor
- 23rd December 2009, 04:06
This might help ...

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

BitHead
- 23rd December 2009, 20:38
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.:-)