举个例子:
#include "reg52.h"
unsigned char code DuLiAnJian[]={1,2,4,8,16,32,64,128,254,253,251,247,239,223,191,127};
unsigned char code smgduan[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,0,64}; //共阴0~F消隐减号
sbit k1=P1^7;
bit k = 0;
void main()
{
unsigned char wei=0,Xd=0,Sw=0;
unsigned int Ys=47474,Lx=0;
while(1)
{
if(!k1&&!++Xd){P2=P0=255;if(++Sw>9)Sw=0;while(!k1);}
while(!--Ys)
{
P2=~smgduan[wei];
if(++wei>9)wei=0;
Ys=47474;
}
}
}
与
#include "reg52.h"
unsigned char code DuLiAnJian[]={1,2,4,8,16,32,64,128,254,253,251,247,239,223,191,127};
unsigned char code smgduan[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,0,64}; //共阴0~F消隐减号
sbit k1=P1^7;
bit k = 0;
void main()
{
unsigned char wei=0,Xd=0,Sw=0;
unsigned int Ys=47474,Lx=0;
while(1)
{
if(!k1&&!++Xd){P2=P0=255;if(++Sw>9)Sw=0;while(!k1);}
if(!--Ys)
{
P2=~smgduan[wei];
if(++wei>9)wei=0;
Ys=47474;
}
}
}
这样写2个程序是一样的。 |