+ Post New Thread
Results 1 to 3 of 3
  1. #1
    Newbie level 2
    Points: 19, Level: 1

    Join Date
    Jan 2015
    Posts
    2
    Helped
    0 / 0
    Points
    19
    Level
    1

    Using 74165 and 74595 with PIC 16F877

    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

    Click image for larger version. 

Name:	devre.png 
Views:	26 
Size:	102.7 KB 
ID:	113092

    •   Alt11th January 2015, 11:05

      advertising

        
       

  2. #2
    Newbie level 2
    Points: 19, Level: 1

    Join Date
    Jan 2015
    Posts
    2
    Helped
    0 / 0
    Points
    19
    Level
    1

    Re: Using 74165 and 74595 with PIC 16F877

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

    Click image for larger version. 

Name:	Untitled.png 
Views:	15 
Size:	94.8 KB 
ID:	113124



    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);
    }



    •   Alt12th January 2015, 20:30

      advertising

        
       

  3. #3
    Advanced Member level 1
    Points: 5,458, Level: 17

    Join Date
    Jul 2004
    Location
    Hungary
    Posts
    472
    Helped
    187 / 187
    Points
    5,458
    Level
    17

    Re: Using 74165 and 74595 with PIC 16F877

    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 ...



--[[ ]]--