蓝桥杯单片机模块-数码管

目录

前言

数码管底层代码

使用方法:

 注意事项:


前言

本文介绍了蓝桥杯单片机数码管模块的使用方法,我们依旧使用定时器进行扫描,相比较于使用Delay消隐来说更加稳定,效果也更完美 

数码管底层代码

#include <STC15F2K60S2.H>
#include "InitHC138.h"

unsigned char Nixie_Buf[9]={0,11,11,11,11,11,11,11,11};//11表示NixieTable数组中0xff位置//用于定时器扫描的数组

unsigned char NixieTable[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xbf,
0xff};
unsigned char point[9]={0,0,0,0,0,0,0,0,0};

void Nixie_SetBuf(unsigned char Location,Number)//数码管显示直接调用函数
{
	Nixie_Buf[Location]=Number;
}

void Nixie(unsigned char Location,Number,dot)

{
	P0=0xff;//消隐
	InitHC138(7);//建议先定义P0口的值,再开启锁存器
	P0=0x01<<(Location-1);//位选
	InitHC138(6);
	P0=NixieTable[Number];//段选
	if(dot)
	P0&=0x7f;//最高位变为0,其他位不变,实现小数点显示
	InitHC138(7);
}

void Nixie_Loop()//定时器扫描函数
{
	static unsigned char i=1;
	Nixie(i,Nixie_Buf[i],point[i]);
	i++;
	if(i==9)
	{
		i=1;
	}
	
}
#ifndef __NIXIE_H__
#define __NIXIE_H__

extern unsigned char point[9];//这样直接在主函数内调用小数点数组
void Nixie_SetBuf(unsigned char Location,Number);
void Nixie(unsigned char Location,Number);
void Nixie_Loop();

#endif

使用方法:

先在定时器中断里每2ms扫描一次,使用时直接调用Nixie_SetBuf(unsigned char Location,Number)函数就行

void ServiceTimer0() interrupt 1
{
	static unsigned char count1=0;
	count1++;
	if(count1==2)
	{
		Nixie_Loop();
		count1=0;
	}
	
	
}

 注意事项:

在某个界面调用数码管显示函数后,如果在下一个界面不使用该位数码管时要手动清除,让Number=0xff在数组的的位置

使用小数点时直接对point变量赋值,要消除上次使用的小数点只要point超过数码管数的范围,例如让point[]=0

  • 23
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值