51单片机,8位共阴极数码管动态显示12位学号,按键调整走动速度,C语言的

如题所述

#include <reg52.h>

#include <intrins.h>


sbit  k_add = P3^1;

sbit  k_sub = P3^4;



unsigned char code SEG7[] = {

    0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90, 0xff};

unsigned char DISP_BUFF[] = {

    10, 10, 10, 10, 10, 10, 10, 10, 

    1, 3, 9, 2, 5, 8, 0, 7, 4, 6, 3, 2,

    10, 10, 10, 10, 10, 10, 10, 10};


unsigned char  j = 0, k = 1;


void DelayMS(unsigned int x)

{

    unsigned char  i;

    while(x--)  for(i = 200; i > 0; i--);

}


void  display(unsigned char x)

{

    unsigned char i, w = 128;


    for(i = 0; i < 8; i++)  {

      P0 = SEG7[DISP_BUFF[i + k]];

      P2 = w;  DelayMS(1);   P2 = 0;

      w = _cror_(w, 1);

    }

    j++;

    if (j > x) {

      j = 0;

      k++; if (k == 20) k = 0;

    }

}


void main()

{

    unsigned char d = 30;

    while(1)  {

      if  (!k_add) {

        display(d);

        if  (!k_add) {

          d += 2;  if (d > 50)  d = 50;

          while (!k_add)  display(d);

        }

      }

      if  (!k_sub) {

        display(d);

        if  (!k_sub) {

          d -= 2;  if (d < 10)  d = 10;

          while (!k_sub)  display(d);

        }

      }

      display(d);

P1 = d;

    }

}

温馨提示:答案为网友推荐,仅供参考
第1个回答  2017-06-17
你好!是仿真实现还是有实物?要是实物的话,发一下原理图

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网