Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Need some idea to move data serially.

Status
Not open for further replies.

swapan

Member
Friends,

I earnestly request you to help me with a piece of code in assembly to move data (8 bit or more) from PIC to shift register like 74HC595.

regards,

swapan
 
This code shifts bit

Code:
start 
 movwf buffer
 movlw 0x08
 movwf counter        ; counts the 8 bits 
    bcf   TX             ; set TX low
    call  BItdelay       ; delay to get a 9600 bit rate
TXLoop  
    rrf   buffer ,f      ;send one bit
    btfss STATUS ,C      ;  
    bcf   TX             ;
    btfsc STATUS ,C  ;
    bsf   TX  ;
    call  BItdelay  ;
    decfsz counter,f     ;test if all done
    goto  TXLoop  ;
    bsf   TX  ;
    call  BItdelay  ;
    return
BItdelay                 ; timing delay 

    movlw 0x17
    movwf  Count  
Wait    
    nop 
    decfsz Count ,f
    goto   Wait
    return 

 END  ; directive 'end of program'
 
You can send it as fast as you want that code was for serial TX at 9600 band I wrote it 4 years ago. You can use it to shift the data just add clock for the delay
 
Burt's code is written for asynchronous serial, not SPI. This code works marvelously with the 74HC595 -

Code:
;*****************************************************************************

;place this section before the main code

SENDREG 	EQU		0x20		;declare send buffer
BITCOUNT	EQU		0x21		;declare bit counter


;change the port/bit assignment to the pins you will be using to interface
;with the 74HC595

#define		SDO		PORTB,RB0
#define		SCK		PORTB,RB1
#define		LAT		PORTB,RB2

;*****************************************************************************

;Do this in main code to use this routine -

		movlw		<DATA>		;load W with data to be sent
		call		595Write	;send data

;or if sending data that is stored in a register, do this -

		movfw		<ADDRESS>	;load W with data to be sent
		call		595Write	;send data

;*****************************************************************************

;Place this with your subroutines

595Write	movwf		SENDREG		;load send buffer
		movlw		8		;init bit counter to 8 bits
		movwf		BITCOUNT

TXLoop		bsf		SDO		;assume MSB = 1
		btfss		SENDREG,7	;MSB = 1?
		bcf		SDO		;no, send 0
		bsf		SCK		;strobe shift clock
		bcf		SCK	
		rlf		SENDREG,F	;shift bits
		decfsz		BITCOUNT,F	;decrement bit counter
		goto		TXLoop		;keep sending until BITCOUNT = 0
		bsf		LAT		;all bits sent, strobe latch
		bcf		LAT	
		return				;done
 
Thanks Jon Wilder for giving example which is very clear to me . Actually, I am a newbie, interested in moving display. For a display having as many as 50 columns and eight rows, I like to feed data to the columns through 7 shift registers (74HC595) in cascade. Moving the data to first row and displaying for a while data for second row will be moved to the shift registers and displayed. This process will continue till eighth row and the whole process for some time thus giving a stable display. That's why I need to know the process to move data to shift register serially.

Would you kindly extend your valuable advice in this regard ?

regards.

swapan
 
Without seeing your circuit diagram no. But if you can post a schematic I might be able to.
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top