首页 > 其他分享 >03-数码管静态显示

03-数码管静态显示

时间:2022-12-22 11:24:12浏览次数:35  
标签:P2 03 静态 unsigned char 数码管 break 0x1f

 

# include "reg52.h"

void delay(unsigned char i)
{
	while(i--);
}

unsigned char code table[] = 
{
	0xc0,//0
	0xf9,//1
	0xa4,//2
	0xb0,//3
	0x99,//4
	0x92,//5
	0x82,//6
	0xf8,//7
	0x80,//8
	0x90,//9
	0x88,//A
	0x83,//B
	0xc6,//C
	0xa1,//D
	0x86,//E
	0x8e //F
};


void HC138 (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 show (unsigned char pos,unsigned char dat)
{
	HC138(7);//数码管的内容
	P0 = table[dat];
	HC138(6);//数码管的位置
	P0 = 0x01 << pos;
}


void showseg()
{
	unsigned char i,j;
	
	for(i = 0;i <8;i++)
	{
		for(j = 0;j <10 ;j++)
		{
			show(i,j);
			delay(60000);
		}
	}
	
	for(j = 0; j<10;j++)
	{
		HC138(6);
		P0 = 0xff;
		HC138(7);
		P0 = table[j];
		delay(60000);
	}
}


void main()
{
	while(1)
	{
		showseg();
	}
}

 

标签:P2,03,静态,unsigned,char,数码管,break,0x1f
From: https://www.cnblogs.com/Unclesundada/p/16997972.html

相关文章