Simple operation of digital tube (keil5)

Each bit of the digital tube lights up from 0 to f and then jumps to the next bit, and then all the bits light up from 0 to f together.

#include <STC15F2K60S2.H>
#include <intrins.h>
int i,j;
unsigned char code num[16]={
    
    0xc0,0xcf,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x98,0x88,0x80,0xc6,0xc0,0x86,0x8e};//0123456789abcd
/*************************************************/
void initsystem(unsigned char i)
{
    
    
	switch(i)
	{
    
    
		case 4:
			P2=0X8f&(P2|0xe0);//打开y4锁存器
		break;
		case 5:
			P2=0xbf&(P2|0xe0);//打开y5锁存器
		break;
		case 6:
			P2=0xdf&(P2|0xe0);//打开y6锁存器
		break;
		case 7:
			P2=0xff&(P2|0xe0);//打开y7锁存器
		break;
		case 0:
			P2=0x1f&(P2|0xe0);//关闭锁存器
		break;
	}
}
/*******************************************/
void Delay100ms()		//@11.0592MHz
{
    
    
	unsigned char i, j, k;

	_nop_();
	_nop_();
	i = 5;
	j = 52;
	k = 195;
	do
	{
    
    
		do
		{
    
    
			while (--k);
		} while (--j);
	} while (--i);
}
/*****************************************************************/
void SMG_change()//每位从0亮到f,再全部从o亮到f。
{
    
    
	for(i=0;i<8;i++)
	{
    
    
	initsystem(6);
	P0=0x01<<i;
		for(j=0;j<16;j++)
		{
    
    
		initsystem(7);
		P0=num[j];
		Delay100ms();
		Delay100ms();
		Delay100ms();
		}
	}
		initsystem(6);
		P0=0xff;
		for(j=0;j<16;j++)
		{
    
    
		initsystem(7);
		P0=num[j];
		Delay100ms();
		Delay100ms();
		Delay100ms();
		}
}
/*********************************************************************/
void main()
{
    
    
	initsystem(4);//开y4
	P0=0xff;//关灯
	initsystem(0);//关y4
	initsystem(5);//开y5
	P0=0x00;//关继电器蜂鸣器
	initsystem(0);//关y5
	while(1)
	{
    
    
		SMG_change();
	}
}

Guess you like

Origin blog.csdn.net/m0_53126906/article/details/113785305