天天看點

單片機筆記:數位管

單片機筆記:數位管
單片機筆記:數位管
單片機筆記:數位管

共陰數位管編碼:

0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f, 0x77, 0x7c, 0x39, 0x5e, 0x79, 0x71, 0x00

靜态數位管代碼:

#include "reg52.h"

typedef unsigned char u8;
typedef unsigned int u16;

sbit LSA = P2^2;
sbit LSB=P2^3;
sbit LSC=P2^4;

u8 code smgduan[]={
	0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f, 0x77, 0x7c, 0x39, 0x5e, 0x79, 0x71
};

void delayms(u16 i)
{
	while(i--);
}

void main()
{
	LSA=0;
	LSB=0;
	LSC=0;
	while(1)
	{
		u8 i =0;
		while (i<16)
		{
			P0=smgduan[i];
			delayms(30000);
			++i;
		}
	}
}
           

動态數位管代碼:

#include "reg52.h"

typedef unsigned char u8;
typedef unsigned int u16;

sbit LSA = P2^2;
sbit LSB=P2^3;
sbit LSC=P2^4;

u8 code smgduan[]={
	0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f, 0x77, 0x7c, 0x39, 0x5e, 0x79, 0x71
};

void delayus(u16 i)
{
	while(i--);
}
void smgDisplay()
{
	u8 i;
	for(i=0;i<8;i++)
	{
		switch(i)
		{
			case(0): LSC=0;LSB=0;LSA=0;break;
			case(1): LSC=0;LSB=0;LSA=1;break;
			case(2): LSC=0;LSB=1;LSA=0;break;
			case(3): LSC=0;LSB=1;LSA=1;break;
			case(4): LSC=1;LSB=0;LSA=0;break;
			case(5): LSC=1;LSB=0;LSA=1;break;
			case(6): LSC=1;LSB=1;LSA=0;break;
			case(7): LSC=1;LSB=1;LSA=1;break;			
		}
		P0=smgduan[i];
		delayus(100000);
		P0=0x00;
	}
}
void main()
{
	LSA=0;
	LSB=0;
	LSC=0;
	while(1)
	{
		smgDisplay();
	}
}
           

繼續閱讀