mcpigdull

代码:【自己写的,初学者水平不高,但是能实现,如果有错误或者是可以优化,请评论区留言,不喜勿喷】

#include<reg51.h>
unsigned char code tab[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f}; 
sbit K1=P3^0;
sbit K2=P3^1;
sbit A1=P1^0;
sbit B1=P1^1;
sbit C1=P1^2;
void delay(int i) //i * 1ms
{
    int x,y;
    for(x=0;x<i;x++)
    for(y=0;y<120;y++); //1ms  
}
main()
{
    int num=0;K1=1,K2=1;
    while(1)
    {    
        if(K1==0)
        {
            delay(500);//如果觉得数字跳得太快了,就改这里,这里是防抖的,一般设置20-500就好了,看情况来
            num++;
            if(num>99)
                num=0;
        }
        if(K2==0)
        {
            delay(500);//这里同上面,也是防抖的
            num--;
            if(num<0)                 
                num=99;
        }
        A1=0;B1=1;C1=1;
        P0=tab[num/10];
        delay(1);
        P0=0x00;

        A1=1;B1=1;C1=1;
        P0=tab[num%10];
        delay(1);
        P0=0x00;
    }
}

 


protues仿真:


 

分类:

技术点:

相关文章:

  • 2022-01-02
  • 2021-09-01
  • 2021-11-18
  • 2021-06-12
  • 2022-12-23
  • 2021-11-18
  • 2021-06-17
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-10-13
  • 2021-11-25
  • 2021-09-13
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案