C51单片机数码管的显示代码

利用单片机数码管的数字显示:

#include<stc15f2k60s2.h>

unsigned char CS[]={0x7f,0xbf,0xdf,0xef};
unsigned char DM[]={0x77,0x41,0x3b,0x6b,0x4d,0x6e,0x7e,0x43,0x7f,0x6f};

void Delay500ms()		//@11.0592MHz
{
	unsigned char i, j, k;

	i = 22;
	j = 3;
	k = 227;
	do
	{
		do
		{
			while (--k);
		} while (--j);
	} while (--i);
}

void Delay100us()		//@11.0592MHz
{
	unsigned char i, j;

	i = 2;
	j = 15;
	do
	{
		while (--j);
	} while (--i);
}

void Delay100ms()		//@11.0592MHz
{
	unsigned char i, j, k;

	i = 5;
	j = 52;
	k = 195;
	do
	{
		do
		{
			while (--k);
		} while (--j);
	} while (--i);
}


int main()
{
	int i,j;
	P1M1 &= ~0xff;  //P1推挽输出
   P1M0 |=  0xff;
	P0=0xff;
	j=0;
	while(1)
	{
		for(i=0;i<4;i++)
		{
			P0=CS[i];
			
			P1=DM[j];
			Delay500ms();
			
		}
		j++;
		if(j>9)
		{
			j=0;
		}
	}
	return 0;
}


你可能感兴趣的:(c,单片机,数码管)