蓝桥杯单片机CT107D 数码管显示

蓝桥杯单片机CT107D 数码管显示
定义display.h

#ifndef  _display_h
#define _display_h

#include "common.h"  //包含通用的头文件

void display(uint32 dat);

#endif

定义相应的.c文件

#include "display.h"

uint8 wei[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80}; 
uint8 duan[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};

void display(uint32 dat)
{
	uint8 str[8];
	static uint8 i;
	
	str[0]=dat%100000000/10000000;  
	str[1]=dat%10000000/1000000;
	str[2]=dat%1000000/100000;
	str[3]=dat%100000/10000;
	str[4]=dat%10000/1000;
	str[5]=dat%1000/100;
	str[6]=dat%100/10;
	str[7]=dat%10;

	P2=P2&0x1f|0xc0;//y6
	P0=wei[7-i];
	
	P2=P2&0x1f|0xe0;//y7
	P0=duan[str[7-i]];
	P2=P2&0x1f;
	
	i++;
	if(i>=8)
		i=0;
}	

工程模板:https://download.csdn.net/download/qq_41676952/11126460

你可能感兴趣的:(蓝桥杯练习)