===== Shift Register ===== Sourced from [[ http://romux.com/tutorials/pic-tutorial/shift-registers | Romux.com ]] Output shift registers transform serial data into parallel data. On every rising edge of the clock, the shift register reads the value from data line, stores it in temporary register, and then repeats this cycle 8 times. On a signal from 'latch' line, data is copied from the shift register to input register, thus data is transformed from serial into parallel data. {{ :electronics:pic:shift_reg_hc595_ovr.jpg?300 |}} An outline of the 74HC595 shift register connections is shown on the diagram below: {{ :electronics:pic:shift_reg_hc595.jpg?500 |}} Macro HC595 has two parameters: HC595 macro Var, Var1 **Var** variable whose contents is transferred to outputs of shift register. **Var1** loop counter Example: HC595 Data, counter The data we want to transfer is stored in data variable, and counter variable is used as a loop counter. HC595 MACRO VAR,VARL LOCAL LOOP ;Local label MOVLW .8 ;Transfer eight bits MOVWF VARL ;Initialising counter RLF VAR,F ;Rotate "Var" on place to the left BTFSS STATUS,C ;Is carry = "1" ? BCF DATAA ;If not, set Dataa line to "0" BTFSC STATUS,C ;Is carry = "0" ? BSF DATAA ;If not, set Dataa line to "1" BSF CLOCK ;Generate one clock NOP BCF CLOCK DECFSZ VARL,F ;Has eight bits been sent ? GOTO LOOP ;If not, repeat BSF LATCH ;If all 8 bits have been sent, NOP ;contents of SHIFT register to send the output latch BCF LATCH ENDM ==== Example ==== /* SOURCE : WWW.ROMUX.COM AUTHOR : romux team */ PROCESSOR 16f84 #include "pl6f84.inc" __CONFIG _CP_0FF & _TODT_0FF & _PWRTE_0N & _XT_0SC CBLOCK 0X0C ;RAM starting address TX ;Belongs to the function "HC595" COUNTSPI ENDC #DEFINE DATAA PORTA, 0 #DEFINE CLOCK PORTA, 1 #DEFINE LATCH PORTA,2 ORG 0X00 ;Reset vector GOTO MAIN ORG 0X04 ;Interrupt vector GOTO MAIN ;no interrupt routine INCLUDE "HC595.INC" MAIN ;Beginning of the program BANKSEL TRISA MOVLW B'00011000' ;Initialising port A MOVWF TRISA ;TRISA <- 0x18 BANKSEL PORTA CLRF PORTA ;PORTA <- 0x00 MOVLW 0XCB ;Fill TX buffer MOVWF TX ;TX <- '11001011' HC595 TX, COUNTSPI LOOP GOTO LOOP ;Remain at this line END ;End of program