求单片机大神解答,谢谢。。。。。。。。。急求。。。。

2025-04-13 04:52:29
推荐回答(1个)
回答1:

这个简单 


没有格子 你就从上往下看吧  那看不明白 问我吧 

  1. # include


  2. unsigned char code tab[]={0xc0, 0xf9, 0xa4, 0xb0,

  3.  0x99, 0x92, 0x82, 0xf8,

  4.  0x80, 0x90, 0x88, 0x83,

  5.  0xc6, 0xa1, 0x86, 0x8e,};  


  6. sbit aj1 = P1^0;


  7. void delay(unsigned int z)

  8. {

  9. unsigned int x,y;

  10. for(x=z;x>0;x--)

  11. for(y=110;y>0;y--);

  12. }


  13. void main()

  14. {

  15. P0 = 0xff;


  16.    while(1)

  17.    {

  18. if(aj1==0)

  19. {

  20. delay(5);

  21. if(aj1==0)

  22. {

  23. P0= tab[1];

  24. while(!aj1);

  25. }

  26. }

  27. if(aj1==0)

  28. {

  29. delay(5);

  30. if(aj1==0)

  31. {

  32. P0= tab[0];

  33.  

  34. while(!aj1);

  35. }

  36. }

  37.    }

  38. }



流水灯程序


# include


void delay500ms(void)     //时间500MS

{

    unsigned char a,b,c;

    for(c=98;c>0;c--)

        for(b=127;b>0;b--)

            for(a=17;a>0;a--);

  

}




void main()

{

unsigned char i,k;

while(1)

{

i=0xfe;

for(k=0;k<8;k++)

{

 P1=i;

 delay500ms();

 i=(i<<1)|0x01; 

}

}

}

当然还有别的写法