Blue Bridge Cup single-chip design and development (2) LED display with flashing

Blue Bridge Cup microcontroller design and development (2) LED display with flashing

Today we introduce the operation of the Blue Bridge Cup development board LED module.
We first introduce dynamic digital sweep second principle:
LED divided into two types, common anode and common cathode LED digital tube. A digital tube segment selector and a bit selection, is fed into high and low bits is selected such that the digital display data into the segment selector to be displayed. Blue Bridge Cup uses a total of Yang digital tube.

Here Insert Picture Description
This is a digital schematic of the development board. Y7C control segment selected digital tube, Y6C selected digital control bits, there are 74HC138 control, when the data can be fed Y7C is high, is low in the cord storage state.

void enable138(uchar x)
{
	P2&=0X1f;    //先将138 A B C 置位0 0 0输出Y0为低,其他为高
	P2|=(x<<5); //X左移5位后通过或非门对对应的74HC573送入数据
	
	_nop_();
	_nop_();
	P2&=0X1f;//在此将P2置位
}

This is the above HC138 code.
Here Insert Picture Description
We first establish a good project.
The code:
smg.c

# include "smg.h"
uchar code smgDU[34]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0x88,0x83,0xC6,0xA1,0x86,0x8E,//0 ~F 
					0x40,0x79,0x24,0x30,0x19,0x12,0x02,0x78,0x00,0x10,0x08,0x03,0x46,0x21,0x06,0x0E,//0.~F.
					0xff,0xbf}; 		//灭 -
uchar smgWE[8]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
uchar displaydat[8]={1,2,3,4,5,6,7,8};//数码管一定会立刻显示的内容
uchar flashset=0x00;
uint flashT=400;//数码管闪烁周期为400ms,1ms进入一次定时器0中断


void Timer0Init(void)		//1毫秒@12.000MHz
{
	AUXR |= 0x80;		//定时器时钟1T模式
	TMOD &= 0xF0;		//设置定时器模式
	TL0 = 0x20;		//设置定时初值
	TH0 = 0xD1;		//设置定时初值
	TF0 = 0;		//清除TF0标志
	TR0 = 1;		//定时器0开始计时
	
	EA=1;//开启总中断
	ET0=1;//开启定时器0中断	
}


void smgdisplay()//数码管子扫描函数,放入中断
{
	static uchar WhichWE=0;
	
	P0=0XFF;
	enable138(DU);
	
	P0=smgWE[WhichWE];
	enable138(WE);
	
	P0=smgDU[displaydat[WhichWE]];
	enable138(DU);
	
	WhichWE++;
	if(WhichWE==8)
	{
		WhichWE=0;
	}
}

void smg_set(uchar dat1,uchar dat2,uchar dat3,uchar dat4,uchar dat5,uchar dat6,uchar dat7,uchar dat8)//数据传送函数,放入main函数
{
	displaydat[0]=dat1;
	displaydat[1]=dat2;
	displaydat[2]=dat3;
	displaydat[3]=dat4;
	displaydat[4]=dat5;
	displaydat[5]=dat6;
	displaydat[6]=dat7;
	displaydat[7]=dat8;

}
void flash_service()
{
	uchar i;
	static uint flashcount=0;
	flashcount++;
	if(flashcount<flashT/2)//前半个周期给需要闪烁的无效位选
	{
		for(i=0;i<8;i++)
		{
			if(flashset&(0x80>>i))//如果是需要闪烁的给无效位选,
			{
				smgWE[i]=0x00;
			}
			else //如果不是需要闪烁的给有效位选
			{
				smgWE[i]=0x01<<i;
			}
		}
		
	}
	else if(flashcount<flashT)//后半个周期给有效位选
	{
		for(i=0;i<8;i++)
		{
			
				smgWE[i]=0x01<<i;
			
		}
	}
	else
	{
		flashcount=0;
	}
	
}

void Timer0() interrupt 1
{
	smgdisplay();
	flash_service();
}



smg.h

#ifndef _SMG_H_
#define _SMG_H_

# include "include.h"


extern uchar flashset;

void Timer0Init(void);
void flash_service();
void smgdisplay();
void smg_set(uchar dat1,uchar dat2,uchar dat3,uchar dat4,uchar dat5,uchar dat6,uchar dat7,uchar dat8);



#endif 

main function

# include"include.h"

void suoyouwaishe_Init()
{

	P0=0xff;
	enable138(LED);
	P0=0x00;
	enable138(ULN2003);
	P0=0x00;
	enable138(WE);
	P0=0xff;
	enable138(DU);

}

void main()
{
	suoyouwaishe_Init();
	Timer0Init();
	flashset=0xc0;
	while(1)
	{
		smg_set(15,14,13,12,11,10,9,8);

	}
	
}






include.h

#ifndef _INCLUDE_H_
#define _INCLUDE_H_

#define uchar unsigned char 
#define uint unsigned int

#include "STC15F2K60S2.h"
#include "intrins.h"
# include "enable138.h"
# include "smg.h"





#endif 

If you want to effect a change in the position of flashing, only you need to modify the value flashset on it.
Development:
About transfer function parameters, there is a way passed by a pointer:

void smg_set(uchar *smgdatastore)
{
	uchar i;
	for(i=0;i<8;i++)
	{
		displaydat[i]=*(smgdatastore+i);
	}
}

main function

# include"include.h"
uchar smgdatastore[8]={1,2,3,4,5,6,7,8};

void suoyouwaishe_Init()
{

	P0=0xff;
	enable138(LED);
	P0=0x00;
	enable138(ULN2003);
	P0=0x00;
	enable138(WE);
	P0=0xff;
	enable138(DU);

}

void main()
{
	suoyouwaishe_Init();
	Timer0Init();
	flashset=0xc0;
	while(1)
	{
		smg_set(smgdatastore);

	}
	
}






Ruoguo is calculated without the need may write, other circumstances may be modified (e.g.):

void main()
{  
	uchar smgdatastore[8]={0};
	uchar keyvalue=244;
	suoyouwaishe_Init();
	Timer0Init();
	flashset=0xc0;
		while(1)
	{
		smgdatastore[5]=keyvalue/100%10;
		smgdatastore[6]=keyvalue/10%10;
		smgdatastore[7]=keyvalue%10;
		smg_set(smgdatastore);

	}
	
}
Released two original articles · won praise 2 · views 92

Guess you like

Origin blog.csdn.net/weixin_44874337/article/details/104313476