数码管

.H文件

#ifndef _SMG_H_
#define _SMG_H_

#include "STC15F2K60S2.h"

extern unsigned char SMGOut[12];
extern unsigned char SMGBit[8];
extern unsigned char SMGCount;

void SMG_display();


#endif

.C文件

#include "SMG.h"

unsigned char SMGOut[12]={0xc0, 0xf9, 0xa4, 0xb0, 0x99, 0x92, 0x82, 0xf8, 0x80, 0x90, 0xbf, 0xff};
unsigned char SMGBit[8]={11,11,11,11,11,11,11,11};
unsigned char SMGCount;

void SMG_display()
{
	P2=(P2&0X1F)|0xe0;
	P0=0XFF;
	P2=(P2&0X1F);
	
	P2=(P2&0X1F)|0xC0;
	P0=1<<SMGCount;
	P2=P2&0X1F;
	
	P2=(P2&0X1F)|0xE0;
	P0=SMGOut[SMGBit[SMGCount]];
	P2=P2&0X1F;
	
	if(++SMGCount==8)SMGCount=0;
}


猜你喜欢

转载自blog.csdn.net/qq_39815222/article/details/80256563