Friday, June 12, 2009

SHIFT REGISTER








Understanding about shift register is basic knowledge to understand serial communication.

To learn about shift register, we can use 74HC164 which is a serial in parallel out shift register. In and out are respect to the shift register. The project is to create and send 8 bit data to the shift register serially and looks is output via LED to see if the byte got there successfully.

Data to be send from microcontroller PIC16F84/A is initially defined and stored in a file register as 8 bits in parallel format. In order to convert them into serial format, the 8 bits in the file register are shifted left ( RLF ) one at a time. Bit 7 of the file register is sent on its way via a single output port line after each shift. The most significant bit is sent first because that is what the 74HC164 expects.











The 8 bits are marched out one at a time in succession.


The 74HC164 has 3 control line as the following :
Serial input
Clear ( clears output to 0’s ( normally High )
Clock ( Shift data trough bit 0 toward bit 7 )


To move data into the shift register, the first data bit is presented to the input. Then it is shifted in. The second bit is presented and shifted and so on.






Fig. Microcontroller PIC16F84/A with 74HC164


The shift register output are cleared on initialization as part of the power-on reset housekeeping so that all output will be low to start with.




;=======74HC164.ASM=================================4/25/97==
list p=16f84a
__config h'3ff1'
radix hex
;------------------------------------------------------------
; cpu equates (memory map)
porta equ 0x05
status equ 0x03
sendreg equ 0x0c
count equ 0x0d
trisa equ 0x85
;------------------------------------------------------------
; bit equates
rp0 equ 5
;------------------------------------------------------------
org 0x000
;
start bsf status,rp0 ;switch to bank 1
movlw b'00000000' ;outputs
movwf trisa
bcf status,rp0 ;switch back to bank 0
movlw 0x04 ;0000 0100
movwf porta ;control word
bcf porta,2 ;clear shift register
bsf porta,2
movlw 0x80 ;number to be sent
call ser_out ;to serial out subroutine
circle goto circle ;done
;------------------------------------------------------------
ser_out movwf sendreg ;save copy of number
movlw 0x08 ;init 8 counter
movwf count
testbit bcf porta,0 ;default
btfsc sendreg,7 ;test number bit 7
bsf porta,0 ;bit is set
shift bsf porta,1 ;shift register
bcf porta,1
rotlft rlf sendreg,f ;shift number left
decfsz count,f ;decrement bit counter
goto testbit ;next bit
return ;done
;------------------------------------------------------------
end
;------------------------------------------------------------
;at device program time, select:
; code protection off
; watchdog timer disabled (default is enabled)
; standard crystal XT (using 4 MHz osc for test)
; power-up timer on
;============================================================

source : pic’n up the pace

Download PDF

1 comment:

Unknown said...

Dear writer
Thank you so much for your help.So how I can email to you,for ask some question and i will pay (sorry for my opinion).Thanks in advance for your time.
Best regards vu