首页 > 其他分享 >51单片机实验2:静态数码管

51单片机实验2:静态数码管

时间:2023-11-21 18:31:42浏览次数:40  
标签:case LSB LSC LSA 数码管 51 break 单片机

数码管介绍

共阳极数码管是指将所有发光二极管的阳极接到一起形成公共阳极的数码管,共阳极数码管在应用时将公共端接到+5V。

共阴极数码管是指将所有发光二极管的阳极接到一起形成公共阴极的数码管,共阴极数码管在应用时将公共端接到GND。

硬件设计

74HC138译码器

51单片机实验2:静态数码管_数码管

管脚说明

51单片机实验2:静态数码管_单片机_02

真值表(低电平有效)

51单片机实验2:静态数码管_单片机_03

51单片机实验2:静态数码管_单片机_04

P0口是段选,LEDx(x=1~8)是位选。

软件设计

#include "reg52.h"
typedef unsigned int u16;
typedef unsigned char u8;
#define PORT          P0
#define LSA           P22
#define LSB           P23
#define LSC           P24
u8 gsmg_code[] = {0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07,
                    0x7f, 0x6f, 0x77, 0x7c, 0x39, 0x5e, 0x79, 0x71};
void delay_10us(u16 ten_us)
{
    while (ten_us--);
}
void display(u8 dat[], u8 pos1)
{
    u8 i= 0;
    u8 pos = pos1 - 1;
    for (i = pos; i < 8; i++) {
        switch (i) {
            case 0:LSC = 1;LSB = 1;LSA = 1;break;
            case 1:LSC = 1;LSB = 1;LSA = 0;break;
            case 2:LSC = 1;LSB = 0;LSA = 1;break;
            case 3:LSC = 1;LSB = 0;LSA = 0;break;
            case 4:LSC = 0;LSB = 1;LSA = 1;break;
            case 5:LSC = 0;LSB = 1;LSA = 0;break;
            case 6:LSC = 0;LSB = 0;LSA = 1;break;
            case 7:LSC = 0;LSB = 0;LSA = 0;break;
        }
        PORT = gsmg_code[dat[i-pos]];
        delay_10us(10);//消影
        PORT = 0x00;
    }
}
void main()
{
    u8 dat[8] = {1, 2, 3, 4, 5, 6, 7,8};
    while (1)
    {
    display(dat,1);
    } 
}

实验现象

51单片机实验2:静态数码管_单片机_05

标签:case,LSB,LSC,LSA,数码管,51,break,单片机
From: https://blog.51cto.com/u_16299102/8505870

相关文章

  • 7段数码管绘制
    importturtle,datetimeimporttimedefdrawGap():turtle.penup()turtle.fd(5)defdrawLine(draw):drawGap()turtle.pendown()ifdrawelseturtle.penup()turtle.fd(40)drawGap()turtle.right(90)defdrawDigit(d):drawLine(T......
  • 适用于广泛的物联网应用RM500QAEAA-M20-SGASA、EG25GGB-MINIPCIE、EM06ELA-512-SGAS网
    1、RM500QAEAA-M20-SGASA是一款5Gsub-6GHzM.2模块,尺寸为52.0mm×30.0mm×2.3mm,符合3GPPRelease15规范,针对工业和商业物联网及eMBB应用进行了优化。它支持独立(SA)和非独立(NSA)模式,最大下行链路速率为2.5Gbps,最大上行链路速率为900Mbps。RM500QAEAA-M20-SGASA支持Q......
  • 7段数码管绘制
    importturtleimportdatetimeimporttimedefdraw_gap():#画数码间隔turtle.penup()turtle.fd(5)defdraw_line(draw):#画单段数码管draw_gap()turtle.pendown()ifdrawelseturtle.penup()turtle.fd(40)draw_gap()turtle.r......
  • 7段数码管绘制
       ......
  • 7段数码管绘制
    importturtle,datetimedefdrawGap():#绘制数码管间隔turtle.penup()turtle.fd(5)defdrawLine(draw):#绘制单段数码管drawGap()turtle.pendown()ifdrawelseturtle.penup()turtle.fd(40)drawGap()turtle.right(90)defdrawDigit(d):#......
  • 7段数码管绘制
    importturtleimportdatetimeimporttimedefdraw_gap():#绘制数码间隔turtle.penup()turtle.fd(5)defdraw_line(draw):#绘制单段数码管draw_gap()turtle.pendown()ifdrawelseturtle.penup()turtle.fd(40)draw_gap()turtle.right(90)def......
  • 7段数码管绘制
    要求:画出,系统时间。具体包括:小时,分,秒,星期。 importturtleastimporttimea=time.strftime('%a',time.localtime())ifa=='Mon':c=1elifa=='Tue':c=2elifa=='Wed':c=3elifa=='Thu':c=4elif......
  • 七段数码管显示时间
    importturtleimportdatetimeimporttimedefdraw_gap():#绘制数码间隔turtle.penup()turtle.fd(5)defdraw_line(draw):#绘制单段数码管draw_gap()turtle.pendown()ifdrawelseturtle.penup()turtle.fd(40)draw_gap()turt......
  • 数码管
    #数码管显示系统年,月,日,时间1importturtle,datetime2defdrawling(draw):34turtle.pendown()ifdrawelseturtle.penup()5turtle.fd(40)6turtle.right(90)78defdraworigin(d):9drawling(True)ifdin[2,3,4,5,6,8,9]elsedr......
  • 7段数码管绘制
    7段数管码代码运行22信计1班34号代码#e7.2DrawSevenSegDisplay.pyimportturtle,datetimedefdrawGap():#绘制数码管间隔turtle.penup()turtle.fd(5)defdrawLine(draw):#绘制单段数码管drawGap()turtle.pendown()ifdrawelseturtle.penup()turtle......