Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[PIC] Using 74165 and 74595 with PIC 16F877

Status
Not open for further replies.

eldvin1

Newbie level 2
Newbie level 2
Joined
Jan 8, 2015
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Visit site
Activity points
13
Hi all,


I'm trying to extend both input and output pin numbers of PIC 16F877. I'm using 2 x 74HC595 and 2 x 74HC165. It's nearly working but when I hit the first pin of first 74HC165 It's not working. When I hit the second one, both first and second pin of 74hc595 working.

The other problem is when I hit the last pin of second 74hc165 first 74hc595 is not working anymore.

What will be the problem? Here I have added schematic and zip file of both code and schematic. Thanks in advance.

PS: Working with CCS C

devre.png
 

Attachments

  • Soru_2.zip
    212.6 KB · Views: 192

I really need a help. Here is the problem I have:

Untitled.png



Here are the codes;

74595.c
Code:
#IFNDEF EXP_OUT_ENABLE

#define EXP_OUT_ENABLE  PIN_B4
#define EXP_OUT_CLOCK   PIN_B5
#define EXP_OUT_DO      PIN_B6
#define NUMBER_OF_74595 2

#ENDIF


void write_expanded_outputs(byte* eo) {
  byte i;

  output_low(EXP_OUT_CLOCK);
  output_low(EXP_OUT_ENABLE);

  for(i=1;i<=NUMBER_OF_74595*8;++i) {  // Clock out bits from the eo array
    if((*(eo+(NUMBER_OF_74595-1))&0x80)==0)
      output_low(EXP_OUT_DO);
    else
      output_high(EXP_OUT_DO);
   shift_left(eo,NUMBER_OF_74595,0);
   output_high(EXP_OUT_CLOCK);
   output_low(EXP_OUT_CLOCK);
  }
  output_high(EXP_OUT_ENABLE);
}

74165.c
Code:
#IFNDEF EXP_IN_ENABLE

#define EXP_IN_ENABLE   PIN_B4
#define EXP_IN_CLOCK    PIN_B5
#define EXP_IN_DI       PIN_B6
#define NUMBER_OF_74165 2

#ENDIF


void read_expanded_inputs(byte *ei) {
  byte i;

  output_high(EXP_IN_CLOCK);
  output_low(EXP_IN_ENABLE);      // Latch all inputs
  output_high(EXP_IN_ENABLE);

  for(i=1;i<=NUMBER_OF_74165*8;++i) {      // Clock in bits to the ei structure
    shift_left(ei,NUMBER_OF_74165,input(EXP_IN_DI));
    output_low(EXP_IN_CLOCK);
    output_high(EXP_IN_CLOCK);
  }
  output_low(EXP_IN_ENABLE);
}

Here is my main function

Code:
#include "16F877.h"
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600,xmit=pin_c6,rcv=pin_c7,parity=N,stop=1)

#include <C:\Users\BASGAN\Desktop\Embedded Control Final\Soru_2\kod\74595.c>
#include <C:\Users\BASGAN\Desktop\Embedded Control Final\Soru_2\kod\74165.c>
#include <math.h>

int adana;
main() {
   byte data;

   do {
   adana++;
   
   if (adana%2==0)
      {   
            read_expanded_inputs (&data);
      }
      else
      {
            output_low(PIN_B3);
            write_expanded_outputs (&data);
      }
   } while (TRUE);
}
 

Hi;
First of all:
- both IC you are using (HC595 and HC164) are serial-to-parallel converters but only for outputs. For parallel-to-serial converting (ie for inputs) have to use for example a CD4021 like in my old project. See the picture and the attached Proteus simulation. Its program was written in mikroC (not in CCS C) so does not attached here.

- second (and this is important):
All above ICs are positive edge controlled (for example the 595 stores the values at the raising edge of its ST_CL input or shifts in the new data at the raising edge of its SH_CL).
Have to revise your code ...
 

Attachments

  • 8pinPortExp.jpg
    8pinPortExp.jpg
    160.7 KB · Views: 178
  • 8pinPortExp.rar
    171.9 KB · Views: 171

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top