| 缩小了1ms延时,不明白怎么会有余晖,有附图 
 #include <REG52.H>
 #define uchar unsigned char
 #define uint unsigned char
 /********************************************************************
 1ms延时程序
 *********************************************************************/
 void delay (unsigned int a)    // 1ms延时程序
 {
 unsigned int i;
 while(a--)
 {
 for(i = 0; i < 10; i++);//STC单片机在外部晶振为12MHz时i值上限为600
 }                               //AT89C51单片机在外部晶振为12MHz时i值上限为125
 }
 
 /*******************************************************************
 共阳数码管
 ********************************************************************/
 uchar code table[]={0xc0, 0xf9, 0xa4, 0xb0,0x99,
 0x92, 0x82,0xf8,0x80,0x90,
 };            //0123456789
 
 void main()
 {
 uint i=0;
 while (1)
 {
 P2=0x7f;         //01111111
 P0=table[1];
 delay(2);
 P2=0xbf;          //10111111
 P0=table[2];
 delay(2);
 P2=0xdf;            //11011111
 P0=table[3];
 delay(2);
 P2=0xef;                //11101111
 P0=table[4];
 delay(2);
 }
 }
 |