当前位置:网站首页>【单片机】【数码管】数码管显示
【单片机】【数码管】数码管显示
2022-07-01 11:44:00 【sinat_41752325】
1. 数码管的显示器及其接口
单片机系统中 常用的显示器有: 发光二极管LED显示器、液晶LCD显示器、TFT液晶显示器。本文主要是关于LED显示器的说明。
LED显示器有两种显示结构:段显示(7段、米字型等)和点阵显示(5x8、8x8点阵等)。
LED数码管根据接法可以分为共阴和共阳。
如下图中,左边是共阴接法,右边是共阳接法。共阴表示8个led的阴极接到一起,共阳是8个led的阳极接到一起。

显示数字或字符时需要编码。如果是共阴接法,那么a/b/c/d/e/f/g/dp为高电平时对应的led就会亮,编码0~F分别是:

2. 数码管静态显示原理
LED显示器工作方式有两种:静态显示方式和动态显示方式。静态显示的特点是每个数码管的段选必须接一个8位数据线来保持显示的字形码。当送入依次字形码后,显示字形可一直保持,知道送入新字形码为止,这种方法的优点是占用CPU时间少,显示便于监测和控制。缺点是硬件电路比较复杂,成本较高。
3. 数码管原理图
如下是普中51-单核-A2板子上的数码管模块原理图,可以看到,右上有8个数码管用来显示字符,这8个数码管一端分别与LED1~LED8连接,另一端与P0口连接,所以通过控制P0口来显示我们需要的字符;LED1~LED8通过74HC138译码器与P2^2、P2^3、P2^4连接,这三个IO口控制是哪一个LED可以显示。


静态数码管显示,第一个数码管显示字符F
sbit P22 = P2^2;
sbit P23 = P2^3;
sbit P24 = P2^4;
#define LCD P0
typedef unsigned char u8;
// code保存数据到寄存器中
u8 code segment[] = {0x3f,0x06,0x5b,0x4f,0x66,
0x6d,0x7d,0x07,0x7f,0x6f,
0x77,0x7c,0x39,0x5e,0x79,0x71};
void show_LCD_static()
{
// LED1显示字符F
P22 = 1;
P23 = 1;
P24 = 1;
P0 = segment[15];
while(1){}
}显示结果:

动态数码管显示,从第一个数码管开始依次显示0,1,2,3,4,5,6,7
#include "LCD.h"
#include "reg51.h"
#include "delay.h"
sbit P22 = P2^2;
sbit P23 = P2^3;
sbit P24 = P2^4;
#define LCD P0
typedef unsigned char u8;
// code保存数据到寄存器中
u8 code segment[] = {0x3f,0x06,0x5b,0x4f,0x66,
0x6d,0x7d,0x07,0x7f,0x6f,
0x77,0x7c,0x39,0x5e,0x79,0x71};
void show_P0_0()
{
u8 i;
for(i=0;i<8;i++)
{
switch(i)
{
case 0:
P22 = 1; P23 = 1; P24 = 1; break;
case 1:
P22 = 0; P23 = 1; P24 = 1; break;
case 2:
P22 = 1; P23 = 0; P24 = 1; break;
case 3:
P22 = 0; P23 = 0; P24 = 1; break;
case 4:
P22 = 1; P23 = 1; P24 = 0; break;
case 5:
P22 = 0; P23 = 1; P24 = 0; break;
case 6:
P22 = 1; P23 = 0; P24 = 0; break;
case 7:
P22 = 0; P23 = 0; P24 = 0; break;
}
P0 = segment[i];
delay_ms(500); // delay.h中的延时函数
P0 = 0;
}
}显示结果:

上图的连接中左边的数码管1对应的是74HC138的15pin,即Y0,也就是74HC138的ABC都是0的时候输出对应的是Y0,正好对应的是代码中P22=P23=P24=0时,显示7.
边栏推荐
- How to make the development of liquidity pledge mining system, case analysis and source code of DAPP defi NFT LP liquidity pledge mining system development
- 伸展树(一) - 概念和C实现
- Openinstall: wechat applet jump to H5 configuration service domain name tutorial
- [buuctf.reverse] 144_ [xman2018 qualifying]easyvm
- Impressive bug summary (continuously updated)
- Tianrunyun, invested by Tian Suning, was listed: its market value was 2.2 billion Hong Kong, and its first year profit decreased by 75%
- Tempest HDMI leak reception 4
- Redis configuration environment variables
- Learning summary on June 30, 2022
- 力扣首页简介动画
猜你喜欢

CPI tutorial - asynchronous interface creation and use

Exposure: a white box photo post processing framework reading notes

CAD如何设置标注小数位

Software project management 9.2 Software project configuration management process

Face detection and recognition system based on mtcnn+facenet

2022/6/30学习总结

Learning summary on June 29, 2022

Adjacency matrix undirected graph (I) - basic concepts and C language

ABBIRB120工业机器人机械零点位置

Chen Gong: Micro service, is it still so pure?
随机推荐
[Maui] add click events for label, image and other controls
用于分类任务的数据集划分脚本
Deep understanding of grpc part1
CAD如何設置標注小數比特
Shangtang entered the lifting period: the core management voluntarily banned and strengthened the company's long-term value confidence
Width and widthstep of iplimage
Face detection and recognition system based on mtcnn+facenet
TEMPEST HDMI泄漏接收 4
redis中value/String
Redis startup and library entry
Xiaomi mobile phone unlocking BL tutorial
证券账户随便哪里开都能使用吗 开户安全吗
Building external modules
Chen Gong: Micro service, is it still so pure?
耐克如何常年霸榜第一名?最新财报答案来了
IPlImage的width和widthStep
redis中value/hush
I'm in Zhongshan. Where is a better place to open an account? Is it actually safe to open an account online?
二叉堆(一) - 原理与C实现
Compile and debug net6 source code