找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 2660|回復(fù): 0
收起左側(cè)

基于單片機的秒表設(shè)計 帶仿真文件和源程序

[復(fù)制鏈接]
ID:85698 發(fā)表于 2015-7-14 20:59 | 顯示全部樓層 |閱讀模式
基于單片機的秒表設(shè)計

  1. /****************************/
  2. /*          題2-13 C語言程序                */
  3. /****************************/

  4. #include <reg51.h>
  5. #define uint unsigned int
  6. #define uchar unsigned char

  7. sbit s1=P3^1;
  8. sbit wei1=P2^0;
  9. sbit wei2=P2^1;

  10. uchar code table[]={
  11. 0x3f,0x06,0x5b,0x4f,
  12. 0x66,0x6d,0x7d,0x07,
  13. 0x7f,0x6f,0x77,0x7c,
  14. 0x39,0x5e,0x79,0x71};

  15. uchar shi,ge;
  16. uint count,second,keycount;

  17. void init();
  18. void key();
  19. void delayms(uint z);
  20. void display(uchar shi,uchar ge);

  21. void main()
  22. {
  23.   init();
  24.   while(1)
  25.   {
  26.     key();
  27.     display(shi,ge);
  28.   }
  29. }

  30. void init()
  31. {
  32.   TMOD=0x10;
  33.   TH1=(65536-20000)/256;
  34.   TL1=(65536-20000)%256;
  35.   TR1=0;
  36.   EA=1;
  37.   ET1=1;
  38. }

  39. void delayms(uint z)
  40. {
  41.   uint x,y;
  42.   for(x=z;x>0;x--)
  43.     for(y=110;y>0;y--);
  44. }

  45. void key()
  46. {
  47.   if(s1==0)
  48.    {
  49.      delayms(5);
  50.          if(s1==0)
  51.            {
  52.                  while(!s1);
  53.                  keycount++;
  54.                  switch(keycount)
  55.                   {
  56.                    case 1: TR1=1;break;
  57.                    case 2: TR1=0;break;
  58.                    case 3:
  59.                     {
  60.                       keycount=0;
  61.                           count=0;
  62.                       second=0;
  63.                       shi=second/10;
  64.               ge=second%10;
  65.                       display(shi,ge);
  66.                       TR1=0;
  67.                 }break;       
  68.                  }
  69.            }
  70.    }
  71. }

  72. void display(uchar shi,uchar ge)
  73. {
  74.   P0=table[shi];
  75.   wei1=0;
  76.   delayms(1);
  77.   wei1=1;
  78.   P0=table[ge];
  79.   wei2=0;
  80.   delayms(1);
  81.   wei2=1;
  82. }

  83. void timer1() interrupt 3
  84. {
  85.   TH1=(65536-20000)/256;
  86.   TL1=(65536-20000)%256;
  87.   count++;
  88.   if(count==50)
  89.    {
  90.      count=0;
  91.          second++;
  92.          if(second==11)second=0;
  93.    }
  94.    shi=second/10;
  95.    ge=second%10;
  96. }
復(fù)制代碼


基于單片機的秒表設(shè)計.rar

43.21 KB, 下載次數(shù): 57, 下載積分: 黑幣 -5

智能秒表

評分

參與人數(shù) 1黑幣 +50 收起 理由
admin + 50 共享資料的積分獎勵!

查看全部評分

相關(guān)帖子

回復(fù)

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機教程網(wǎng)

快速回復(fù) 返回頂部 返回列表