Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

595 shift register

Status
Not open for further replies.

ghostman11

Well-Known Member
i been playing aound with a shift register but so far have had no luck getting any output on it
i know the code is crappy at the mo but i was just trying to get a pin (any pin) set.
Code:
#pragma config OSC = IRCIO67, PWRT = OFF, WDT = OFF, MCLRE = ON, DEBUG = ON, LVP = OFF //..............Fuse stup
#include <p18f4685.h>
#include <stdio.h>
#include <delays.h>
#include <usart.h>
#include <adc.h>
#include "EEP.h"


#define reset LATDbits.LATD3 //storgae register reclear pin 10 on 595 clears the register 
#define data_input  LATDbits.LATD2 //pin 14 on 595 (ds) ser loads in the data if pin high 1 is loaded if low 0 is loaded
#define stclk LATDbits.LATD1 // pin 11 on 595 (shcp) clock pin toggle to load data in storage register clk
#define output_enable LATDbits.LATD4 // active low
#define latch LATDbits.LATD0//shift register clk
#define low =0;
#define high =1;
 void main (void)
{
	
//sssssssssssssssssssssssssssssssssssssssssssssssssssss all the things we do once sssssssssssssssssssssss	
    // speed up the clock to 8MHz,18f4685
    //OSCCONbits.IRCF0=1;
    //OSCCONbits.IRCF1=1;
    //OSCCONbits.IRCF2=1;
    OSCCON = 0x70;
    while(OSCCON & 0x02);

    ADCON1=0x0A; //set up ADC
    CMCON=0x07;
    //stdout = _H_USER; 
    TRISBbits.TRISB2=1;            //set switch 1 to input
    TRISD=0x00;
output_enable=0;
   reset=0;
   latch=1;
   latch=0; 
  LATDbits.LATD4=0;
    while(1)
 //ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss
    {
	    
	    Nop();
	    output_enable=0;
	   data_input=1;
	   Nop();
	   stclk=1;
	   latch=1;
	   latch=0;
	   Nop();
	   stclk=0;
	   latch=1; 
	   }
}
i am aware i probaly not given enough info but i cant think of what else i need to tell you :rolleyes: soon as it pops back in my head i will post any details i have left out.
so from the scant info anyone got any cluse where i am going wrong?
 

be80be

Well-Known Member
Need to set Output enable, low it's active low

Set the latch low then clock out your data
 
Last edited:

ghostman11

Well-Known Member
i thought i had done that, i will have another go in the morning, hopefuly the old brain will have better function after sleep :D i also better recheck my connections.
 

be80be

Well-Known Member
In your code your setting the latch to 1.
You set it low then data_bit out clock, data_bit out clock, till you send all your bit's then latch.

This Is in C but not C18 but it will give a idea

Code:
void loop() {
  // count from 0 to 255 and display the number 
  // on the LEDs
  for (int numberToDisplay = 0; numberToDisplay < 256; numberToDisplay++) {
    // take the latchPin low so 
    // the LEDs don't change while you're sending in bits:
    digitalWrite(latchPin, LOW);
    // shift out the bits:
    shiftOut(dataPin, clockPin, MSBFIRST, numberToDisplay);  

    //take the latch pin high so the LEDs will light up:
    digitalWrite(latchPin, HIGH);
    // pause before next value:
    delay(500);
  }
}
 
Last edited:

tubos

New Member
Here's a C snippet of how I sent data to the 74HC595

CLK88 = clock pin
SER88 = serial data pin
STC88 = Latch pin

Code:
Ia=7;
      do       // Send Red 8 bits to 74HC595's
         {
           SER88=0;                       // PIXEL ON
           if(slice>=gm[*(pR+Ia)] )  SER88=1; // PIXEL OFF
           CLK88=1;                       // Send current bit to 74HC595
           // asm nop
           CLK88=0;
         }
      while(Ia--);

     PORTC = ~Ival;                    // Change to next row (row on ='0')
     STC88 = 1;  STC88 = 0;            // Latch data in registers to output
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Top