Saturday, June 13, 2009

PARALEL IN , SERIAL OUT SHIFT REGISTER 74HC165








Bringing 8 bits of data into a PIC16F84 serially is done in a similar way. For that purpose we can use 74HC165 parallel in serial out shift register.





This digital IC has 3 control lines as follow :

1. Serial Output
2. Load ( load 8 bits into shift register )
3. Clock ( shift data MS bit first )


The 8 bits of data presented to the shift register are latched in using the LOAD control line. The 8 data bits are shifted out most significant bit first.

One port pin of PIC16F84/A is used for serial in. It is convenient to use bit 0 for serial input. The program looks at the port as a whole, rotate bit “0” into the carry flag, and rotate the content of the carry flag into the least significant bit ( LSB ) of the file register assigned to receive the incoming data.

This process is carried out for each of the 8 bits. Notice that the first bit is available at the serial output line immediately after the data is latched. Shifting 7 times ( not 8 times ) is required to access the remaining bits.


;=======74HC165.ASM=================================4/25/97==
list p=16f84a
__config h'3ff1'
radix hex
;------------------------------------------------------------
; cpu equates (memory map)
porta equ 0x05
portb equ 0x06
status equ 0x03
rcvreg equ 0x0c
count equ 0x0d
temp equ 0x0e
trisa equ 0x85
trisb equ 0x86
;------------------------------------------------------------
; bit equates
rp0 equ 5
;------------------------------------------------------------
org 0x000
;
start bsf status,rp0 ;switch to bank 1
movlw b'00000001' ;bit 0 = input
movwf trisa
movlw b'00000000' ;outputs
movwf trisb
bcf status,rp0 ;switch back to bank 0
movlw 0x04 ;0000 0100
movwf porta ;control word
call ser_in ;to serial input subroutine
movf rcvreg,w ;get data
movwf portb ;display data via LEDs
circle goto circle ;done
;------------------------------------------------------------
ser_in clrf rcvreg ;clear receive register
movlw 0x08 ;init 8 counter
movwf count
bcf porta,2 ;load shift register
bsf porta,2
getbit movf porta,w ;read port A
movwf temp ;store copy
rrf temp,f ;rotate bit into carry flag
rlf rcvreg,f ;rotate carry flag into rcvreg
decfsz count,f ;decrement counter
goto shift
return ;done
shift bsf porta,1 ;shift 1 bit
bcf porta,1
goto getbit ;again
;------------------------------------------------------------
end
;------------------------------------------------------------
;note: the 74HC165 gets shifted 7 times
;------------------------------------------------------------
;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

No comments: