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.
SN74HC164 Pin Assignments |
SN74HC164 DIP-14 |
Controller typically need only two pins - serial clock and serial data to interface to this chip.
Logic Diagram |
Serial Data Input A (DSA) and Serial Data Input B (DSB) must be wired together. Otherwise we can make one input high.
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.
Schematic |
I wrote this example in C using Microchip Studio.
/* * SN74HC164LEDBitBang.c * * Created: 7/7/2023 7:18:00 PM * Author : Admin */ #include <avr/io.h> #define SDAT 7 #define SCLK 6 void send74hc164(unsigned char data){ for(int i=0; i<8;i++){ if ((data&(1<<7))==0) { PORTC&=~(1<<SDAT); } else PORTC|=(1<<SDAT); PORTC|=(1<<SCLK); for(int i=0;i<=50;i++); PORTC&=~(1<<SCLK); for(int i=0;i<=50;i++); data<<=1; } } int main(void) { unsigned char newData = 0, oldData = 0; DDRC|=(1<<SDAT)|(1<<SCLK); DDRB=0x00; PORTB=0xFF; while (1) { newData = PINB; if (newData!=oldData) { send74hc164(newData); oldData = newData; } } }
Click here to download zip file.
Simulating Program In Proteus |
No comments:
Post a Comment