標題: 單片機倒計時程序 [打印本頁]

作者: 不忘初心11    時間: 2016-12-2 16:36
標題: 單片機倒計時程序
  1. #include <at89x51.h>
  2. #define uchar unsigned char
  3. uchar display[10]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
  4. void yan10ms();
  5. void main()
  6. {
  7.    uchar i,n;
  8.    for(i=24;i>0;i--)
  9.    {
  10.        for(n=50;n>0;n--)
  11.            {
  12.                    if(i/10==0)
  13.                 {P0=0xff;}
  14.                    else
  15.                 {P2_1=0;P2_0=1;P0=display[i/10];}
  16.                 yan10ms();
  17.            P2_0=0;P2_1=1;P0=display[i%10];yan10ms();
  18.            }
  19.            P3_0=0;yan10ms();P3_0=1;
  20.    }
  21.     P2_0=0;P2_1=1;P0=display[0];P3_0=0;        while(1);
  22. }
  23. void yan10ms()   //10ms
  24. {
  25.   uchar i,j;
  26.     for(j=20;j>0;j--)
  27.           {for(i=250;i>0;i--);}
  28. }
復制代碼







歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1