標題: 單片機基礎(chǔ)1-9999計數(shù)器 [打印本頁]

作者: 張中瓊    時間: 2023-12-12 15:05
標題: 單片機基礎(chǔ)1-9999計數(shù)器
  1. #include<reg51.h>
  2. unsigned char code table1[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7c,0x07,0x7f,0x67};
  3. unsigned char code table2[]={0xf7,0xfb,0xfd,0xfe};
  4. unsigned char i,num;
  5. unsigned int count;
  6. void delay(int);
  7. main()
  8. {
  9.   while(1)
  10.   {       
  11.         {if(count==9999)count=0;}
  12.         count++;
  13.         for(num=0;num<200;num++)
  14.         {P0=0x00;
  15.          P2=table2[0];
  16.          P0=table1[((count%1000)%100)%10];
  17.          delay(1);

  18.          P0=0x00;
  19.          P2=table2[1];
  20.          P0=table1[((count%1000)%100)/10];
  21.          delay(1);

  22.          P0=0x00;
  23.          P2=table2[2];         
  24.          P0=table1[(count%1000)/100];
  25.          delay(1);

  26.          P0=0x00;
  27.          P2=table2[3];
  28.          P0=table1[count/1000];
  29.          delay(1);
  30.          }       
  31.   }       
  32. }
  33. void delay(int x)
  34. {
  35.   int i,j;
  36.   for(i=0;i<x;i++)
  37.      for(j=1;j<=150;j++);
  38. }
復(fù)制代碼

1-9999計數(shù)器.zip (66.42 KB, 下載次數(shù): 19)





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