wrahulr88
Newbie level 1
hi all,
i tried o/p port expansion using shift register 74HC595.But the code when i simulate it ,is not working.Still i tried it after programing.But it doesnt make ny change.i will give u the code.Please help me.
;program to read port B and send it to the shift register via serial mode data transfer(SPI)
;using shift register 74HC595
#include<p16f877a.inc>
__CONFIG _CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_ON & _HS_OSC & _LVP_OFF & _DEBUG_OFF & _CPD_OFF
org 0h
goto main
main
bsf STATUS,RP0
movlw b'11111111' ;portb input
movwf TRISB
clrf TRISC ;portc o/p
movlw b'01000000' ;putting CKE=1
movwf SSPSTAT
bcf STATUS,RP0 ;bank 0
clrf PORTC ;clearing PORTC
clrf PIR1 ;clear interrupt flag
movlw b'00100010'
movwf SSPCON ;enabling SSP
bsf PORTC,1 ;disabling o/p
goto program
program
movlw PORTB ;reading PORTB
movwf SSPBUF
btfss PIR1,SSPIF ;checkin whether SSPIF has been set
goto $-1 ;else go back to previous instruction
bsf PORTC,4 ;latching data out of shift register
nop
bcf PORTC,4
nop
bcf PORTC,1 ;o/p disable
nop
bcf PIR1,SSPIF ;clearing flag
goto program ;continue the process
END
i tried o/p port expansion using shift register 74HC595.But the code when i simulate it ,is not working.Still i tried it after programing.But it doesnt make ny change.i will give u the code.Please help me.
;program to read port B and send it to the shift register via serial mode data transfer(SPI)
;using shift register 74HC595
#include<p16f877a.inc>
__CONFIG _CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_ON & _HS_OSC & _LVP_OFF & _DEBUG_OFF & _CPD_OFF
org 0h
goto main
main
bsf STATUS,RP0
movlw b'11111111' ;portb input
movwf TRISB
clrf TRISC ;portc o/p
movlw b'01000000' ;putting CKE=1
movwf SSPSTAT
bcf STATUS,RP0 ;bank 0
clrf PORTC ;clearing PORTC
clrf PIR1 ;clear interrupt flag
movlw b'00100010'
movwf SSPCON ;enabling SSP
bsf PORTC,1 ;disabling o/p
goto program
program
movlw PORTB ;reading PORTB
movwf SSPBUF
btfss PIR1,SSPIF ;checkin whether SSPIF has been set
goto $-1 ;else go back to previous instruction
bsf PORTC,4 ;latching data out of shift register
nop
bcf PORTC,4
nop
bcf PORTC,1 ;o/p disable
nop
bcf PIR1,SSPIF ;clearing flag
goto program ;continue the process
END