找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 2705|回复: 0
收起左侧

单片机设计制作北京奥运会倒计时牌的仿真 实现年月日的倒计时功能

[复制链接]
ID:346816 发表于 2018-6-7 17:06 | 显示全部楼层 |阅读模式
本设计能实现年月日的倒计时功能,
北京奥运会倒计时牌仿真原理图如下(proteus仿真工程文件可到本帖附件中下载)
0.png 0.png

单片机源程序如下:
  1. /***************************************
  2. 名称:2008奥运会倒计时
  3. ***************************************/
  4. #include<reg51.h>
  5. #include<absacc.h>
  6. #include<intrins.h>
  7. #include "delay.h"
  8. #define clock_segment XBYTE[0xBFFF] //时钟段码地址
  9. #define clock_sel XBYTE[0x7FFF]     //时钟位码地址
  10. #define year_segment XBYTE[0xEFFF]  //日历段码地址
  11. #define year_sel XBYTE[0xDFFF]      //日历位码地址
  12. #define retime_segment XBYTE[0xFBFF]//倒计时段码地址
  13. #define retime_sel XBYTE[0xF7FF]    //倒计时位码地址

  14. unsigned char time_num=0;//定时一秒次数
  15. unsigned char shi_num=24;//小时位计数
  16. unsigned char miao_ge=0; //秒个位
  17. unsigned char miao_shi=0;//秒十位
  18. unsigned char fen_ge=0;//分个位
  19. unsigned char fen_shi=4;//分十位
  20. unsigned char shi_ge=8;//时个位
  21. unsigned char shi_shi=0;//时十位
  22. unsigned char year_thousand=2;
  23. unsigned char year_hundred=0;
  24. unsigned char year_decade=0;
  25. unsigned char year_unit=7;
  26. unsigned char month_decade=0;
  27. unsigned char month_unit=6;
  28. unsigned char day_decade=2;
  29. unsigned char day_unit=6;
  30. unsigned char retime_unit=0;
  31. unsigned char retime_decade=1;
  32. unsigned char retime_hundred=4;
  33. unsigned char retime_thousand=0;

  34. unsigned char year_thoustore; //保存年千位数据
  35. unsigned char year_hundstore; //保存年百位数据
  36. unsigned char year_decastore; //保存年十位数据
  37. unsigned char year_unitstore; //保存年个位数据
  38. unsigned char month_unitstore;//保存月个位数据
  39. unsigned char month_decastore;//保存月十位数据
  40. unsigned char day_unitstore;  //保存日个位数据
  41. unsigned char day_decastore;  //保存日十位数据
  42. unsigned char year_unitstore2;//保存年各位数据
  43. unsigned char year_decastore2;//年位组合子程序用来保护数据用
  44. unsigned char year_hundstore2;
  45. unsigned char year_thoustore2;
  46. unsigned char retime_ustore;  //保存倒计时各位数据
  47. unsigned char retime_dstore;
  48. unsigned char retime_hstore;
  49. unsigned char retime_tstore;
  50. unsigned char day_numj=31;  //奇数月31天
  51. unsigned char day_numo=30;  //偶数月30天
  52. unsigned char day_numooo=30;
  53. unsigned char day_numoo;
  54. unsigned char month_num=12;
  55. unsigned int year_jointed; //年各位组合在一起,以便进行闰年判断
  56. unsigned int year_help1;
  57. unsigned int year_help2;
  58. unsigned char xiaoshi_ge;//闪烁时存小时个位
  59. unsigned char xiaoshi_shi;//闪烁时存小时十位
  60. unsigned char fenzhong_ge;//闪烁时存分钟个位
  61. unsigned char fenzhong_shi;//闪烁时存分钟十位
  62. unsigned char cort=0;//判断第几次按下确认键
  63. sbit key_sure=P1^0;//调时或确认键
  64. sbit key_dec=P1^2;//调时减键
  65. bit first_sure=0; //第一次按下确认键
  66. bit second_sure=0;//第二次按下确认键
  67. bit third_sure=0; //第三次按下确认键
  68. bit fourth_sure=0;//第四次按下确认键
  69. bit fifth_sure=0; //第五次按下确认键
  70. bit sixth_sure=0; //第六次按下确认键
  71. bit seventh_sure=0;//第七次按下确认键
  72. unsigned code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x00};//段码表
  73. /************函数声明*************/
  74. void shannum_jian(void);
  75. void inc_key(void);
  76. void dec_key(void);
  77. void dis_dingshi(void);
  78. void hour_shanshuo(void);
  79. void min_shanshuo(void);
  80. void kbscan(void);
  81. void display(void);
  82. void year_joint(void);
  83. unsigned char judgement_leap(void);
  84. void retime_flash(void);
  85. /********************************
  86. 显示子程序
  87. *********************************/
  88. void display(void)
  89. {
  90.     clock_sel=0xdf;
  91.     clock_segment=table[miao_ge];        //送秒个位段位码
  92.     delay(3);
  93.     clock_sel=0xef;
  94.     clock_segment=table[miao_shi];       //送秒十位段位码
  95.     delay(3);
  96.     clock_sel=0xf7;
  97.     clock_segment=table[fen_ge]|0x80;    //送分个位段位码
  98.     delay(3);
  99.     clock_sel=0xfb;
  100.     clock_segment=table[fen_shi];        //送分十位段位码
  101.     delay(3);
  102.     clock_sel=0xfd;
  103.     clock_segment=table[shi_ge]|0x80;    //送时个位段位码
  104.     delay(3);
  105.     clock_sel=0xfe;
  106.     clock_segment=table[shi_shi];        //送时十位段位码
  107.     delay(3);
  108.     year_sel=0x7f;
  109.     year_segment=table[day_unit];        //送日个位段位码
  110.     delay(3);
  111.     year_sel=0xbf;
  112.     year_segment=table[day_decade];      //送日十位段位码
  113.     delay(3);
  114.     year_sel=0xdf;
  115.     year_segment=table[month_unit]|0x80; //送月个位段位码
  116.     delay(3);
  117.     year_sel=0xef;
  118.     year_segment=table[month_decade];    //送月十位段位码
  119.     delay(3);
  120.     year_sel=0xf7;
  121.     year_segment=table[year_unit]|0x80;  //送年个位段位码
  122.     delay(3);
  123.     year_sel=0xfb;
  124.     year_segment=table[year_decade];     //送年十位段位码
  125.     delay(3);
  126.     year_sel=0xfd;
  127.     year_segment=table[year_hundred];    //送年百位段位码
  128.     delay(3);
  129.     year_sel=0xfe;
  130.     year_segment=table[year_thousand];   //送年千位段位码
  131.     delay(3);
  132.     retime_sel=0xf7;
  133.     retime_segment=table[retime_unit];   //送倒计时个位段位码
  134.     delay(3);
  135.     retime_sel=0xfb;
  136.     retime_segment=table[retime_decade]; //送倒计时十位段位码
  137.     delay(3);
  138.     retime_sel=0xfd;
  139.     retime_segment=table[retime_hundred];//送倒计时百位段位码
  140.     delay(3);
  141.     retime_sel=0xfe;
  142.     retime_segment=table[retime_thousand];//送倒计时千位段位码
  143.     delay(3);

  144. }
  145. /**********************************
  146. 判断闰年子程序
  147. ***********************************/
  148. unsigned char judgement_leap(void)
  149. {
  150.     year_joint();       //调用年各位组合子程序
  151.     if((year_jointed%4==0&&year_jointed%100!=0)||(year_jointed%100==0&&year_jointed%400==0))return(29); //是闰年二月29天
  152.     else return(28);    //是平年二月28天       
  153. }
  154. /**********************************
  155. 按键扫描子程序
  156. ***********************************/
  157. void kbscan(void)
  158. {
  159.     unsigned char sccode;
  160.     P1=0xff;
  161.     if((P1&0xff)!=0xff)
  162.     {
  163.         //delay(5);
  164.         display();
  165.         display();
  166.         display();
  167.                            
  168.         if((P1&0xff)!=0xff)
  169.             {
  170.              sccode=P1;
  171.              //while((P1&0xff)!=0xff)     //按键后消陡
  172.                  //{
  173.                  //        ;
  174.                 // }
  175.              switch(sccode)
  176.                  {
  177.                 case 0xfe:shannum_jian();break;
  178.                 case 0xfd:inc_key();         break;
  179.                 case 0xfb:dec_key();         break;
  180.                 default:                                  break;
  181.                  }
  182.             }
  183.     }
  184. }
  185. /********************************
  186. 确认键按键次数子程序
  187. ********************************/
  188. void shannum_jian(void)
  189. {   
  190.     cort++;
  191.     if(cort==1)          //第一次按下确认键
  192.     {
  193.         first_sure=1;
  194.         second_sure=0;
  195.         third_sure=0;
  196.         fourth_sure=0;
  197.         fifth_sure=0;
  198.         sixth_sure=0;
  199.         seventh_sure=0;
  200.            
  201.     }
  202.     else if(cort==2)    //第二次按下确认键
  203.     {       
  204.         first_sure=0;
  205.         second_sure=1;
  206.         third_sure=0;
  207.         fourth_sure=0;
  208.         fifth_sure=0;
  209.         sixth_sure=0;
  210.         seventh_sure=0;
  211.            
  212.     }
  213.     else if(cort==3)    //第三次按下确认键
  214.     {
  215.         first_sure=0;
  216.         second_sure=0;
  217.         third_sure=1;
  218.         fourth_sure=0;
  219.         fifth_sure=0;
  220.         sixth_sure=0;
  221.         seventh_sure=0;
  222.            
  223.     }
  224.     else if(cort==4)   //第四次按下确认键
  225.     {
  226.         first_sure=0;
  227.         second_sure=0;
  228.         third_sure=0;
  229.         fourth_sure=1;
  230.         fifth_sure=0;
  231.         sixth_sure=0;
  232.         seventh_sure=0;
  233.                    
  234.     }
  235.     else if(cort==5)   //第五次按下确认键
  236.     {
  237.         first_sure=0;
  238.         second_sure=0;
  239.         third_sure=0;
  240.         fourth_sure=0;
  241.         fifth_sure=1;
  242.         sixth_sure=0;
  243.         seventh_sure=0;
  244.                    
  245.     }
  246.     else if(cort==6)   //第六次按下确认键
  247.     {
  248.             
  249.         first_sure=0;
  250.         second_sure=0;
  251.         third_sure=0;
  252.         fourth_sure=0;
  253.         fifth_sure=0;
  254.         sixth_sure=1;
  255.         seventh_sure=0;
  256.                    
  257.     }
  258.     else if(cort==7)  //第七次按下确认键
  259.     {
  260.         cort=0;
  261.         first_sure=0;
  262.         second_sure=0;
  263.         third_sure=0;
  264.         fourth_sure=0;
  265.         fifth_sure=0;
  266.         sixth_sure=0;
  267.         seventh_sure=1;
  268.     }               

  269. }
  270. /*******************************
  271. 减一键子程序
  272. *******************************/
  273. void dec_key(void)
  274. {
  275.     if(first_sure)                          //第一次按下确认键,小时位减
  276.     {
  277.         if(shi_num!=24)
  278.             {
  279.             ++shi_num;
  280.             if((--xiaoshi_ge)==255)
  281.                     {
  282.                 xiaoshi_ge=9;
  283.                 if((--xiaoshi_shi)==255)
  284.                         {
  285.                     xiaoshi_shi=2;
  286.                     xiaoshi_ge=3;
  287.                         }
  288.                 }       
  289.             }
  290.         else if(shi_num==24)
  291.             {
  292.             shi_num=1;
  293.             xiaoshi_ge=3;
  294.             xiaoshi_shi=2;
  295.             }
  296.     }
  297.     else if(second_sure)                         //第二次按下确认键,分钟位减
  298.     {
  299.         if((--fenzhong_ge)==255)
  300.             {
  301.             fenzhong_ge=9;
  302.             if((--fenzhong_shi)==255)
  303.                     {
  304.                 fenzhong_shi=5;
  305.                     }
  306.             }
  307.     }
  308.     else if(third_sure)                           //第三次按下确认键,年位减
  309.     {
  310.         if((--year_unitstore)==255)
  311.             {
  312.             year_unitstore=9;
  313.             if((--year_decastore)==255)
  314.                     {
  315.                 year_decastore=9;
  316.                 if((--year_hundstore)==255)
  317.                         {
  318.                     year_hundstore=9;
  319.                     if((--year_thoustore)==255)
  320.                                 {
  321.                         year_thoustore=9;
  322.                                 }
  323.                         }
  324.                     }
  325.             }
  326.     }
  327.     else if(fourth_sure)                        //第四次按下确认键,月位减
  328.     {
  329.         if(month_num!=12)
  330.             {
  331.               ++month_num;
  332.               if((--month_unitstore)==255)
  333.                   {
  334.                     month_unitstore=9;
  335.                     --month_decastore;
  336.                   }
  337.             }
  338.         else if(month_num==12)
  339.             {
  340.             month_num=1;
  341.             month_unitstore=2;
  342.             month_decastore=1;
  343.             }
  344.     }
  345.     else if(fifth_sure)                         //第五次按下确认键,日位减
  346.     {                                                                                            
  347.         if((month_unitstore|0xfe)==0xff)        //是奇数月,日为31天
  348.          {       
  349.             if((day_numj)!=31)
  350.                     {
  351.                 ++day_numj;
  352.                 if((--day_unitstore)==255)
  353.                         {
  354.                     day_unitstore=9;
  355.                     --day_decastore;
  356.                         }
  357.                     }
  358.             else if(day_numj==31)
  359.                     {
  360.                 day_numj=1;
  361.                 day_unitstore=1;
  362.                 day_decastore=3;
  363.                     }
  364.             }
  365.         else if((month_unitstore|0xfe)!=0xff)      //是偶数月,日为30天
  366.             {
  367.                    
  368.                 if(
  369.                    
  370.             month_unitstore==2)                    //是二月
  371.                 {       
  372.                         if(day_numo!=day_numoo)
  373.                                         {       
  374.                                     ++day_numo;
  375.                             if((--day_unitstore)==255)
  376.                                                 {
  377.                                 day_unitstore=9;
  378.                                 --day_decastore;
  379.                                                 }
  380.                                         }
  381.                            
  382.                         else if(day_numo==day_numoo)
  383.                                         {
  384.                             if(day_numoo==28)
  385.                                             {       
  386.                                             day_numo=1;
  387.                                         day_unitstore=8;
  388.                                         day_decastore=2;
  389.                                                 }
  390.                             else if(day_numoo==29)
  391.                                                 {
  392.                                            day_numo=1;
  393.                                         day_unitstore=9;
  394.                                         day_decastore=2;
  395.                                                 }
  396.                            
  397.                                         }
  398.                     }
  399.             else if(month_unitstore!=2)                     //不是二月
  400.                 {       
  401.                 if(day_numooo!=30)
  402.                         {
  403.                     ++day_numooo;
  404.                     day_numo=day_numooo;
  405.                     if((--day_unitstore)==255)
  406.                                 {
  407.                         day_unitstore=9;
  408.                         --day_decastore;
  409.                         day_numo=day_numooo;
  410.                                 }
  411.                         }
  412.                 else if(day_numooo==30)
  413.                         {
  414.                         
  415.                             day_numooo=1;
  416.                         day_unitstore=0;
  417.                         day_decastore=3;
  418.                         day_numo=day_numooo;
  419.                            
  420.                         }
  421.                     }
  422.             }
  423.     }
  424.     else if(sixth_sure)                         //第六次按下确认键,倒计时位减
  425.     {
  426.          if((--retime_ustore)==255)
  427.              {
  428.                retime_ustore=9;
  429.                if((--retime_dstore)==255)
  430.                    {
  431.                      retime_dstore=9;
  432.                      if((--retime_hstore)==255)
  433.                                  {
  434.                                 retime_hstore=9;
  435.                             if((--retime_tstore)==255)retime_tstore=9;
  436.                                  }
  437.                    }
  438.              }
  439.     }
  440. }
  441. /*******************************

  442. 年位闪烁子程序

  443. *******************************/
  444. void year_flash(void)
  445. {
  446.     unsigned char i;
  447.     if(third_sure)
  448.     {
  449.          year_thoustore=year_thousand;
  450.          year_hundstore=year_hundred;
  451.          year_decastore=year_decade;
  452.          year_unitstore=year_unit;
  453.          while(third_sure)
  454.              {
  455.             for(i=0;i<18;i++)       //年位不显示,其它位都显示
  456.                     {
  457.                 year_thousand=10;
  458.                 year_hundred=10;
  459.                 year_decade=10;
  460.                 year_unit=10;
  461.                 fen_ge=fenzhong_ge;
  462.                 fen_shi=fenzhong_shi;
  463.                 display();
  464.                 kbscan();
  465.                 if(!third_sure)i=51;   //如果不满足立即跳出
  466.                     }
  467.             if(third_sure)
  468.                     {
  469.                 for(i=0;i<18;i++)      //年位和其它位都显示
  470.                         {
  471.                      year_thousand=year_thoustore;
  472.                      year_hundred=year_hundstore;
  473.                      year_decade=year_decastore;
  474.                      year_unit=year_unitstore;
  475.                      fen_ge=fenzhong_ge;
  476.                      fen_shi=fenzhong_shi;
  477.                          display();
  478.                          kbscan();
  479.                      if(!third_sure)i=51;   //如果不满足立即跳出
  480.                         }
  481.                     }
  482.              }
  483.     }
  484. }
  485. /*******************************
  486. 月位闪烁子程序
  487. *******************************/
  488. void month_flash(void)
  489. {
  490.     unsigned char i;
  491.     if(TR0==0)                                  //为日位润平年二月天数做准备
  492.     {
  493.             day_numo=judgement_leap();
  494.             day_numoo=day_numo;
  495.     }
  496.     if(fourth_sure)
  497.     {
  498.         month_unitstore=month_unit;
  499.         month_decastore=month_decade;
  500.         while(fourth_sure)
  501.             {
  502.             for(i=0;i<18;i++)
  503.                     {
  504.                  month_unit=10;
  505.                  month_decade=10;
  506.                  year_thousand=year_thoustore;    //送原始数据避免取到不显示数据
  507.                  year_hundred=year_hundstore;
  508.                  year_decade=year_decastore;
  509.                  year_unit=year_unitstore;
  510.                  display();
  511.                  kbscan();
  512.                  if(!fourth_sure)i=51;
  513.                     }
  514.             if(fourth_sure)
  515.                     {
  516.                  for(i=0;i<18;i++)
  517.                          {       
  518.                     month_unit=month_unitstore;
  519.                     month_decade=month_decastore;//送原始数据避免取到不显示数据
  520.                     year_thousand=year_thoustore;
  521.                     year_hundred=year_hundstore;
  522.                     year_decade=year_decastore;
  523.                     year_unit=year_unitstore;
  524.                         display();
  525.                         kbscan();
  526.                     if(!fourth_sure)i=51;
  527.                         }
  528.                     }
  529.             }

  530.     }
  531. }
  532. /*******************************
  533. 日位闪烁子程序
  534. ******************************/
  535. void day_flash(void)
  536. {
  537.     unsigned char i;
  538.     if(fifth_sure)
  539.     {
  540.         day_unitstore=day_unit;
  541.         day_decastore=day_decade;
  542.         while(fifth_sure)
  543.             {
  544.             for(i=0;i<18;i++)
  545.                     {
  546.                 day_unit=10;
  547.                 day_decade=10;
  548.                 month_unit=month_unitstore;       //送原始数据避免取到不显示数据
  549.                 month_decade=month_decastore;
  550.                 year_thousand=year_thoustore;
  551.                 year_hundred=year_hundstore;
  552.                 year_decade=year_decastore;
  553.                 year_unit=year_unitstore;
  554.                 display();
  555.                 kbscan();
  556.                 if(!fifth_sure)i=51;
  557.                     }
  558.             if(fifth_sure)
  559.                     {
  560.                 for(i=0;i<18;i++)
  561.                         {
  562.                      day_unit=day_unitstore;
  563.                      day_decade=day_decastore;
  564.                      month_unit=month_unitstore;     //送原始数据避免取到不显示数据
  565.                      month_decade=month_decastore;
  566.                      year_thousand=year_thoustore;
  567.                      year_hundred=year_hundstore;
  568.                      year_decade=year_decastore;
  569.                      year_unit=year_unitstore;
  570.                          display();
  571.                          kbscan();
  572.                      if(!fifth_sure)i=51;
  573.                         }
  574.                     }
  575.             }
  576.     }
  577. }
  578. /*******************************
  579. 倒计时位闪烁子程序
  580. *******************************/
  581. void retime_flash(void)
  582. {
  583.     unsigned char i;
  584.     if(sixth_sure)
  585.     {
  586.         retime_ustore=retime_unit;
  587.         retime_dstore=retime_decade;
  588.         retime_hstore=retime_hundred;
  589.         retime_tstore=retime_thousand;
  590.         while(sixth_sure)
  591.             {
  592.              for(i=0;i<18;i++)
  593.                  {
  594.                 retime_unit=10;
  595.                 retime_decade=10;
  596.                 retime_hundred=10;
  597.                 retime_thousand=10;
  598.                 day_unit=day_unitstore;
  599.                 day_decade=day_decastore;
  600.                 display();
  601.                 kbscan();
  602.                 if(!sixth_sure)i=51;
  603.                  }
  604.              if(sixth_sure)
  605.                  {
  606.                 for(i=0;i<18;i++)
  607.                         {
  608.                    retime_unit=retime_ustore;
  609.                    retime_decade=retime_dstore;
  610.                    retime_hundred=retime_hstore;
  611.                    retime_thousand=retime_tstore;
  612.                    day_unit=day_unitstore;
  613.                    day_decade=day_decastore;
  614.                    display();
  615.                    kbscan();
  616.                    if(!sixth_sure)i=51;
  617.                         }
  618.                  }
  619.             }
  620.         if(seventh_sure)                 //第八次确认键按下,启动定时器,将各位的数据全部弹出,时钟正常显示
  621.             {
  622.             seventh_sure=0;
  623.             fen_ge=fenzhong_ge;                                       
  624.             fen_shi=fenzhong_shi;
  625.             shi_ge=xiaoshi_ge;  
  626.             shi_shi=xiaoshi_shi;
  627.             year_unit=year_unitstore;
  628.             year_decade=year_decastore;
  629.             year_hundred=year_hundstore;
  630.             year_thousand=year_thoustore;
  631.             month_unit=month_unitstore;
  632.             month_decade=month_decastore;
  633.             day_unit=day_unitstore;
  634.             day_decade=day_decastore;
  635.             retime_unit=retime_ustore;
  636.             retime_decade=retime_dstore;
  637.             retime_hundred=retime_hstore;
  638.             retime_thousand=retime_tstore;
  639.             TR0=1;                                       
  640.             }
  641.     }
  642. }
  643. /*******************************
  644. 小时位闪烁子程序
  645. *******************************/
  646. void hour_flash(void)
  647. {   
  648.     unsigned char i;
  649.     if(first_sure)
  650.     {       
  651.         TR0=0;                //关定时器,进入闪烁
  652.         xiaoshi_ge=shi_ge;    //保存时个位显示的数据
  653.         xiaoshi_shi=shi_shi;  //保存时十位显示的数据
  654.         while(first_sure)     //第一次确认键按下,在小时位闪烁
  655.             {       
  656.             for(i=0;i<18;i++) //小时位不显示,其它位显示
  657.                 {       
  658.                 shi_ge=10;
  659.                 shi_shi=10;
  660.                 display();
  661.                 kbscan();
  662.                 if(!first_sure)i=51;
  663.                     }
  664.             if(first_sure)
  665.                     {
  666.                 for(i=0;i<18;i++)//小时位和其它位都显示
  667.                         {       
  668.                     shi_ge=xiaoshi_ge;
  669.                     shi_shi=xiaoshi_shi;
  670.                         display();
  671.                         kbscan();
  672.                     if(!first_sure)i=51;
  673.                         }
  674.                 }  
  675.             }
  676.     }
  677. }
  678. /******************************
  679. 分钟位闪烁子程序
  680. *******************************/
  681. void min_flash(void)   
  682. {   
  683.     unsigned char i;
  684.     if(second_sure)
  685.     {       
  686.             fenzhong_ge=fen_ge;     //保存分个位显示的数据
  687.             fenzhong_shi=fen_shi;   //保存分十位显示的数据
  688.             while(second_sure)      //第二次确认键按下,在分钟位闪烁
  689.                     {
  690.                 for(i=0;i<18;i++)//分钟位不显示,其它位都显示
  691.                         {
  692.                         fen_ge=10;
  693.                         fen_shi=10;
  694.                     shi_ge=xiaoshi_ge;  //送小时个位的原始数据,避免调到小时个位不显示时的数据
  695.                     shi_shi=xiaoshi_shi;//送小时十位的原始数据,避免调到小时十位不显示时的数据
  696.                         display();
  697.                         kbscan();
  698.                     if(!second_sure)i=51;
  699.                         }
  700.                 if(second_sure)
  701.                         {
  702.                     for(i=0;i<18;i++)      //分钟位和其它位都显示
  703.                                 {
  704.                         fen_ge=fenzhong_ge;
  705.                         fen_shi=fenzhong_shi;
  706.                         shi_ge=xiaoshi_ge;  //送小时个位的原始数据,避免调到小时个位不显示时的数据
  707.                         shi_shi=xiaoshi_shi;//送小时十位的原始数据,避免调到小时十位不显示时的数据
  708.                                 display();
  709.                                 kbscan();
  710.                         if(!second_sure)i=51;
  711.                                 }
  712.                         }       
  713.                     }
  714.     }
  715. }
  716. /******************************
  717. 年位组合子程序
  718. ********************************/
  719. void year_joint(void)
  720. {   
  721.     year_unitstore2=year_unitstore;       //保存年各位数据
  722.     year_decastore2=year_decastore;
  723.     year_hundstore2=year_hundstore;
  724.     year_thoustore2=year_thoustore;
  725.     year_jointed=year_unitstore;
  726.     year_decastore=year_decastore<<4;
  727.     year_decastore=year_decastore&0xf0;
  728.     year_jointed=year_jointed+year_decastore;       //得到年的抵8位
  729.     year_jointed=year_jointed<<8;               //将年的低8和高8互换
  730.     year_jointed=year_jointed+year_hundstore;
  731.     year_thoustore=year_thoustore<<4;
  732.     year_thoustore=year_thoustore&0xf0;
  733.     year_jointed=year_jointed+year_thoustore;   //得到年,需将其进行高8与低8互换
  734.     year_help1=year_jointed&0xff00;
  735.     year_help1=year_help1>>8;                       //得到年低8位
  736.     year_help2=year_jointed&0x00ff;
  737.     year_help2=year_help2<<8;                       //得到年高8位
  738.     year_jointed=year_help1+year_help2;         // 得到年位
  739.     year_unitstore=year_unitstore2;
  740.     year_decastore=year_decastore2;
  741.     year_hundstore=year_hundstore2;
  742.     year_thoustore=year_thoustore2;             //弹出年各位数据
  743. }

  744. /*******************************
  745. 定时器0中断子程序
  746. ********************************/
  747. void timer0(void) interrupt 1 using 1
  748. {
  749.     TH0=0x3c;
  750.     TL0=0xb0;
  751.     if((++time_num)==20)
  752.             {
  753.             time_num=0;
  754.             ++miao_ge;   //定时一秒到,秒个位加一
  755.             }
  756. }                  
  757. /******************************
  758. 当秒个位加到9时进一,
  759. ……
  760. *******************************/   
  761. void dis_dingshi(void)  
  762. {   
  763.     if(miao_ge==10)                           
  764.     {
  765.         miao_ge=0;
  766.         if((++miao_shi)==6)               
  767.             {       
  768.             miao_shi=0;
  769.             if((++fen_ge)==10)               
  770.                     {
  771.                 fen_ge=0;
  772.                 if((++fen_shi)==6)
  773.                         {
  774.                         fen_shi=0;
  775.                     if((--shi_num)!=0)
  776.                                 {
  777.                         if((++shi_ge)==10)
  778.                                         {
  779.                                         shi_ge=0;
  780.                                     ++shi_shi;
  781.                                         }
  782.                                 }
  783.                     else if(shi_num==0)
  784.                                 {
  785.                             shi_num=24;
  786.                                 shi_ge=0;
  787.                                 shi_shi=0;
  788.                             if(retime_unit==0&retime_decade==0&retime_hundred==0&retime_thousand==0)//倒计时减一
  789.                                                 {
  790.                                                     ;
  791.                                                 }
  792.                                             else
  793.                                                 {
  794.                                  if((--retime_unit)==10)
  795.                                                      {
  796.                                               retime_unit=0;
  797.                                     if((--retime_decade)==10)
  798.                                                             {
  799.                                                      retime_decade=0;
  800.                                             if((--retime_hundred)==10)
  801.                                                                     {
  802.                                                          retime_hundred=0;
  803.                                                 if((--retime_thousand)==10)
  804.                                                                             {
  805.                                                                  retime_thousand=0;
  806.                                                                             }
  807.                                                                     }
  808.                                                             }
  809.                                                      }
  810.                                                 }

  811.                         if((month_unit|0xfe)==0xff)     //是奇数月,日为31天
  812.                                         {       
  813.                                     if((--day_numj)!=0)                        //31天没到
  814.                                                     {       
  815.                                                 if((++day_unit)==10)
  816.                                                                     {
  817.                                                                  day_unit=0;
  818.                                                                 ++day_decade;
  819.                                                                     }
  820.                                                             }
  821.                                     else if(day_numj==0)                        //31天到了
  822.                                                             {
  823.                                                        day_numj=31;
  824.                                                            day_unit=1;
  825.                                                        day_decade=0;
  826.                                                                    
  827.                                         if((--month_num)!=0)                 //12个月没到
  828.                                                                    {       
  829.                                                             if((++month_unit)==10)
  830.                                                                                    {
  831.                                                                             month_unit=0;
  832.                                                                             ++month_decade;
  833.                                                                                    }
  834.                                                                     }
  835.                                         else if(month_num==0)         //12个月到了
  836.                                                                     {
  837.                                                                 month_num=12;
  838.                                                                 month_unit=1;
  839.                                                             month_decade=0;
  840.                                             if((++year_unit)==10)        //年个位是否到9
  841.                                                                             {
  842.                                                                       year_unit=0;
  843.                                                              if((++year_decade)==10)
  844.                                                                                  {
  845.                                                                              year_decade=0;
  846.                                                                 if((++year_hundred)==10)
  847.                                                                                         {
  848.                                                                                  year_hundred=0;
  849.                                                         if((++year_thousand)==10)year_thousand=0;
  850. ……………………

  851. …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码

所有资料51hei提供下载:
单片机设计2008奥运会.rar (178.65 KB, 下载次数: 18)

评分

参与人数 1黑币 +50 收起 理由
admin + 50 共享资料的黑币奖励!

查看全部评分

回复

使用道具 举报

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

本版积分规则

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

Powered by 单片机教程网

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