SERIAL2PARALLEL ;using 74HC595 IC ;input, serial_byte4, serial_byte3, serial_byte2, serial_byte1, serial_byte0 ;output, display bytes from 74LS595 serial to parallel logic IC #define s2p_serial_data_out PORTA,3 #define s2p_serial_clock PORTA,4 #define s2p_latch_clock PORTA,5 _SWITCH_BANK 0 BSF s2p_serial_clock ;initialise the serial clock BSF s2p_latch_clock ;initialise the latch clock ;{loop rountine to loop through all the bits in the defined number of byte ;{loop rountine to do left rotate for all the bytes to check starting from the MSB bit MOVLW SERIAL_BYTE_SIZE ;counting loop to determine the number of bytes that need to have the bits shifted BANKSEL serial_bytesize_count ;bank select for direct addressing MOVWF serial_bytesize_count CLRW S2P_SERIAL_BYTE_COUNT0 ADDLW 0x08 DECFSZ serial_bytesize_count,F GOTO S2P_SERIAL_BYTE_COUNT0 ;counting loop back ;} ADDLW d'1' ;add in one more loop to rotate data back to their original memory location MOVWF serial_bitsize_count ;compute the number of bits required to rotate S2P_SERIAL_BIT_COUNT ;{loop rountine to do left rotate for all the bytes to check starting from the MSB bit MOVLW serial_byte0 ;find out the base address MOVWF FSR ;load base address MOVLW SERIAL_BYTE_SIZE ;counting loop to determine the number of bytes that need to have the bits shifted BANKSEL serial_bytesize_count ;bank select for direct addressing MOVWF serial_bytesize_count ; _SWITCH_BANK 0 ; BCF STATUS,0 ;check previous data bit shifted out ; BTFSC serial_data ;set the previous shifted bit back to the carry bit position ; BSF STATUS,0 ;to be shifted back to the data memory S2P_SERIAL_BYTE_COUNT1 BANKISEL serial_byte0 ;bank select for indirect addressing RLF INDF,F INCF FSR,F BANKSEL serial_bytesize_count DECFSZ serial_bytesize_count,F GOTO S2P_SERIAL_BYTE_COUNT1 ;counting loop back ;} DECFSZ serial_bitsize_count,F GOTO SERIAL2PARALLEL_SERIALCLOCK ;proceed to do serial clock GOTO SERIAL2PARALLEL_END ;last rotation, rotates the data back to their location and does not need any serial clocking SERIAL2PARALLEL_SERIALCLOCK ;MSB now shifted to the STATUS bit 0 _SWITCH_BANK 0 ;setting serial data to the output serial data line BCF s2p_serial_data_out BTFSC STATUS,0 ;check the rotated out bit from the MSB BSF s2p_serial_data_out BCF s2p_serial_clock ;initialise the serial clock BSF s2p_serial_clock ;clock the serial data in on positive edge GOTO S2P_SERIAL_BIT_COUNT ;counting loop back ;} SERIAL2PARALLEL_END _SWITCH_BANK 0 ;setting serial data to the output serial data line BCF s2p_latch_clock ;initialise the latch clock BSF s2p_latch_clock ;clock latch the clocked serial data on positive edge ;serial_clock or latch_clock should be at logic 1 at any one time so that output will not be disturbed ;the two clock line should not be at logic 0 at the same time or else the output will be affected by the data line. RETURN