STC8H8K64U——4位数码管动态显示

4位数码管动态显示

可显示0~9999整数,显示小数需转换成整数,指定dp小数点位置。

#include 
#include "delay.h"

unsigned char code LED_7SEG_AN[10] = {0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};     //共阳极数码管0~9
unsigned char code LED_7SEG_AN_DP[10] = {0x40,0x79,0x24,0x30,0x19,0x12,0x02,0x78,0x00,0x10};  //共阳极数码管0~9,带小数点
unsigned char code LED_7SEG_CAT[10] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};    //共阴极数码管0~9
unsigned char code LED_7SEG_CAT_DP[10] = {0xbf,0x86,0xdb,0xcf,0xe6,0xed,0xfd,0x87,0xff,0xef}; //共阴极数码管0~9,带小数点

/*74HC245
三态输出的八组总线收发器*/
#define OUT P0

/*3线——8线译码器*/
sbit A0 = P2^2;
sbit A1 = P2^3;
sbit A2 = P2^4;

/*
可显示0~9999整数,
显示小数需转换成整数,指定dp小数点位置*/

void LED_7SEG_CAT_Display(unsigned int dt,unsigned char dp) 
{	
	unsigned int temp;
	unsigned char One,Ten,Hundred,Thousand;
	
	temp = dt;	
	Thousand = temp/1000;   /*千位*/
	Hundred = temp/100%10;  /*百位*/	
	Ten = temp/10%10;       /*十位*/	
	One = temp%10;          /*个位*/
		
	A2 = 0; 
	A1 = 1; 
	A0 = 1; 
	OUT = LED_7SEG_CAT[Thousand];
	if(dp == 3)
		OUT = LED_7SEG_CAT_DP[Thousand];
	delay_ms(5);
	
	A2 = 0; 
	A1 = 1; 
	A0 = 0; 
	OUT = LED_7SEG_CAT[Hundred];
	if(dp == 2)
		OUT = LED_7SEG_CAT_DP[Hundred];
	delay_ms(5);
	
	A2 = 0; 
	A1 = 0; 
	A0 = 1; 
	OUT = LED_7SEG_CAT[Ten];
	if(dp == 1)
		OUT = LED_7SEG_CAT_DP[Ten];	
	delay_ms(5);
	
	A2 = 0; 
	A1 = 0; 
	A0 = 0; 
	OUT = LED_7SEG_CAT[One];
	if(dp == 0)
		OUT = LED_7SEG_CAT_DP[One];		
	delay_ms(5);
	
	
}

void main(void)
{
/*准双向口模式*/
	P0M0 = 0x00;
	P0M1 = 0x00;
	P2M0 = 0x00;
	P2M1 = 0xe3;
	while(1)
	{
		LED_7SEG_CAT_Display(8421,3); 
	}	
}

STC8H8K64U——4位数码管动态显示_第1张图片

你可能感兴趣的:(STC8H8K64U——打狗棍,单片机,嵌入式硬件,51单片机)