找回密码
 立即注册

QQ登录

只需一步,快速开始

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

10秒秒表 精确到0.1 proteus仿真

[复制链接]
跳转到指定楼层
楼主
10秒秒表  精确到0.1  
用proteus仿真
带源文件

仿真工程文件下载:
秒表.zip (55.81 KB, 下载次数: 50)



源程序:
  1. /*     名称:10s 的秒表
  2.        说明:首次按键计时开始,再次按键暂停,第三次按键清零。
  3. */
  4.           #include<reg51.h>
  5. #define uchar unsigned char
  6. #define uint unsigned int
  7. sbit K1=P3^7;
  8. uchar
  9. i,Second_Counts,Key_Flag_Idx;
  10. bit Key_State;
  11. uchar
  12. DSY_CODE[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
  13. //延时
  14. void DelayMS(uint ms)
  15. {
  16. uchar t;
  17. while(ms--) for(t=0;t<120;t++);
  18. }
  19. //处理按键事件
  20. void Key_Event_Handle()
  21. {
  22. if(Key_State==0)
  23. {
  24. Key_Flag_Idx=(Key_Flag_Idx+1)%3;
  25. switch(Key_Flag_Idx)
  26. {
  27. case 1: EA=1;ET0=1;TR0=1;break;
  28. case 2: EA=0;ET0=0;TR0=0;break;
  29. case 0: P0=0x3f;P2=0x3f;i=0;Second_Counts=0;
  30. }
  31. }
  32. }
  33. //主程序
  34. void main()
  35. {
  36. P0=0x3f; //显示 00
  37. P2=0x3f;
  38. i=0;
  39. Second_Counts=0;
  40. Key_Flag_Idx=0; //按键次数(取值 0,1,2,3)
  41. Key_State=1; //按键状态
  42. TMOD=0x01; //定时器 0 方式 1
  43. TH0=(65536-50000)/256; //定时器 0:15ms
  44. TL0=(65536-50000)%256;
  45. while(1)
  46. {
  47. if(Key_State!=K1)
  48. {
  49. DelayMS(10);
  50. Key_State=K1;
  51. Key_Event_Handle();
  52. }
  53. }
  54. }
  55. //T0 中断函数
  56. void DSY_Refresh() interrupt 1
  57. {
  58. TH0=(65536-50000)/256; //恢复定时器 0 初值
  59. TL0=(65536-50000)%256;
  60. if(++i==2) //50ms*2=0.1s 转换状态
  61. {
  62. i=0;
  63. Second_Counts++;
  64. P0=DSY_CODE[Second_Counts/10];
  65. P2=DSY_CODE[Second_Counts%10];
  66. if(Second_Counts==100) Second_Counts=0; //满 100(10s)后显示 00
  67. }
  68. }
复制代码


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

使用道具 举报

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

本版积分规则

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

Powered by 单片机教程网

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