Originally Posted by
Joe Rocci
Darrel,
Can you post an example of how you'd implement that in PBP?
Thanks
Joe
I can.
First let me say that ASM is a very BIG part of PicBasic Pro.
It's the Glue that binds everything together.
Ignoring ASM, and pretending it's not part of PBP simply deprives you of the easiest ways to do exactly what you want, without having to find some basackwards way to get around your problems.
OK, now that the commercials over ...<hr>
20uS shift @ 40Mhz. With 18F's ONLY!
Using a large Circular buffer.
Variable length Shift up to 2032 bits.
Basic Language ONLY ...
Code:
<font color="#0000FF"><b><i>'***************************************************************************
'* Name : 1000Bits.pbp *
'* Author : Darrel Taylor *
'* Date : 4/17/2009 *
'* Version : 1.1 *
'* Notes : Requires an 18F *
'* : 20uS ~shift at 40Mhz, 40uS @ 20Mhz *
'***************************************************************************
</i></b></font><font color="#000080">@ __CONFIG _CONFIG1H, _OSCS_OFF_1H & _HSPLL_OSC_1H
</font><font color="#008000"><b>DEFINE </b></font><b>OSC </b><font color="#800000"><b>40
</b></font><font color="#008000"><b>CLEAR
</b></font><b>BufferBits </b><font color="#008000"><b>CON </b></font><font color="#800000"><b>1000 </b></font><font color="#0000FF"><b><i>; max 2032
</i></b></font><b>BufferBytes </b><font color="#008000"><b>CON </b></font><b>BufferBits </b>/ <font color="#800000"><b>8 </b></font>+ <font color="#800000"><b>1 </b></font><font color="#0000FF"><b><i>; number of BYTEs required for buffer
</i></b></font><b>Buffer </b><font color="#008000"><b>VAR BYTE</b></font>[<b>BufferBytes</b>] <font color="#0000FF"><b><i>; The Buffer Array
</i></b></font><b>ShiftSize </b><font color="#008000"><b>VAR WORD </b></font><font color="#0000FF"><b><i>; Variable sized Shift at run-time
</i></b></font><b>INptr </b><font color="#008000"><b>VAR WORD </b></font><font color="#0000FF"><b><i>; Points to the IN bit of the array
</i></b></font><b>OUTptr </b><font color="#008000"><b>VAR WORD </b></font><font color="#0000FF"><b><i>; Points to the OUT bit of the array
</i></b></font><b>BuffPtr </b><font color="#008000"><b>VAR BYTE </b></font><font color="#0000FF"><b><i>; Points to the BYTE in the buffer
</i></b></font><b>BitPtr </b><font color="#008000"><b>VAR BYTE </b></font><font color="#0000FF"><b><i>; Points to the BIT in the byte
</i></b></font><b>TempB </b><font color="#008000"><b>VAR BYTE </b></font><font color="#0000FF"><b><i>; temporary byte variable
</i></b></font><b>BITin </b><font color="#008000"><b>VAR </b></font><b>PORTB</b>.<font color="#800000"><b>0 </b></font><font color="#0000FF"><b><i>; The BIT being shifted IN
</i></b></font><b>BITout </b><font color="#008000"><b>VAR </b></font><b>PORTB</b>.<font color="#800000"><b>1 </b></font><font color="#0000FF"><b><i>; The BIT being shifted OUT
</i></b></font><b>ShiftSize </b>= <font color="#800000"><b>800 </b></font><font color="#0000FF"><b><i>; Any Size - up to BufferBits
</i></b></font><font color="#008000"><b>GOSUB </b></font><b>ResizeBuffer </b><font color="#0000FF"><b><i>; setup the Pointers
</i></b></font><font color="#008000"><b>GOSUB </b></font><b>ClearBuffer </b><font color="#0000FF"><b><i>; Set buffer to all 0's
</i></b></font><font color="#008000"><b>INPUT </b></font><b>BITin </b><font color="#0000FF"><b><i>; Input pin
</i></b></font><font color="#008000"><b>LOW </b></font><b>BITout </b><font color="#0000FF"><b><i>; Output pin
;---------------------------------------------------------------------------
</i></b></font><b>Main</b>:
<font color="#008000"><b>GOSUB </b></font><b>ShiftBits
</b><font color="#008000"><b>PAUSEUS </b></font><font color="#800000"><b>80
</b></font><font color="#008000"><b>GOTO </b></font><b>Main
</b><font color="#0000FF"><b><i>;---------------------------------------------------------------------------
</i></b></font><b>ShiftBits</b>:
<b>INptr </b>= <b>INptr </b>+ <font color="#800000"><b>1 </b></font><font color="#0000FF"><b><i>; Increment IN pointer
</i></b></font><font color="#008000"><b>IF </b></font><b>INptr</b>.<b>LowByte </b>= <b>ShiftSize</b>.<b>LowByte </b><font color="#008000"><b>Then </b></font><font color="#0000FF"><b><i>; IF past end of buffer?
</i></b></font><font color="#008000"><b>IF </b></font><b>INptr</b>.<b>HighByte </b>= <b>ShiftSize</b>.<b>HighByte </b><font color="#008000"><b>Then
</b></font><b>INptr </b>= <font color="#800000"><b>0 </b></font><font color="#0000FF"><b><i>; Wrap to beginning
</i></b></font><font color="#008000"><b>ENDIF
ENDIF
</b></font><b>OUTptr </b>= <b>OUTptr </b>+ <font color="#800000"><b>1 </b></font><font color="#0000FF"><b><i>; Increment OUT pointer
</i></b></font><font color="#008000"><b>IF </b></font><b>OUTptr</b>.<b>LowByte </b>= <b>ShiftSize</b>.<b>LowByte </b><font color="#008000"><b>Then </b></font><font color="#0000FF"><b><i>; IF past end of buffer?
</i></b></font><font color="#008000"><b>IF </b></font><b>OUTptr</b>.<b>HighByte </b>= <b>ShiftSize</b>.<b>HighByte </b><font color="#008000"><b>Then
</b></font><b>OUTptr </b>= <font color="#800000"><b>0 </b></font><font color="#0000FF"><b><i>; Wrap to beginning
</i></b></font><font color="#008000"><b>ENDIF
ENDIF
</b></font><font color="#0000FF"><b><i>; --- Put new BIT into the Buffer ------------
</i></b></font><b>BuffPtr </b>= <b>INptr </b>>> <font color="#800000"><b>3 </b></font><font color="#0000FF"><b><i>; Which BYTE in the buffer
</i></b></font><b>BitPtr </b>= <b>INptr </b>& <font color="#800000"><b>%111 </b></font><font color="#0000FF"><b><i>; Which BIT in the byte
</i></b></font><b>TempB </b>= <b>Buffer</b>(<b>BuffPtr</b>) <font color="#0000FF"><b><i>; retrieve the byte
</i></b></font><b>TempB</b>.<font color="#800000"><b>0</b></font>(<b>BitPtr</b>) = <b>BITin </b><font color="#0000FF"><b><i>; store the bit
</i></b></font><b>Buffer</b>(<b>BuffPtr</b>) = <b>TempB </b><font color="#0000FF"><b><i>; put byte back in buffer
; --- Get old BIT from the Buffer ------------
</i></b></font><b>BuffPtr </b>= <b>OUTptr </b>>> <font color="#800000"><b>3 </b></font><font color="#0000FF"><b><i>; Which BYTE in the buffer
</i></b></font><b>BitPtr </b>= <b>OUTptr </b>& <font color="#800000"><b>%111 </b></font><font color="#0000FF"><b><i>; Which BIT in the byte
</i></b></font><b>TempB </b>= <b>Buffer</b>(<b>BuffPtr</b>) <font color="#0000FF"><b><i>; retrieve the byte
</i></b></font><b>BITout </b>= <b>TempB</b>.<font color="#800000"><b>0</b></font>(<b>BitPtr</b>) <font color="#0000FF"><b><i>; output the BIT
</i></b></font><font color="#008000"><b>RETURN
</b></font><font color="#0000FF"><b><i>;---------------------------------------------------------------------------
</i></b></font><b>ResizeBuffer</b>:
<b>ShiftSize </b>= <b>ShiftSize </b><font color="#008000"><b>MIN </b></font><b>BufferBits </b><font color="#0000FF"><b><i>; limit to buffer size
</i></b></font><b>INptr </b>= <b>ShiftSize </b>- <font color="#800000"><b>1 </b></font><font color="#0000FF"><b><i>; buffer starting point
</i></b></font><b>OUTptr </b>= <font color="#800000"><b>0 </b></font><font color="#0000FF"><b><i>; out bit starts at 0
</i></b></font><font color="#008000"><b>RETURN
</b></font><font color="#0000FF"><b><i>;---------------------------------------------------------------------------
</i></b></font><b>ClearBuffer</b>:
<font color="#008000"><b>FOR </b></font><b>TempB </b>= <font color="#800000"><b>0 </b></font><font color="#008000"><b>to </b></font><b>BufferBytes - 1
Buffer</b>(<b>TempB</b>) = <font color="#800000"><b>0
</b></font><font color="#008000"><b>NEXT </b></font><b>TempB
</b><font color="#008000"><b>RETURN
</b></font>
Bookmarks