Basic Principle of Dynamic Scanning The basic principle of dynamic scanning is to connect the same segments of all seven-segment displays in parallel, and to select the displayed digit by controlling the common terminal (digit selection) of each display.By outputting the corresponding codes to the segment selection lines through the microcontroller, and simultaneously activating the corresponding digit selection line, the predetermined number or character can be displayed on the selected seven-segment display. Delay Control: After each switch, a delay function is executed by the microcontroller to control the duration of the display. The length of the delay affects the stability and brightness of the display. Wiring Diagram:
Code:
void delay(void) // Delay function{ unsigned char i,j;for(i=0;i<250;i++) for(j=0;j<250;j++) ; }
Main Program:
void main(void){ while(1) // Infinite loop { P2=0xfe; // Output low level on P2.0, DS0 lights up P0=0xf9; // Segment code for number 1 delay(); P2=0xfd ; // Output low level on P2.1, DS1 lights up P0=0xa4; // Segment code for number 2 delay(); P2=0xfb; // Output low level on P2.2, DS2 lights up P0=0xb0; // Segment code for number 3 delay(); P2=0xf7; // Output low level on P2.3, DS3 lights up P0=0x99; // Segment code for number 4 delay(); P2=0xff; } }
