欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136

標題: 簡易頻率計單片機代碼 [打印本頁]

作者: zhangbin11    時間: 2017-4-3 21:58
標題: 簡易頻率計單片機代碼

  1. #include <AT89X51.H>
  2. //********數碼管位代碼表(P0口)**********//
  3. unsigned char code dispbit[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0x7f};
  4. //********數碼管段代碼表(P2口,共陰且高位接a,低位接h筆段)**********//   
  5. unsigned char code dispcode[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};
  6. //********8位數據緩沖器**********//                                          
  7. unsigned char dispbuf[8];            
  8. unsigned char temp[8];                  
  9. unsigned char dispcount;                 
  10. unsigned char T0count;
  11. unsigned char timecount;
  12. bit flag;                  
  13. unsigned long x;

  14. //*********初始化模塊**********//
  15. void initial(void){
  16. TMOD=0x15;                    
  17. TH0=0;
  18. TL0=0;
  19. TH1=(65536-4000)/256;
  20. TL1=(65536-4000)%256;
  21. TR1=0;
  22. TR0=0;
  23. ET0=1;
  24. ET1=1;
  25. EA=1;
  26. }
  27. //******************************************************//

  28. //*********顯示模塊**********//
  29. void dataDisplay(){
  30. unsigned char i;   
  31. for(i=0;i<8;i++){
  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<8;i++){
  43.    dispbuf[i]=temp[i];   
  44.     }   
  45. P2=dispcode[dispbuf[dispcount]];
  46. P0=dispbit[dispcount];
  47. dispcount++;
  48. if(dispcount==8)
  49. {
  50.    dispcount=0;
  51. }
  52. }
  53. //******************************************************//

  54. //*********信號頻率測量模塊**********//
  55. float frequency(float freq)
  56. {
  57. initial();
  58. TR0=1;TR1=1;
  59. if(timecount==250)
  60. {
  61.    TR0=0;
  62.    freq=T0count*65536+TH0*256+TL0;   
  63.    return(freq);
  64. }   
  65. }
  66. //******************************************************//

  67. //*********信號周期測量模塊**********//
  68. float cycle(float count){
  69. initial();
  70. if(P3_4==1){
  71.    TR0=1;TR1=1;
  72.    if(P3_4==0){
  73.     TR0=0;   
  74.     count=1000000/(timecount*4000+TH1*256+TL1-61536);
  75.    }
  76. }        
  77. return(count);
  78. }
  79. //******************************************************//

  80. //*********定時中斷服務程序1**********//
  81. void t1(void) interrupt 3 using 0{
  82. //initial();
  83. //TR0=1;
  84. //TR1=1;
  85. TH1=(65536-4000)/256;
  86. TL1=(65536-4000)%256;
  87. timecount++;
  88. }
  89. //******************************************************//

  90. //*********定時中斷服務程序2**********//
  91. void t0(void) interrupt 1 using 0{
  92. //initial();
  93. //TR0=1;
  94. //TR1=1;
  95. T0count++;
  96. }
  97. //******************************************************//

  98. //*********主函數**********//
  99. void main(void){
  100. while(1){  
  101.    x=frequency(x);
  102.    if(x<100){
  103.     x=cycle(x);
  104.    }
  105.    dataDisplay();
  106. }
  107. }
  108. //******************************************************//
復制代碼





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