Multiplexing Display could be driven form controller digital output pins without any additional memory chips. However it needs at least one digital output port. In this example, I use two SN74HC164 shift register chip to store seven-segment display data, and drive each commons. It makes a multiplexing 7-Segment display that use only three micro-controller digital output pins.
For more example of using SN74HC164 chip you can check these links:
- 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
- ATMega32 And SN74HC164 Serial Seven Segment Display
There's an input button to count the number of input pulse. It's active low input. Optionally, I use a signal source with the frequency around 5Hz as an input signal instead of push button.
Simulating Program |
The program activate each digits before it reset the registers to refresh display data without conflicting the display output.
/* * SN74HC164MUX.c * * Created: 7/10/2023 2:01:24 PM * Author : Admin */ #include <avr/io.h> #define F_CPU 4000000UL #include <util/delay.h> #define SW4 4 #define nRST 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<=25;i++); PORTC&=~(1<<SCLK); for(int i=0;i<=25;i++); data<<=1; } } void nMr(void){ PORTC&=~(1<<nRST); //for(int i=0;i<10;i++); PORTC|=(1<<nRST); //for(int i=0;i<10;i++); } 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 char count = 0; DDRC|=(1<<SDAT)|(1<<SCLK)|(1<<nRST); DDRC&=~(1<<SW4); PORTC|=(1<<nRST)|(1<<SW4); while (1) { if ((PINC&(1<<SW4))==0) { _delay_ms(50); count++; } send74hc164(0b11111110); send74hc164(cCathode[count/100]); _delay_ms(10); nMr(); send74hc164(0b11111101); send74hc164(cCathode[(count%100)/10]); _delay_ms(10); nMr(); send74hc164(0b11111011); send74hc164(cCathode[count%10]); _delay_ms(10); nMr(); } }
Click here to download its source file.
No comments:
Post a Comment