找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 1429|回复: 0
打印 上一主题 下一主题
收起左侧

51单片机做频率计

[复制链接]
跳转到指定楼层
楼主

  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. }
复制代码
全部资料51hei下载地址:
51黑论坛_简易频率计 (1).zip (84.99 KB, 下载次数: 12)


分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 顶 踩
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表