please dont rip this site

PIC Microcontroller Output Method

Expand 3 IO pins into 8 outputs with a 74HC595

Lawrence Glaister VE7IT says:

Code used to expand I/O on pic16xxx series. I used a 74hc595 to get 8 extra output bits on a pic16f627. The 595's can be cascaded for higher i/o counts with no extra lines used. In another project, I used 3 595's.

Also:


#DEFINE SRCLK   PORTB,4     ; 74hc595 clock output
#DEFINE SRDAT   PORTB,5     ; 74hc595 data output  
#DEFINE SRLAT   PORTB,3     ; 74hc595 output latch 

;----------------------------------------------------------------------
;  set relays to match global variable "relay"             
;  8 bits are clocked out to 74hct595 and then strobed to output register
;----------------------------------------------------------------------
set_relays
	movlw 	d'8'		    ; 8 hi bits to shift out
	movwf 	sr_tmp
    movf    relay,w
    movwf   sr_sr           ; save a temp copy of relay image

sr_001
	bcf	    SRDAT	        ; start with bit low
	rlf 	sr_sr,f		    ; rotate bits through c
	btfsc	STATUS,C
	bsf	    SRDAT   	    ; flip data if needed
	nop

	bsf	    SRCLK	        ; strobe active rising edge
	nop
	bcf	    SRCLK

	decfsz	sr_tmp,f
	goto	sr_001		    ; loop for rest of bits in byte	
    
	bsf	    SRLAT	        ; xfer data from sr to output latch
	nop
	bcf	    SRLAT

	return

Questions:

Comments:

Here is one possible C version of this code.


void OutPORT(unsigned char data) 

{ 
   unsigned char bits; 
   for (bits=0x80; bits!=0; bits >>= 1) 
   { 
      if ((bits & data) == bits)            // send Data 
         SRDAT = 1; 
      else 
         DRDAT = 0; 
      SRCLK = 1;                              // Clock the data
      SRCLK = 0; 
   } 
   SRLAT = 1;                                  // Latch the data 
   SRLAT = 0; 
} 

+
file: /Techref/microchip/16x-74hc595-lg.htm, 4KB, , updated: 2011/2/20 09:22, local time: 2024/11/14 09:22,
TOP NEW HELP FIND: 
3.135.217.85:LOG IN

 ©2024 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions?
Please DO link to this page! Digg it! / MAKE!

<A HREF="http://techref.massmind.org/techref/microchip/16x-74hc595-lg.htm"> PIC Microcontroller Output Method - Expand 3 IO pins into 8 outputs with a 74HC595</A>

After you find an appropriate page, you are invited to your to this massmind site! (posts will be visible only to you before review) Just type a nice message (short messages are blocked as spam) in the box and press the Post button. (HTML welcomed, but not the <A tag: Instead, use the link box to link to another page. A tutorial is available Members can login to post directly, become page editors, and be credited for their posts.


Link? Put it here: 
if you want a response, please enter your email address: 
Attn spammers: All posts are reviewed before being made visible to anyone other than the poster.
Did you find what you needed?

 

Welcome to massmind.org!

 
Here is a great gift for computer geeks or widows:
The Backwoods Guide to Computer Lingo

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  .