单片机笔记:数码管

数码管引脚图
开发板数码管连接图
74HC138管脚图

共阴数码管编码:
0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f, 0x77, 0x7c, 0x39, 0x5e, 0x79, 0x71, 0x00

静态数码管代码:

#include "reg52.h"

typedef unsigned char u8;
typedef unsigned int u16;

sbit LSA = P2^2;
sbit LSB=P2^3;
sbit LSC=P2^4;

u8 code smgduan[]={
	0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f, 0x77, 0x7c, 0x39, 0x5e, 0x79, 0x71
};

void delayms(u16 i)
{
	while(i--);
}

void main()
{
	LSA=0;
	LSB=0;
	LSC=0;
	while(1)
	{
		u8 i =0;
		while (i<16)
		{
			P0=smgduan[i];
			delayms(30000);
			++i;
		}
	}
}

动态数码管代码:

#include "reg52.h"

typedef unsigned char u8;
typedef unsigned int u16;

sbit LSA = P2^2;
sbit LSB=P2^3;
sbit LSC=P2^4;

u8 code smgduan[]={
	0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f, 0x77, 0x7c, 0x39, 0x5e, 0x79, 0x71
};

void delayus(u16 i)
{
	while(i--);
}
void smgDisplay()
{
	u8 i;
	for(i=0;i<8;i++)
	{
		switch(i)
		{
			case(0): LSC=0;LSB=0;LSA=0;break;
			case(1): LSC=0;LSB=0;LSA=1;break;
			case(2): LSC=0;LSB=1;LSA=0;break;
			case(3): LSC=0;LSB=1;LSA=1;break;
			case(4): LSC=1;LSB=0;LSA=0;break;
			case(5): LSC=1;LSB=0;LSA=1;break;
			case(6): LSC=1;LSB=1;LSA=0;break;
			case(7): LSC=1;LSB=1;LSA=1;break;			
		}
		P0=smgduan[i];
		delayus(100000);
		P0=0x00;
	}
}
void main()
{
	LSA=0;
	LSB=0;
	LSC=0;
	while(1)
	{
		smgDisplay();
	}
}

版权声明:本文为CSDN博主「acktomas」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/acktomas/article/details/104154001

生成海报
点赞 0

acktomas

我还没有学会写个人说明!

暂无评论

发表评论

相关推荐

单片机:按键

#include "reg52.h"#define GPIO_KEY P1 #define GPIO_DIG P0typedef unsigned char u8; typedef unsigned int u16;sbit LSA P2^2

单片机:led点阵

左上角led点亮代码 #include "reg52.h" #include "intrins.h"#define WELA P0 typedef unsigned char u8; typedef unsigned int u16;sbit

单片机:外部中断

#include "reg52.h"typedef unsigned char u8; typedef unsigned int u16;sbit led P2^0; sbit k3P3^2;void int0Init() {EA1;EX01

单片机:定时器

实现60S循环计时 #include "reg52.h"typedef unsigned char u8; typedef unsigned int u16;sbit LSA P2^2; sbit LSBP2^3; sbit LSCP2^4