找回密码
 立即注册

QQ登录

只需一步,快速开始

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

数码管5min倒计时(单片机定时器中断)

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


单片机源程序如下:
  1. #include<reg51.h>
  2. unsigned char Seg_CA_Data[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};
  3. unsigned char Seg_CA_Position[]={0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01};
  4. void DelayTime10ms(unsigned int DelayValue);
  5. void Seg_Display_Second(unsigned char DisData,unsigned char Seg_Number);
  6. void Seg_Display_Minute(unsigned char DisData,unsigned char Seg_Number);
  7. unsigned char Second =59;
  8. unsigned char Minute=4;
  9. unsigned char         Count=0;
  10. void main()
  11. {
  12. EA=1;
  13. ET0=1;
  14. PT0=1;
  15. TMOD=0x01;

  16. TL0=(65536-50000)%256;
  17. TH0=(65536-50000)/256;
  18. TR0=1;



  19. for(;;)
  20. {
  21.   Seg_Display_Second(Second,2);
  22.   Seg_Display_Minute(Minute,2);
  23. }
  24. }
  25. void DelayTime10ms(unsigned int DelayValue)
  26. {
  27. unsigned int a,b;
  28. for(a=0;a<DelayValue;a++)
  29. for(b=0;b<1828;b++);
  30. }
  31. void Seg_Display_Second(unsigned char DisData,unsigned char Seg_Number)
  32. {
  33. unsigned char i=0;
  34. for(i=0;i<Seg_Number;i++)
  35. {
  36. P2=Seg_CA_Position[i];
  37. P0=Seg_CA_Data[DisData%10];
  38. DisData=DisData/10;
  39. DelayTime10ms(1);
  40. }
  41. }
  42. void Seg_Display_Minute(unsigned char DisData,unsigned char Seg_Number)
  43. {
  44. unsigned char i=0;
  45. P2=Seg_CA_Position[2];
  46. P0=0xbf;
  47. DelayTime10ms(1);
  48. for(i=3;i<Seg_Number+3;i++)
  49. {
  50. P2=Seg_CA_Position[i];
  51. P0=Seg_CA_Data[DisData%10];
  52. DisData=DisData/10;
  53. DelayTime10ms(1);
  54. }
  55. }
  56. void Irq_Timer_0() interrupt 1
  57. {
  58. TL0=(65536-50000)%256;
  59. TH0=(65536-50000)/256;
  60. Count++;
  61. if(Count==20)
  62.    {
  63.         Count=0;
  64.         if(Second--==0)
  65.         {
  66.          Second=59;
  67.          if(Minute--==0)
  68.          {
  69.          Second=59;
  70.          Minute=4;
  71.          }
  72.         }
  73.         }
  74. }
复制代码

所有资料51hei提供下载:
数码管5min倒计时(定时器中断).rar (33.86 KB, 下载次数: 16)


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

使用道具 举报

沙发
ID:552535 发表于 2019-6-10 22:05 | 只看该作者
程序可以用但是小白表示看不懂
回复

使用道具 举报

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

本版积分规则

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

Powered by 单片机教程网

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