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.

How to expand I/O pins of a microcontroller using 74HC595 C Code

In this blog entry I will show you how to use a 74HC595 to expand I/O pins using only 3 I/O pins of a microcontroller. The program is tested on a 16F876A at 20MHz.

The associated program shows how to transfer a byte data serially to the 74HC595 and then sets the output accordingly.

According to page 5 of Datasheet, the outputs of 74HC595 provide 8 mA. Though I have used 330E resistors to drive LEDs , this should not be done! It is therefore recommended to connect a higher resistance (620E). LEDs light up very, very little, but enough to test the circuit.

I will mainly cover the technical details to connect a 74HC595 with a microcontroller. I will avoid the theory of a shift register and all those theoretical details.

The data are transferred into the shift register 74HC595 pin through the PIN 14 (Serial date).
PIN 11 (Shift register clock). Once finished sending data, just bring a high level on the pin 12 (Storage Clock or Latch) to transfer data from the shift register to the latch. The pin 13 (Output Enable - active low) enables the transfer of data from the latch to the output ports when it is brought low: since we connected the drive pin to ground, they meet again on the data outputs as soon as we give the shot clock on the latch. The pin 10 is the master reset: placing it at a low level resets the contents of the shift register, for which we keep it up for safety. The pin 9 we keep it disconnected because it is not used in this application.

You can use any microcontroller but be careful, in case of open collector pins, add pull up resistors.

595.gif




Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#define shift 8
sbit latch at RB1_bit;
sbit clock at RB0_bit;
sbit data_bit at RB3_bit;
sbit latch_Direction at TRISB1_bit;
sbit clock_Direction at TRISB0_bit;
sbit data_bit_Direction at TRISB3_bit;
 
void send_data(unsigned char temp);
 
void main()
{
unsigned char a;
  latch_Direction=0;
  clock_Direction=0;
  data_bit_Direction=0;
  while(1){
  
  for(a=0;a<255;a++)
   {
   send_data(a);
   Delay_ms(500);
   }
 
          }
}
void send_data(unsigned char temp)
   {
   unsigned char i;
   unsigned char dd;
   latch=0;
   clock=0;
   for(i=0;i<shift;i++){
   dd=temp>>i;
   if(dd&1)
                        data_bit=1;
             else
                        data_bit=0;
   clock=1;
   clock=0;
                       }
   latch=1;
   }


Using mikroC Pro

Comments

There are no comments to display.

Part and Inventory Search

Blog entry information

Author
papunblg
Read time
2 min read
Views
1,073
Last update

More entries in Uncategorized

More entries from papunblg

Share this entry

Back
Top