当前位置:   article > 正文

动态数码管的显示(共阳数码管)_:动态数码管(共阳编码 :{0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0

:动态数码管(共阳编码 :{0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90})循

#include<reg52.h>	   
#define uint unsigned int
unsigned int mouth=1;
unsigned char code SMG[18]=
{
0xc0,0xf9,0xa4,0xb0,0x99,0x92,
0x82,0xf8,0x80,0x90,0x88,0x80,
0xc6,0xc0,0x86,0x8e,0xbf,0x7f
};
void delay_SMG(uint time)
{
	uint i,j;
	for(i=time;i>0;i--)
		for(j=114;j>0;j--);
}
void SelectHC573(unsigned char n)
{
	switch(n)
	{
		case 4:
			P2=(P2 & 0x1f) | 0x80;
		break;
		case 5:
			P2=(P2 & 0x1f) | 0xa0;
		break;
		case 6:
			P2=(P2 & 0x1f) | 0xc0;
		break;
		case 7:
			P2=(P2 & 0x1f) | 0xe0;
		break;
	}
}
void Init()
{
	SelectHC573(5);
	P0=0x00;
	SelectHC573(4);
	P0=0xff;
}
void Show_SMG_Bit(unsigned char dat,unsigned char pos)
{
	SelectHC573(6);
	P0=0x01<<pos;
	SelectHC573(7);
	P0=dat;
}
void Show_SMG()
{
	Show_SMG_Bit(SMG[2],0);
	delay_SMG(10);
	Show_SMG_Bit(0xff,0);//消影
	Show_SMG_Bit(SMG[0],1);
	delay_SMG(10);
	Show_SMG_Bit(0xff,1);
	Show_SMG_Bit(SMG[2],2);
	delay_SMG(10);
	Show_SMG_Bit(0xff,2);
	Show_SMG_Bit(SMG[1],3);
	delay_SMG(10);
	Show_SMG_Bit(0xff,3);
	Show_SMG_Bit(0xbf,4);
	delay_SMG(10);
	Show_SMG_Bit(0xff,4);
	Show_SMG_Bit(0xbf,5);
	delay_SMG(10);
	Show_SMG_Bit(0xff,5);
	Show_SMG_Bit(SMG[mouth/10],6);
	delay_SMG(10);
	Show_SMG_Bit(0xff,6);
	Show_SMG_Bit(SMG[mouth%10],7);
	delay_SMG(10);
	Show_SMG_Bit(0xff,7);
}
void delay(uint time)
{
	while(time--)
	{
		Show_SMG();
	}
}
void main()
{
	Init();
	while(1)
	{
		Show_SMG();
		delay(100);
		mouth++;
		if(mouth>12)																 
		{
			mouth=1;
		}
	}
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/代码探险家/article/detail/848867
推荐阅读
相关标签
  

闽ICP备14008679号