Sunday, July 5, 2020

ATMega32 Interfaces To SN74HC164 Shift Registers

A shift register is needed whenever we want to expand microcontroller outputs. The SN74HC164 is a parallel out serial shift register. This IC is very simple to use.

ATMega32 Interface To SN74HC164 Shift Register
SN74HC164 Pin Assignments

ATMega32 Interfaces To SN74HC164 Shift Registers
SN74HC164 DIP-14

Controller typically need only two pins - serial clock and serial data to interface to this chip.

ATMega32 Interface To SN74HC164 Shift Registers
Logic Diagram

Serial Data Input A (DSA) and Serial Data Input B (DSB) must be wired together. Otherwise we can make one input high.

ATMega32 Interface To SN74HC164 Shift Registers
Timing Diagram
 

To interface to this chip controller should have an SPI module. Otherwise the programmer must write an SPI software routine using bit banging.

In this example, I use software bit banging to send serial data to SN74HC164 chip. It needs only two pins - data and clock.

ATMega32 Interfaces To SN74HC164 Shift Registers
Schematic

I wrote this example in C using Microchip Studio.

  1. /*
  2.  * SN74HC164LEDBitBang.c
  3.  *
  4.  * Created: 7/7/2023 7:18:00 PM
  5.  * Author : Admin
  6.  */
  7.  
  8. #include <avr/io.h>
  9.  
  10. #define SDAT 7
  11. #define SCLK 6
  12.  
  13. void send74hc164(unsigned char data){
  14. for(int i=0; i<8;i++){
  15. if ((data&(1<<7))==0)
  16. {
  17. PORTC&=~(1<<SDAT);
  18. }
  19. else PORTC|=(1<<SDAT);
  20. PORTC|=(1<<SCLK);
  21. for(int i=0;i<=50;i++);
  22. PORTC&=~(1<<SCLK);
  23. for(int i=0;i<=50;i++);
  24. data<<=1;
  25. }
  26. }
  27.  
  28. int main(void)
  29. {
  30. unsigned char newData = 0, oldData = 0;
  31.  
  32. DDRC|=(1<<SDAT)|(1<<SCLK);
  33. DDRB=0x00;
  34. PORTB=0xFF;
  35. while (1)
  36. {
  37. newData = PINB;
  38. if (newData!=oldData)
  39. {
  40. send74hc164(newData);
  41. oldData = newData;
  42. }
  43. }
  44. }
  45.  
  46.  

Click here to download zip file.

ATMega32 Interfaces To SN74HC164 Shift Registers
Simulating Program In Proteus

 

No comments:

Post a Comment