;************************************************************************************************************************************* ;* * ;* Serial output routine - using cascaded SR's (2x 4096 SR's) * ;* version 1.0.28 (aggggggh) 21 Oct 2012 * ;* Using devicde type PIC12F509 * ;* * ;* (pin 1) Vdd +5vDC. (pin 8) Vss 0v/Gnd. * ;* (pin 2) GPIO_b5 Unused (pin 7) GPIO_b0 STROBE * ;* (pin 3) GPIO_b4 CLOCK (pin 6) GPIO_b1 Unused * ;* (pin 4) GPIO_b3 Unused (pin 5) GPIO_b2 DATA out * ;* * ;* expanded I/O driver routine has been tested on PIC12F509, but should work on most of PIC range with appropriate memory mapping * ;* for output shift register use CD4096, for input shift register use 74HC165, for CMOS/TTL converter use CD4504 * ;* routine duration 215uS @ 4MHz * ;************************************************************************************************************************************* ;************************************* ;* System variables * ;************************************* EXP_IO_BIT_COUNT equ H'0007' ; Expanded I/O bit counter. EXP_IO_BYTE_COUNT equ H'0008' ; Expanded I/O byte counter. EXP_IO_TMP equ H'0009' ; Expanded I/O temporary byte. EXP_IO_OUT_BYTE_1 equ H'000A' ; Expanded I/O output byte 1. EXP_IO_OUT_BYTE_2 equ H'000B' ; Expanded I/O output byte 2. ;************************************* ;* System variables * ;************************************* STB equ H'0000' ; GPIO_b0 Output - Output SR - Strobe D_out equ H'0002' ; GPIO_b2 Output - Output SR - Data CLK equ H'0004' ; GPIO_b4 Output - Common - Clock ;************************************* ;* Expanded output driver routine * ;************************************* WEO movlw H'0008' ; Common I/O Reset EXP_IO_BIT_COUNT - must be set to eight. movwf EXP_IO_BIT_COUNT ; Common I/O - "" - movf EXP_IO_BYTE_COUNT,W ; Common I/O Check EXP_IO_OUT_BYTE_COUNT state btfss STATUS,Z ; Common I/O - "" - goto WEO_#2 ; Common I/O - "" - movlw H'0002' ; Common I/O THEN Reset EXP_IO_OUT_BYTE_COUNT - number of SR's movwf EXP_IO_BYTE_COUNT ; Common I/O in this example we are using two cascaded SR's WEO_#2 movf EXP_IO_BYTE_COUNT,W ; Output Fetch data BYTE to be sent to SR's during the current cycle... addwf PCL,F ; Output - "" - nop ; Output - "" - goto WEO_#3 ; Output - "" - goto WEO_#4 ; Output - "" - WEO_#3 movf EXP_IO_OUT_BYTE_1,W ; Output EXP_IO_OUT_BYTE_1 goto WEO_#7 ; Output - "" - WEO_#4 movf EXP_IO_OUT_BYTE_2,W ; Output EXP_IO_OUT_BYTE_2 WEO_#7 movwf EXP_IO_TMP ; Output - "" - WEO_BIT rrf EXP_IO_TMP,F ; Common I/O I/O bit processor - rotate right btfss STATUS,C ; Output test "STATUS,C" state goto WEO_BIT_#2 ; Output - "" - bsf GPIO,D_out ; Output THEN set "GPIO,D_out" if "STATUS,C" is set goto WEO_BIT_#3 ; Output - "" - WEO_BIT_#2 bcf GPIO,D_out ; Output ELSE clr "GPIO,D_out" if "STATUS,C" is clr WEO_BIT_#3 bsf GPIO,CLK ; Common I/O Generate a single clock pulse of 1uS duration… nop ; Common I/O - "" - bcf GPIO,CLK ; Common I/O - "" - decfsz EXP_IO_BIT_COUNT,F ; Common I/O Decrement EXP_IO_BYTE_COUNT, and test for zero status. goto WEO_BIT ; Common I/O return to Bit processor (WEO_BIT) or, continue & finish... WEO_#D decfsz EXP_IO_BYTE_COUNT,f ; Common I/O Decrement and check EXP_IO_OUT_BYTE_COUNT state... goto WEO ; Common I/O THEN Return to main programme loop if NZ bsf GPIO,STB ; Output ELSE Initiate latch sequence before Return if Z... nop ; Output - "" - bcf GPIO,STB ; Output - "" - retlw H'0000' ; Common I/O - "" -