We can cascade the SN74HC164 chip to make a serial display with any numbers of digit. There are some more example of using this type of shift registers chip,
- ATMega32 Interfaces To SN74HC164 Shift Registers
- ATMega32 SPI Interfaces To SN74HC164 And LED
- ATMega32 SPI Interfaces To SN74HC164 And LCD Using 3 Pins
- ATMega32 SN74HC164 Seven Segments Display And Switch Interfacing.
In this example, I use three registers connecting with individual seven-segment display. I use an input connects to PC5 to count external pulse.
Simulating Program |
I wrote a C program to make software bit-banging that send serial data to shift registers.
/* * SN74HC164SerialSD.c * * Created: 7/9/2023 1:20:09 PM * Author : Admin */ #include <avr/io.h> #define SW1 5 #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; } } const unsigned char cCathode[]={0x3F,0x06,0x5B,0x4F,0x66,0x6D, 0x7D,0x07,0x7F,0x6F,0x77,0x7C,0x39,0x5E,0x79,0x71}; /* unsigned char cAnode[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0x88, 0x83,0xC6,0xA1,0x86,0x8E}; */ int main(void) { unsigned int newData = 0, oldData = 0xFF; /*SW1 For Input Button*/ DDRC&=~(1<<SW1); /*Set SW1 Pin High*/ PORTC|=(1<<SW1); /*Serial Data And Serial Clock Output To SN74HC164*/ DDRC|=(1<<SDAT)|(1<<SCLK); while (1) { if((PINC&(1<<SW1)) == 0){ newData++; //while((PINC&(1<<SW1))==0); for(int i = 0; i <= 150; i++) for(int i = 0; i <= 1000; i++); if(newData > 999) newData = 0; } if (newData != oldData) { send74hc164(cCathode[newData%10]); send74hc164(cCathode[(newData%100)/10]); send74hc164(cCathode[newData/100]); oldData = newData; } } }
Click here to download zip file of this example.
No comments:
Post a Comment