zoukankan      html  css  js  c++  java
  • C51学习 之 动态数码管

    电路图

    动态数码管代码

     1 //以下代码未经过验证
     2 #include <reg52.h>
     3 
     4 sbit WELA = P2^7;
     5 sbit DULA = P2^6;
     6 unsigned char count = 0;
     7 unsigned char code_count = 0;
     8 unsigned char code[] = {0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f, 0x77, 0x7c, 0x39, 0x5e, 0x79, 0x71};
     9 
    10 void init()
    11 {
    12     WELA = 0;
    13     DULA = 0;
    14     P0 = 0x0;
    15 }
    16 
    17 void delay(unsigned int value)
    18 {
    19     while(value--);
    20 }
    21 
    22 int main()
    23 {
    24     init();
    25     
    26     while (1) {
    27         //位选  低电平有效
    28         WELA = 1;
    29         P0 = ~(0x1 << count);
    30         WELA = 0;
    31 
    32         //消影
    33         P0 = 0x0;
    34         
    35         //段选   高电平有效
    36         DULA = 1;
    37         P0 = code[code_count];
    38         DULA = 0;
    39         
    40         //消影
    41         P0 = 0xff;
    42         
    43         delay(50000);  //500ms
    44         
    45         count++;
    46         if (count == 8) {
    47             count = 0;
    48         }
    49         code_count++;
    50         if (code_count == 16) {
    51             code_count = 0;
    52         }
    53     }
    54 }
  • 相关阅读:
    Cocos2d-x之Vector<T>
    Cocos2d-x之Array
    Cocos2d-x之Value
    Cocos2d-x之String
    Cocos2d-x中使用的数据容器类
    Cocos2d-x之Action
    Cocos2d-x之定时器
    Cocos2d-x之MessageBox
    Cocos2d-x之Log输出机制
    Cocos2d-x之事件处理机制
  • 原文地址:https://www.cnblogs.com/wangfeicom/p/14827895.html
Copyright © 2011-2022 走看看