static char Phase = 0; SetScan(DIG_N); //switch off all scan lines SetSeg(SegData[Phase]); //output segment data SetScan(Phase); //switch on scan line if(Phase++ == DIG_N) //next scan phase Phase = 0;