• protues仿真 51点亮点阵


    电路图

    matrix

    程序

     1 /*==============================
     2     点亮点阵心形
     3 ================================*/
     4 #include <REGX51.H>
     5 #include <intrins.h>
     6 
     7 #define uchar unsigned char
     8 #define uint unsigned int
     9 
    10 sbit st_cpA = P1^4;
    11 sbit sh_cpA = P1^7;
    12 sbit dsA = P1^6;
    13 
    14 sbit st_cpB = P1^2;
    15 sbit sh_cpB = P1^0;
    16 sbit dsB = P1^1;
    17 
    18 void sendMessageA(uchar messageA);//发送一个字节到移位寄存器中    列
    19 void outputMessageA();//输出到存储寄存器中
    20 void sendMessageB(uchar messageB);                                  //
    21 void outputMessageB();
    22 void delay(uchar time_delay);
    23 
    24 uchar code rows[] = { 0x01, 0x02, 0x04, 0x08,
    25                       0x10, 0x20, 0x40, 0x80};
    26 uchar code cols[] = { 0xc9, 0xb6, 0xbe, 0xdd,
    27                       0xeb, 0xf7, 0xff, 0xff}; 
    28 void main()
    29 {     
    30     uchar i = 0;
    31     while(1)
    32     {
    33         //扫描显示
    34         for(i = 0; i < 8; i++)
    35         {
    36             sendMessageB(rows[i]);
    37             outputMessageB();
    38             sendMessageA(cols[i]);
    39             outputMessageA();
    40             //delay(5000);
    41         }    
    42     }    
    43 }
    44 
    45 void sendMessageA(uchar messageA)
    46 {
    47     uchar i = 0;
    48     for(; i < 8; i ++)
    49     {
    50         sh_cpA = 0;
    51         dsA = messageA & 0x80;//先写入最高位
    52         messageA = messageA << 1;//左移移位
    53         sh_cpA = 1;
    54     }
    55 }
    56 void sendMessageB(uchar messageB)
    57 {
    58     uchar i = 0;
    59     for(; i < 8; i ++)
    60     {
    61         sh_cpB = 0;
    62         dsB = messageB & 0x80;//先写入最高位
    63         messageB = messageB << 1;//左移移位
    64         sh_cpB = 1;
    65     }
    66 }
    67 void outputMessageA()
    68 {
    69     st_cpA = 0;
    70     _nop_();
    71     st_cpA = 1;
    72 }
    73 void outputMessageB()
    74 {
    75     st_cpB = 0;
    76     _nop_();
    77     st_cpB = 1;
    78 }
    79 //延时函数
    80 void delay(uchar time_delay)
    81 {
    82     uchar x,y;
    83     for(x = time_delay; x > 0; x --)
    84         for(y = time_delay; y > 0; y--)
    85         {}
    86 }
  • 相关阅读:
    javaScript 事件循环机制
    javaScript 原型与原型链
    清除浮动
    水平垂直居中的实现
    GitLab + Jenkins + Harbor 工具链快速落地指南
    a标签下载存储在项目中的文件
    判断数组对象中某一属性是否包含重复的值
    网站title前的小图标
    给二维数组动态赋值
    格式化eltable中的时间
  • 原文地址:https://www.cnblogs.com/huifeidewoniu/p/3430180.html
Copyright © 2020-2023  润新知