Display multiplexing is very common for most microcontroller programming and interfacing. In usual, a controller could drive up to 8 digits before we can see its display flickering. In this programming example, I use only two digits of 7-Segment display. Because it's easy to build the circuit with a little of source codes.
|  | 
| Program simulation in Proteus | 
Controller keeps track of counting an external pulse generated by SW1 switch pressing. The maximum press counting is 60 before it rolls down to 0. The display will become flicker whenever the input switch has a longer press duration, but it's not longer than 250ms.
/*
* mux2Ssd.c
*
* Created: 5/25/2022 7:20:40 PM
* Author : Admin
*/
#include <avr/io.h>
#define F_CPU 4000000UL
#include <util/delay.h>
int main(void)
{
//common cathode
unsigned char SSD[10]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F};
unsigned char cnt=0;
//PortC output
DDRC=0xFF;
//PD7 input
DDRD&=~(1<<7);
//Turn on PD7
PORTD|=(1<<7);
while (1)
{
//Display processing
PORTD&=~(1<<0);
PORTD&=~(1<<1);
PORTC=SSD[cnt/10];
PORTD|=(1<<0);
_delay_ms(3);
PORTD&=~(1<<0);
PORTD&=~(1<<1);
PORTC=SSD[cnt%10];
PORTD|=(1<<1);
_delay_ms(3);
//Input Testing
if ((PIND&0x80)==0)
{
//while((PIND&0x80)==0);
cnt++;
_delay_ms(250);
}
if(cnt>=60) cnt=0;
}
}
Click here to download source file.
|  | 
| Schematic diagram | 
