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:
I have seen this code written three different ways, what dose it do? and why show it ? I am new to programing Pic's and stuff like this confusses me. I s there anyway someone could give an example on how to use this or dose anyone know how to use this?
Hello,
I am fairly new to this, and just have a question. When using this code to expand your outputs, is this code simply a subroutine that is to be called when the 8 bits are ready to be output, or is the code implemented into the main program code? Any details you can give me on the implementation of this type of code would be very helpful. Thanks.
James Newton replies: It is to be used when the 8 bits are ready to be output. +
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/28 01:15,
3.145.75.238: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? <A HREF="http://sxlist.com/TECHREF/microchip/16x-74hc595-lg.htm"> PIC Microcontroller Output Method - Expand 3 IO pins into 8 outputs with a 74HC595</A> |
Did you find what you needed? |
Welcome to sxlist.com!sales, advertizing, & kind contributors just like you! Please don't rip/copy (here's why Copies of the site on CD are available at minimal cost. |
Welcome to sxlist.com! |
.