标题: 51单片机数码管程序 [打印本页]

作者: 111shws    时间: 2020-11-12 20:27
标题: 51单片机数码管程序
  1. #include<reg52.h>

  2. typedef unsigned char uchar;
  3. typedef unsigned int uint;

  4. sbit LSA = P2^2;
  5. sbit LSB = P2^3;
  6. sbit LSC = P2^4;
  7. uchar time [] ={2,0,2,0,1,1,0,7};
  8. uchar code smgduan[17]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
  9.                                         0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};//显示0~F的值

  10.                                        
  11. //延时函数,i=1;延时大约等于1us                                       
  12. void delay(uint i)
  13. {
  14. while(i--);
  15. }
  16. void DigDisplay()
  17. {
  18.         uchar i;
  19.         for(i= 0 ; i<8;i++)
  20.         {
  21.                 switch(i)
  22.                 {
  23.                         case 7:
  24.                                 LSA=0; LSB=0; LSC=0; break; //显示1位;
  25.                         case 6:
  26.                                 LSA=1; LSB=0; LSC=0; break;//显示2位;
  27.                         case 5:
  28.                                 LSA=0; LSB=1; LSC = 0;break;//显示3位
  29.                                 case 4:
  30.                                 LSA=1; LSB=1; LSC=0; break; //显示4位;
  31.                         case 3:
  32.                                 LSA=0; LSB=0; LSC=1; break;//显示5位;
  33.                         case 2:
  34.                                 LSA=1; LSB=0; LSC =1;break;//显示6位
  35.                                 case 1:
  36.                                 LSA=0; LSB=1; LSC=1; break; //显示7位;
  37.                         case 0:
  38.                                 LSA=1; LSB=1; LSC=1; break;//显示8位;
  39.                 }
  40.                 P0 = smgduan[time[i]];
  41.                 delay(10000);
  42.                 P0 = 0X00;
  43.         }
  44. }
  45. void main ()
  46. {
  47.         while(1)
  48.         {
  49.         DigDisplay();
  50.         }
  51. }
复制代码





欢迎光临 (http://www.51hei.com/bbs/) Powered by Discuz! X3.1