標(biāo)題: 51單片機(jī)做頻率計(jì) [打印本頁]

作者: 158925    時間: 2018-12-12 18:28
標(biāo)題: 51單片機(jī)做頻率計(jì)

  1. #include <reg52.h>
  2. unsigned char code dispbit[]={0xef,0xdf,0xbf,0x7f};
  3. unsigned char code dispcode[]={0xc0,0Xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
  4. unsigned char dispbuf[4]={0,0,0,0};
  5. unsigned char temp[8];
  6. unsigned char dispcount;
  7. unsigned char T0count;
  8. unsigned char timecount;
  9. bit flag;
  10. unsigned long x;
  11. void main(void)
  12. {
  13. unsigned char i;
  14.         TMOD=0x15;
  15.         TH0=0;
  16.         TL0=0;
  17.         TH1=(65536-4000)/256;
  18.         TL1=(65536-4000)%256;
  19.         TR1=1;
  20.         TR0=1;
  21.         ET0=1;
  22.         ET1=1;
  23.         EA=1;
  24. while(1)
  25. {
  26. if(flag==1)
  27. {
  28. flag=0;
  29. x=T0count*65536+TH0*256+TL0;
  30. for(i=0;i<4;i++)
  31. {
  32. temp[i]=0;
  33. }
  34. i=0;
  35. while(x/10)
  36. {
  37. temp[i]=x%10;
  38. x=x/10;
  39. i++;
  40. }
  41. temp[i]=x;
  42. for(i=0;i<4;i++)
  43. {
  44. dispbuf[i]=temp[i];
  45. }
  46. timecount=0;
  47. T0count=0;
  48. TH0=0;
  49. TL0=0;
  50. TR0=1;
  51. }
  52. }
  53. }
  54. void t0(void) interrupt 1 using 0
  55. {
  56. T0count++;
  57. }
  58. void t1(void) interrupt 3 using 0
  59. {
  60. TH1=(65536-4000)/256;
  61. TL1=(65536-4000)%256;
  62. timecount++;
  63. if(timecount==250)
  64. {
  65. TR0=0;
  66. timecount=0;
  67. flag=1;
  68. }
  69. P0=dispcode[dispbuf[dispcount]];
  70. P2=dispbit[dispcount];
  71. dispcount++;
  72. if(dispcount==4)
  73. {
  74. dispcount=0;
  75. }
  76. }
復(fù)制代碼
全部資料51hei下載地址:
51黑論壇_簡易頻率計(jì) (1).zip (84.99 KB, 下載次數(shù): 12)







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