zoukankan      html  css  js  c++  java
  • 共阳数码管的动态显示

    动态数码管硬件实现原理

    1.动态显示实际上是轮流点亮单个数码管实现多位数码管整体显示的效果。

    2.在轮流显示过程中,每位数码管点亮时间为1~2ms,由于人的视觉暂留现象以及二极管的余辉效应,尽管实际上各位数码管并非同时点亮,但是只要扫描的速度足够快,给人呈现出的就是一组稳定的显示数据,不会有闪烁感。动态显示的效果跟静态显示是一样的,但是可以节省大量的IO端口,而且功耗更低。

    静态显示I/O端口:8个段码*4+4个COM端=36个I/O端口引脚

    动态显示I/O端口:8个段码+4个COM端=12个I/O端口引脚

    代码实现

     1 #include "reg52.h"
     2 
     3 typedef unsigned int u16;
     4 typedef unsigned char u8;
     5 
     6 u16 month=12;
     7 u8 code smgduan[18]=
     8         {0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,
     9          0x80,0x90,0x88,0x80,0xc6,0xc0,0x86,0x8e,
    10          0xbf,0x7f};
    11 
    12 void delay(u16 i)
    13 {
    14     while (i--);
    15 }
    16     
    17 
    18 
    19 void HC537Init(u16 t)
    20 {
    21     switch (t)
    22     {
    23         case 4:
    24             P2=(P2 & 0x1f) | 0x80;
    25         break;
    26         
    27         case 5:
    28             P2=(P2 & 0x1f) | 0xa0;
    29         break;
    30         
    31         case 6:
    32             P2=(P2 & 0x1f) | 0xc0;
    33         break;
    34         
    35         case 7:
    36             P2=(P2 & 0x1f) | 0xe0;
    37         break;
    38     }
    39 }
    40 
    41 void SMG_BIT(u8 value,u8 pos)
    42 {
    43     HC537Init(6);
    44     P1=0x01 << pos;
    45     HC537Init(7);
    46     P1=value;
    47 }
    48 
    49 void Display()
    50 {
    51     SMG_BIT(smgduan[2],0);
    52     delay(500);
    53     SMG_BIT(smgduan[0],1);
    54     delay(500);
    55     SMG_BIT(smgduan[1],2);
    56     delay(500);
    57     SMG_BIT(smgduan[8],3);
    58     delay(500);
    59     SMG_BIT(smgduan[16],4);
    60     delay(500);
    61     SMG_BIT(smgduan[16],5);
    62     delay(500);
    63     
    64     SMG_BIT(smgduan[month/10],6);
    65     delay(500);
    66     SMG_BIT(smgduan[month]%10,7);
    67     delay(500);
    68     
    69 }
    70 
    71 void Delay(u16 k)
    72 {
    73     while(k--)
    74     {
    75         Display();
    76     }
    77 }
    78 
    79 void main()
    80 {
    81     while(1)
    82     {
    83         Display();
    84         if(month > 12)
    85         {
    86             month =1;
    87         }
    88         Delay(200);
    89     }
    90     
    91 }
  • 相关阅读:
    经典笔试题:用C写一个函数测试当前机器大小端模式
    一个结构体传递方式的问题
    ESP8266 NON-OS SDK 和 RTOS SDK实现GPIO中断不同点
    关于C语言中内存的3个问题
    ESP8266 station模式下建立client、server TCP连接
    连续更新了42天早报之后
    简单socket()编程
    TCP协议学习
    linux系统如何管理文件
    Linux文件操作的主要接口API及相关细节
  • 原文地址:https://www.cnblogs.com/kevinkala/p/12920349.html
Copyright © 2011-2022 走看看