目录
4、C51单片机数码管位选码
一、3461AS-1LED数码管的结构
单个 LED 数码管的外形和外部引脚如图下所示。 LED 数码管由8个发光二极管(以下简称段)构成,通过不同的发光段组合可显示数字0~9、字符 A ~ F 、 H 、 L 、 P 、 R 、 U 、 Y 、符号"-"及小数点"."等信息。
1.数码管的工作原理
3461AS-1数码管是共阴极,数码管的内部结构如上图a所示。是由8个发光二极管的阴极连接在一起,作为公共控制端(com),接低电平。阳极作为“段”控制端,当输入的控制端为高电平时,该段对应的发光二极管导通并点亮。
2.数码管字型编码
显示 字符 | dp | g | f | e | d | c | b | a | 字型符 |
---|---|---|---|---|---|---|---|---|---|
0 | 0 | 0 | 1 | 1 | 1 | 1 | 1 | 1 | 0x3F |
1 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 0 | 0x06 |
2 | 0 | 1 | 0 | 1 | 1 | 0 | 1 | 1 | 0x5B |
3 | 0 | 1 | 0 | 0 | 1 | 1 | 1 | 1 | 0x4F |
4 | 0 | 1 | 1 | 0 | 0 | 1 | 1 | 0 | 0x66 |
5 | 0 | 1 | 1 | 0 | 1 | 1 | 0 | 1 | 0x6D |
6 | 0 | 1 | 1 | 1 | 1 | 1 | 0 | 1 | 0x7D |
7 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 1 | 0x07 |
8 | 0 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 0x7F |
9 | 0 | 1 | 1 | 0 | 1 | 1 | 1 | 1 | 0x6F |
A | 0 | 1 | 1 | 1 | 0 | 1 | 1 | 1 | 0x77 |
B | 0 | 1 | 1 | 1 | 1 | 1 | 0 | 0 | 0x7C |
C | 0 | 0 | 1 | 1 | 1 | 0 | 0 | 1 | 0x39 |
D | 0 | 1 | 0 | 1 | 1 | 1 | 1 | 0 | 0x5E |
E | 0 | 1 | 1 | 1 | 1 | 0 | 0 | 1 | 0x79 |
F | 0 | 1 | 1 | 1 | 0 | 0 | 0 | 1 | 0x71 |
H | 0 | 1 | 1 | 1 | 0 | 1 | 1 | 0 | 0x76 |
L | 0 | 0 | 1 | 1 | 1 | 0 | 0 | 0 | 0x38 |
P | 0 | 1 | 1 | 1 | 0 | 0 | 1 | 1 | 0x73 |
R | 0 | 0 | 1 | 1 | 0 | 0 | 0 | 1 | 0x31 |
U | 0 | 0 | 1 | 1 | 1 | 1 | 1 | 0 | 0x3E |
Y | 0 | 1 | 1 | 0 | 1 | 1 | 1 | 0 | 0x6E |
_ | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0x40 |
. | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0x80 |
熄灭 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0x00 |
3.数管码常用的几个字型码集合
1.
A-F={0x77,0x7C,0x39,0x5E,0x79,0x71}
2.
0-9={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F}
3.
0-F={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F,0x77,0x7C,0x39,0x5E,0x79,0x71}
4.
A-Y={0x77,0x7C,0x39,0x5E,0x79,0x71,0x76,0x38,0x73,0x31,0x3E,0x6E}
4、C51单片机数码管位选码
0xFF,0xFB,0xF7,0xF3,0xFE,0xEB,0xE7,0xE3
二、数码管显示0-F程序代码
#include <reg52.h>
#define GPIO2 P2
#define GPIO P0
#define uint unsigned int
#define uchar unsigned char
void delay_xms(uint xms);
uchar SEG_Code[]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F,0x77,0x7C,0x39,0x5E,0x79,0x71};
void main(void)
{
uint i;
while(1)
{
for(i=0;i<16;i++)
{
GPIO2=0xFE;
GPIO=SEG_Code[i];
delay_xms(500);
}
}
}
void delay_xms(uint xms)
{
uint i;
while(xms--)
{
for(i=0;i<234;i++);
}
}
三、数管码显示2023程序代码
#include <reg52.h>
#define uchar unsigned char // UINT8, u8
#define uint unsigned int // UINT16, u16
#define GPIO P0
#define GPIO2 P2
#define XMS 5
uchar SEG_Code[4] = {0x5B, 0x3F, 0x5B, 0x4F}; // 2023的段码
uchar SEG_Bit[4] = {0xFF,0xFB, 0xF7, 0xF3}; // 数码管位选端位码
void delay_xms(uint xms);
void main(void)
{
uchar i;
GPIO = 0xFF; // 初始化端口
GPIO2 = 0xFF;
while(1)
{
for(i=0; i<4; i++)
{
GPIO = SEG_Code[i];
GPIO2 = SEG_Bit[i];
delay_xms(XMS);
GPIO = 0xFF; // 消隐
}
}
}
void delay_xms(uint xms)
{
uint i;
while(xms--)
{
for(i=0; i<234; i++);
}
}