main.c
资源名称:a.rar [点击查看]
上传用户:lhdljz
上传日期:2021-11-17
资源大小:4k
文件大小:28k
源码类别:

多媒体

开发平台:

Visual C++

  1. /**************************************************
  2. ** 版权:     杭州利尔达科技有限公司
  3. ** 文件名:   DD
  4. ** 工作环境: IAR 3.42A 
  5. ** 作者:     谷丰
  6. ** 生成日期: 2008.08.25
  7. ** 功能: 实现软件万年历功能,并自动识别闰年
  8.          A屏每显示5秒种就自动切换到B屏,
  9.         B屏再显示5秒种就自动切换到C屏,
  10.         C屏再显示5秒种就自动切换到A屏
  11.         通过按键在A屏、B屏和C屏之间切换
  12.         可通过按键手动设定和调整时间,当调整时对应调整位要有闪烁功能
  13.         有闹钟功能,可设置几点几分闹钟,当前时间等于闹钟时间时,
  14.         用点亮LED指示,直到某个键(自定义)被按下时,熄灭LED灯
  15. ** 相关文件:
  16. ** 修改日志:
  17. ***************************************************/
  18. /**************************************************
  19. 包含头文件
  20. ***************************************************/
  21. #include  <msp430x44x.h>
  22. /**************************************************
  23. 定义全局变量
  24. ***************************************************/
  25. unsigned char cnt;                                                  // 计数器
  26. unsigned char tian;                                                 // 天寄存器
  27. unsigned char key_code;                                             // 按键值
  28. unsigned char flag;                                                 // 换屏标志位
  29. unsigned char twinkle_num;                                          // 闪烁标志位 
  30. unsigned char function_flag;                                        // 加减功能标志位
  31. unsigned char function_ping1,function_ping2,function_ping3;         // 每屏闪烁位
  32. unsigned char change_num;                                           // 闪屏时间定时
  33. unsigned char change_ping;                                          // 三屏计数位
  34. unsigned char clock_flag;                                           // 闹钟标志位
  35. unsigned char ping_flag;                                            // 按键跟踪闪屏标志位
  36. unsigned char num_flag;                                             // 按键计数闪屏标志位
  37. unsigned char tian_flag;                                            // 天判断标志位
  38. unsigned char run_flag;                                             // 闰年判断标志位
  39. unsigned int key_num = 150;                                         // 按键消逗延时时间
  40. unsigned int year = 2008;                                           // 年
  41. unsigned char month = 2;                                            // 月
  42. unsigned char day = 28;                                             // 日
  43. unsigned char hour = 23;                                            // 小时
  44. unsigned char min = 59;                                             // 分
  45. unsigned char sec = 57;                                             // 秒
  46. unsigned char nao_hour = 0;                                         // 闹钟时
  47. unsigned char nao_min = 0;                                          // 闹钟分
  48. unsigned char nao_sec = 0;                                          // 闹钟秒
  49. const unsigned char tianshu[13] =
  50. {0,31,28,31,30,31,30,31,31,30,31,30,31};                            // 每月天数表
  51. char digit[12] =                                                    // 液晶显示段码表  
  52. {
  53.   0x7b,
  54.   0x12,
  55.   0x4f,
  56.   0x1f,
  57.   0x36,
  58.   0x3d,
  59.   0x7d,
  60.   0x13,
  61.   0x7f,
  62.   0x3F,
  63.   0x00 
  64. };  
  65. /**************************************************
  66. 定义子函数
  67. ***************************************************/
  68. void init_clk(void);                                                // 初始化时钟
  69. void key_scan(void);                                                // 按键扫描
  70. void key_value(void);                                               // 按键值确定
  71. void rtc(void);                                                     // 时钟扫描函数
  72. void rtc_show(void);                                                // rtc扫描函数                                                  
  73. void leap_year(void);                                               // 闰年判定函数
  74. /**************************************************
  75. ** 函数名称:系统主函数
  76. ** 工作环境: IAR 3.42A 
  77. ** 作者:     谷丰
  78. ** 生成日期: 2008.08.25
  79. ** 相关文件:
  80. ** 修改日志:
  81. ***************************************************/
  82. void main(void)                                                    
  83. {
  84.   init_clk();                                                       // 时钟初始化
  85.   while(1)
  86.   {
  87.     key_scan();                                                     // 按键扫描
  88.     key_value();                                                    // 键值确定
  89.     rtc_show();                                                     // RTC显示
  90.     leap_year();                                                    // 闰年判定
  91.     if((sec == nao_sec) && (min == nao_min) && (hour == nao_hour))  // 闹钟判定
  92.     {
  93.       clock_flag = 1;                                               // 闹钟标志位置一
  94.     }
  95.   }
  96. }
  97. /**************************************************
  98. ** 函数名称:系统初始化函数
  99. ** 工作环境: IAR 3.42A 
  100. ** 作者:     谷丰
  101. ** 生成日期: 2008.08.20
  102. ** 功能:相关寄存器初始化
  103. ** 相关文件:
  104. ** 修改日志:
  105. ***************************************************/
  106. void init_clk(void)
  107. {
  108.   unsigned char i;
  109.   WDTCTL = WDTPW + WDTHOLD;                                         // 关闭看门狗        
  110.   FLL_CTL0 |= XCAP14PF;                                             // 选择14PF电容               
  111.   IE2 |= BTIE;                                                      // 开启基本定时器中断                               
  112.   BTCTL = BT_ADLY_250 + BTFRFQ1;                                    // 250ms  16分频
  113.   LCDCTL = LCDON + LCD4MUX + LCDP2;                                 // STK LCD 4Mux, S0-S14
  114.   P5SEL = 0xFC;                                                     // 选择P5口第二功能 
  115.   P1DIR |= 0x01;                                                    // P1.0选择输出   
  116.   _EINT();                                                          // 开总中断
  117.   for (i=0; i<19; i++)
  118.   {
  119.     LCDMEM[i] = 0;                                                  //清LCD缓冲区
  120.   } 
  121. }
  122. /**************************************************
  123. ** 函数名称:按键扫描函数
  124. ** 工作环境: IAR 3.42A 
  125. ** 作者:     谷丰
  126. ** 生成日期: 2008.08.20
  127. ** 功能:按键扫描,键值确定
  128. ** 相关文件:
  129. ** 修改日志:
  130. ***************************************************/
  131. void key_scan(void)
  132.   static unsigned int num;                                          // 按键消抖计数器 
  133.   if((P1IN&0x0e) != 0x0e)                                           // 如果不等于表示有键按下 
  134.   {
  135.     num++;                                                          // 消逗计数器加
  136.     key_code = 0;                                                   // 键值清零
  137.   }       
  138.   else
  139.   {
  140.     num = 0;                                                        // 按键抖动,键值清零
  141.     key_code = 0;                                                   // 键值清零
  142.   }
  143.   if(num == key_num )                                               // 键值确定
  144.   {      
  145.     num = 0;                                                        // 消逗寄存器清零
  146.     twinkle_num = 0;                                                // 闪烁清零
  147.     key_code = ((P1IN&0x0e)>>1)^0x07;                               // 键值转换   
  148.   }
  149. }
  150. /**************************************************
  151. ** 函数名称:键值功能函数
  152. ** 工作环境: IAR 3.42A 
  153. ** 作者:     谷丰
  154. ** 生成日期: 2008.08.20
  155. ** 功能:按键功能确定
  156.          P1.1 闪烁、清除闹钟
  157.          P1.2 + P1.1 加、清除闹钟
  158.          P1.3 + P1.1 减、清除闹钟
  159.          P1.2 闪屏、清除闹钟
  160.          P1.3 清除闹钟
  161. ** 相关文件:
  162. ** 修改日志:
  163. ***************************************************/
  164. void key_value(void)
  165. {
  166.   if(key_code == 0x01)                                              // 第一个键被按下
  167.   {
  168.     function_flag = 1;                                              // 功能键标志位置一
  169.     clock_flag = 2;                                                 // 关闭闹钟
  170.     if(change_ping == 0)                                            // 第一屏
  171.     {
  172.       function_ping1 ++;                                            // 数值闪烁加
  173.       if(function_ping1 == 4)                                       // 闪烁到第三位         
  174.       { 
  175.         if(tian_flag == 1)
  176.         {
  177.           function_ping1 = 1;                                       // 
  178.         }
  179.         else
  180.         {
  181.           function_ping1 = 0;                                       // 清零
  182.           function_flag = 0;                                        // 功能键清零
  183.         }
  184.       }
  185.       change_num = 0;                                               // 换屏计数器
  186.     }
  187.     if(change_ping == 1)                                            // 第二屏
  188.     {
  189.       function_ping2++;                                             // 数值闪烁加
  190.       if(function_ping2 == 4)
  191.       {
  192.         function_ping2 = 0;
  193.         function_flag = 0;                                          // 清零                                                                   // 功能标志位清零
  194.       }
  195.       change_num = 20;                                              // 换屏时间计数器
  196.     }
  197.     if(change_ping == 2)                                            // 第三屏
  198.     {
  199.       function_ping3++;                                             // 数值闪烁加
  200.       if(function_ping3 == 4)
  201.       {
  202.         function_ping3 = 0;                                         // 清零
  203.         function_flag = 0;                                          // 功能标志位清零
  204.       }
  205.       change_num = 40;                                              // 换屏计数器
  206.     }
  207.   }
  208.   if((key_code == 0x02) && (function_flag == 1))                    // 加法
  209.   { 
  210.     clock_flag = 2;                                                 // 关闭闹钟   
  211.     if(function_ping2 == 1)                                         // 秒闪烁
  212.     {
  213.       sec++;                                                        // 秒加
  214.       if(sec == 60)                                                 // 秒是否等于60
  215.         sec = 0;                                                    // 秒数清零
  216.     }
  217.     if(function_ping2 == 2)                                         // 分闪烁
  218.     {
  219.       min++;                                                        // 分加
  220.       if(min == 60)                                                 // 分是否等于60
  221.         min = 0;                                                    // 分清零 
  222.     }
  223.     if(function_ping2 == 3)                                         // 小时闪烁
  224.     {
  225.       hour++;                                                       // 小时加
  226.       if(hour == 24)                                                // 小时是否等于24
  227.         hour = 0;                                                   // 小时清零
  228.     }
  229.     if(function_ping1 == 1)                                         // 日闪烁
  230.     {
  231.       day++;                                                        // 日加加
  232.       if(day > tian)                                                // 日是否大于天
  233.         day = 1;                                                    // 日等于1
  234.     }
  235.     if(function_ping1 == 2)                                         // 月闪烁
  236.     {
  237.       month++;                                                      // 月加加 
  238.       tian = tianshu[month]; 
  239.       if(day > tian)
  240.       {
  241.         tian_flag = 1;
  242.       }
  243.       else
  244.         tian_flag = 0;
  245.       if(month == 13)                                               // 月是否等于13
  246.         month = 1;                                                  // 月等于1
  247.     }
  248.     if(function_ping1 == 3)                                         // 年闪烁
  249.     {      
  250.       year++;                                                       // 年加加
  251.       if((year%4 != 0)||(year%100 != 0) || (year%400 == 0))
  252.       {
  253.        tian = tianshu[month]; 
  254.        if(day > tian)
  255.        {
  256.         tian_flag = 1;
  257.        }   
  258.       else 
  259.         tian_flag = 0;
  260.       }
  261.       if(year == 2100)                                              // 年是否等于2100
  262.         year = 2000;                                                // 年到2000
  263.     } 
  264.     if(function_ping3 == 1)                                         // 闹钟秒闪烁
  265.     {
  266.       nao_sec++;                                                    // 闹钟秒加加
  267.       if(nao_sec == 60)                                             // 闹钟秒是否等于60
  268.         nao_sec = 0;                                                // 闹钟秒清零
  269.     }
  270.     if(function_ping3 == 2)                                         // 闹钟分闪烁
  271.     {
  272.       nao_min++;                                                    // 闹钟分加加
  273.       if(nao_min == 60)                                             // 闹钟分是否等于60
  274.         nao_min = 0;                                                // 闹钟分清零
  275.     }
  276.     if(function_ping3 == 3)                                         // 闹钟小时闪烁
  277.     {
  278.       nao_hour++;                                                   // 闹钟小时加加
  279.       if(nao_hour == 24)                                            // 闹钟小时是否等于24
  280.         nao_hour = 0;                                               // 闹钟小时清零
  281.     }  
  282.   }
  283.   if((key_code == 0x04) && (function_flag == 1))                    // 减法
  284.   {
  285.     clock_flag = 2;                                                 // 清除闹钟标志位
  286.     if(function_ping2 == 1)                                         
  287.     { 
  288.       sec--;                                                        // 秒减减
  289.       if(sec == 0xff)                                               // 秒是否等于0 
  290.         sec = 59;                                                   // 秒等于60                                                               
  291.     }
  292.     if(function_ping2 == 2)                                         
  293.     {
  294.       min--;                                                        // 分减减
  295.       if(min == 0xff)                                                  // 分是否等于0
  296.         min = 59;                                                   // 分等于60                                                           
  297.     }
  298.     if(function_ping2 == 3)                                         
  299.     {
  300.       hour--;                                                       // 小时减减
  301.       if(hour == 0xff)                                                 // 小时是否等于0
  302.         hour = 23;                                                  // 小时等于24                                                            
  303.     }
  304.     if(function_ping1 == 1)
  305.     {
  306.       day--;                                                        // 天减减
  307.       if(day == 0)                                                  // 天是否等于0 
  308.         day = tian;                                                 // 天等于30/31/28/29                                                             
  309.     }
  310.     if(function_ping1 == 2)                                         
  311.     {
  312.       month--;                                                      // 月减减
  313.       if(month == 0)                                                // 月是否等于0
  314.         month = 12;                                                 // 月等于13
  315.       tian = tianshu[month];  
  316.       if(day > tian)
  317.         tian_flag = 1;
  318.       else 
  319.         tian_flag = 0;
  320.     }
  321.     if(function_ping1 == 3) 
  322.     { 
  323.       year--;                                                       // 年减减
  324.       if(year ==1999)                                               // 年是否等于1999
  325.         year = 2100;                                                // 年等于2100 
  326.       if((year%4 != 0)||(year%100 != 0) || (year%400 == 0))
  327.       {
  328.        tian = tianshu[month]; 
  329.        if(day > tian)
  330.        {
  331.         tian_flag = 1;
  332.        }   
  333.       else 
  334.         tian_flag = 0;
  335.       }
  336.     }  
  337.     if(function_ping3 == 1)                                        
  338.     {  
  339.       nao_sec--;                                                    // 闹钟秒减减
  340.       if(nao_sec == 0xff)                                              // 闹钟秒是否等于0
  341.         nao_sec = 59;                                               // 闹钟秒等于60                                                           
  342.     }
  343.     if(function_ping3 == 2) 
  344.     {
  345.       nao_min--;                                                    // 闹钟分减减
  346.       if(nao_min == 0xff)                                              // 闹钟分是否等于0
  347.         nao_min = 59;                                               // 闹钟分等于60                                                          
  348.     }
  349.     if(function_ping3 == 3) 
  350.     {
  351.       nao_hour--;                                                   // 闹钟小时减减
  352.       if(nao_hour == 0xff)                                             // 闹钟小时是否等于0
  353.         nao_hour = 23;                                              // 闹钟小时等于24                                                         
  354.     }
  355.   }
  356.   if((key_code == 0x02) && (function_flag == 0))                    // 没有功能键按下时
  357.   {
  358.     clock_flag = 2;                                                 // 清除闹钟标志位
  359.     flag = 1;                                                       // 换屏标志位被按下
  360.     if(num_flag == 1)                                               // 换屏位1
  361.      ping_flag = 1;
  362.     if(num_flag == 2)                                               // 换屏位2
  363.      ping_flag = 2;
  364.     if(num_flag == 3)                                               // 换屏位3
  365.      ping_flag = 3;
  366.   }
  367.   if((key_code == 0x04) && (function_flag == 0))                    
  368.   {
  369.     clock_flag = 2;                                                 // 清除闹钟标志位
  370.   }
  371.   key_code = 0;                                                     // 键值清零
  372. }
  373. /**************************************************
  374. ** 函数名称:闰年判断函数
  375. ** 工作环境: IAR 3.42A 
  376. ** 作者:     谷丰
  377. ** 生成日期: 2008.08.20
  378. ** 功能:判断年是否是闰年
  379. ** 相关文件:
  380. ** 修改日志:
  381. ***************************************************/
  382. void leap_year(void)
  383. {
  384.     tian = tianshu[month];                                          // 读出每月天数表
  385.     if(day < tian)
  386.       tian_flag = 0;
  387.     if(month == 2)
  388.     {
  389.       if((year%4 == 0)&&(year%100 != 0) || (year%400 == 0))         // 判断是否是闰年
  390.        {
  391.          tian = 29;                                                // 闰年2月天数修正
  392.        }
  393.        else
  394.        {
  395.          tian = 28;                                                // 闰年2月天数修正
  396.        }
  397.     }
  398. }
  399. /**************************************************
  400. ** 函数名称:时分秒加函数
  401. ** 工作环境: IAR 3.42A 
  402. ** 作者:     谷丰
  403. ** 生成日期: 2008.08.20
  404. ** 功能:时分秒、年月日加
  405. ** 相关文件:
  406. ** 修改日志:
  407. ***************************************************/
  408. void rtc()
  409.   if(++sec < 60)                                                    // 秒加一
  410.     return;
  411.   sec = 0;
  412.   if(++min < 60)                                                    // 分加一
  413.     return;
  414.   min = 0;
  415.   if(++hour < 24)                                                   // 小时加一
  416.     return;
  417.   hour = 0;
  418.   if(++day <= tian)                                                 // 天数加一
  419.     return;
  420.   day = 1;                                                          // 月加一      
  421.   if(++month <= 12)
  422.     return;
  423.    month = 1;
  424.   if(++year < 2100)                                                 // 年加一
  425.     return;
  426.   year = 2000;   
  427. }
  428. /**************************************************
  429. ** 函数名称:LCD显示函数
  430. ** 工作环境: IAR 3.42A 
  431. ** 作者:     谷丰
  432. ** 生成日期: 2008.08.20
  433. ** 功能:LCD显示、闪烁、换屏
  434. ** 相关文件:
  435. ** 修改日志:
  436. ***************************************************/
  437. void rtc_show(void)
  438. {
  439.   if((function_ping1 != 0) && (function_ping2 == 0) && (function_ping3 == 0))
  440.   {
  441.     change_ping = 0;                                                // 第一屏
  442.   }
  443.   else if((function_ping1 == 0) && (function_ping2 != 0) && (function_ping3 == 0))
  444.   {
  445.     change_ping = 1;                                                // 第二屏
  446.   }
  447.   else if((function_ping1 == 0) && (function_ping2 == 0) && (function_ping3 != 0))
  448.   {
  449.     change_ping = 2;                                                // 第三屏 
  450.   }
  451.   if(change_ping == 1)
  452.   {
  453.     if(function_ping2 == 0)                                         // 正常显示
  454.     {
  455.       LCDMEM[0] = digit[sec%10]; 
  456.       LCDMEM[1] = digit[sec/10]; 
  457.       LCDMEM[2] = digit[min%10];
  458.       LCDMEM[3] = digit[min/10];     
  459.       LCDMEM[4] = digit[hour%10];
  460.       LCDMEM[5] = digit[hour/10];
  461.     }
  462.     if(function_ping2 == 1)                                         // 秒闪烁
  463.     {
  464.       if(twinkle_num == 0)                                          // 闪烁标志位
  465.       {
  466.         LCDMEM[0] = digit[sec%10];
  467.         LCDMEM[1] = digit[sec/10]; 
  468.       }
  469.       else
  470.       {
  471.         LCDMEM[0] = 0;
  472.         LCDMEM[1] = 0;
  473.       }
  474.       LCDMEM[2] = digit[min%10];
  475.       LCDMEM[3] = digit[min/10];
  476.       LCDMEM[4] = digit[hour%10];
  477.       LCDMEM[5] = digit[hour/10];   
  478.     }
  479.     if(function_ping2 == 2)                                         // 分闪烁
  480.     {
  481.       if(twinkle_num == 0)
  482.       {
  483.         LCDMEM[2] = digit[min%10];
  484.         LCDMEM[3] = digit[min/10];
  485.       }
  486.       else
  487.       {
  488.         LCDMEM[2] = 0;
  489.         LCDMEM[3] = 0;
  490.       }
  491.       LCDMEM[0] = digit[sec%10];
  492.       LCDMEM[1] = digit[sec/10];
  493.       LCDMEM[4] = digit[hour%10];
  494.       LCDMEM[5] = digit[hour/10];
  495.     }
  496.     if(function_ping2 == 3)                                         // 小时闪烁
  497.     {
  498.       if(twinkle_num == 0)                                                
  499.       {
  500.         LCDMEM[4] = digit[hour%10];
  501.         LCDMEM[5] = digit[hour/10]; 
  502.       }
  503.       else                                                          
  504.       {
  505.         LCDMEM[4] = 0;
  506.         LCDMEM[5] = 0;
  507.       }
  508.       LCDMEM[0] = digit[sec%10];
  509.       LCDMEM[1] = digit[sec/10];
  510.       LCDMEM[2] = digit[min%10];
  511.       LCDMEM[3] = digit[min/10];
  512.     }
  513.   }
  514.   if(change_ping == 0)
  515.   {
  516.     if(function_ping1 == 0)                                         // 正常显示
  517.     {
  518.       LCDMEM[0] = digit[(day)%10];
  519.       LCDMEM[1] = digit[(day)/10];     
  520.       LCDMEM[2] = digit[(month)%10];
  521.       LCDMEM[3] = digit[(month)/10];   
  522.       LCDMEM[4] = digit[year%10];                    
  523.       LCDMEM[5] = digit[(year/10)%10]; 
  524.     }
  525.     if(function_ping1 == 1)                                          // 天闪烁
  526.     {
  527.       if(twinkle_num == 0)
  528.       {
  529.         LCDMEM[0] = digit[day%10];
  530.         LCDMEM[1] = digit[day/10]; 
  531.       }
  532.       else
  533.       {
  534.         LCDMEM[0] = 0;
  535.         LCDMEM[1] = 0;
  536.       }
  537.       LCDMEM[2] = digit[(month)%10];
  538.       LCDMEM[3] = digit[(month)/10];   
  539.       LCDMEM[4] = digit[year%10];                    
  540.       LCDMEM[5] = digit[(year/10)%10]; 
  541.     }
  542.     if(function_ping1 == 2)                                          // 月闪烁
  543.     {
  544.       if(twinkle_num == 0)
  545.       {
  546.         LCDMEM[2] = digit[(month)%10];
  547.         LCDMEM[3] = digit[(month)/10]; 
  548.       }
  549.       else
  550.       {
  551.         LCDMEM[2] = 0;
  552.         LCDMEM[3] = 0;
  553.       }
  554.       LCDMEM[0] = digit[day%10];
  555.       LCDMEM[1] = digit[day/10];
  556.       LCDMEM[4] = digit[year%10];                    
  557.       LCDMEM[5] = digit[(year/10)%10];
  558.     }
  559.     if(function_ping1 == 3)                                         // 年闪烁
  560.     {
  561.       if(twinkle_num == 0)
  562.       {
  563.         LCDMEM[4] = digit[year%10];                    
  564.         LCDMEM[5] = digit[(year/10)%10];
  565.       }
  566.       else
  567.       {
  568.         LCDMEM[4] = 0;                    
  569.         LCDMEM[5] = 0; 
  570.       }
  571.       LCDMEM[0] = digit[(day)%10];
  572.       LCDMEM[1] = digit[(day)/10];     
  573.       LCDMEM[2] = digit[(month)%10];
  574.       LCDMEM[3] = digit[(month)/10]; 
  575.     }
  576.   }
  577.   if(change_ping == 2)
  578.   {
  579.     if(function_ping3 == 0)                                         // 正常显示
  580.     {
  581.       LCDMEM[0] = digit[nao_sec%10];
  582.       LCDMEM[1] = digit[nao_sec/10];     
  583.       LCDMEM[2] = digit[nao_min%10];
  584.       LCDMEM[3] = digit[nao_min/10];   
  585.       LCDMEM[4] = digit[nao_hour%10];                    
  586.       LCDMEM[5] = digit[nao_hour/10]; 
  587.     }
  588.     if(function_ping3 == 1)                                        // 闹钟秒闪烁
  589.     {
  590.       if(twinkle_num == 0)
  591.       {
  592.         LCDMEM[0] = digit[nao_sec%10];
  593.         LCDMEM[1] = digit[nao_sec/10]; 
  594.       }
  595.       else
  596.       {
  597.         LCDMEM[0] = 0;
  598.         LCDMEM[1] = 0;
  599.       }
  600.       LCDMEM[2] = digit[nao_min%10];
  601.       LCDMEM[3] = digit[nao_min/10];   
  602.       LCDMEM[4] = digit[nao_hour%10];                    
  603.       LCDMEM[5] = digit[nao_hour/10]; 
  604.     }
  605.     if(function_ping3 == 2)                                        // 闹钟分闪烁
  606.     {
  607.       if(twinkle_num == 0)
  608.       {
  609.         LCDMEM[2] = digit[nao_min%10];
  610.         LCDMEM[3] = digit[nao_min/10]; 
  611.       }
  612.       else
  613.       {
  614.         LCDMEM[2] = 0;
  615.         LCDMEM[3] = 0;
  616.       }
  617.       LCDMEM[0] = digit[nao_sec%10];
  618.       LCDMEM[1] = digit[nao_sec/10];
  619.       LCDMEM[4] = digit[nao_hour%10];                    
  620.       LCDMEM[5] = digit[nao_hour/10];
  621.     }
  622.     if(function_ping3 == 3)                                       // 闹钟小时闪烁
  623.     {
  624.       if(twinkle_num == 0)
  625.       {
  626.         LCDMEM[4] = digit[nao_hour%10];                    
  627.         LCDMEM[5] = digit[nao_hour/10];
  628.       }
  629.       else
  630.       {
  631.         LCDMEM[4] = 0;                    
  632.         LCDMEM[5] = 0; 
  633.       }
  634.       LCDMEM[0] = digit[nao_sec%10];
  635.       LCDMEM[1] = digit[nao_sec/10];     
  636.       LCDMEM[2] = digit[nao_min%10];
  637.       LCDMEM[3] = digit[nao_min/10]; 
  638.     }
  639.   }
  640. }
  641. /**************************************************
  642. ** 函数名称:基本定时器中断函数
  643. ** 工作环境: IAR 3.42A 
  644. ** 作者:     谷丰
  645. ** 生成日期: 2008.08.20
  646. ** 功能:秒+,5s换屏,闹钟闪烁,修改闪烁
  647. ** 相关文件:
  648. ** 修改日志:
  649. ***************************************************/  
  650. #pragma vector=BASICTIMER_VECTOR
  651. __interrupt void basic_timer (void)
  652. {  
  653.   if(clock_flag == 1)                                              // 闹钟存在
  654.     P1OUT ^= BIT0;                                                 // LED闪烁
  655.   if(clock_flag == 2)                                              // 闹钟清除
  656.     P1OUT &= ~BIT0;                                                // 关闭LED 
  657.   cnt++;                                                           // 1s计数器加
  658.   if(cnt == 4)                                                     // 是否等于4
  659.   {
  660.     rtc();                                                         // 秒加一
  661.     cnt = 0;                                                       // 清零
  662.   } 
  663.   change_num++;                                                    // 换屏计数器
  664.   twinkle_num = ~twinkle_num;                                      // 闪烁标志位 
  665.   if(change_num == 60)                                             // 屏幕切换计数器到时复位
  666.   {
  667.     change_num = 0;                                                // 
  668.   }
  669.   if(((change_num > 0) && (change_num < 20) || (change_num == 0)) || ((ping_flag == 1) && (flag == 1)))
  670.   {
  671.     if((ping_flag == 1) && (flag == 1))                            // 按键时在第一屏
  672.     {
  673.       change_num = 20;                                             // 切换到第二屏
  674.       flag = 0;                                                    // 按键标志位清零
  675.     }
  676.     change_ping = 0;                                               // 第一屏
  677.     num_flag = 1;                                                  // 屏切换标志位1
  678.   }
  679.   if(((change_num > 20) && (change_num < 40) || (change_num == 20)) || ((ping_flag == 2) && (flag == 1)))
  680.   {
  681.     if((ping_flag == 2) && (flag == 1))                            // 按键时在第二屏
  682.     {
  683.       change_num = 40;                                             // 切换到第三屏
  684.       flag = 0;
  685.     }
  686.     change_ping = 1;                                               // 第二屏
  687.     num_flag = 2;                                                  // 屏切换标志位2
  688.   }
  689.   if(((change_num > 40) && (change_num < 60) || (change_num == 40)) || ((ping_flag == 3) && (flag == 1))) 
  690.   {
  691.     if((ping_flag == 3) && (flag == 1))                            // 按键时在第二屏
  692.     {
  693.       change_num = 0;                                              // 切换到第1屏
  694.       flag = 0;
  695.     }
  696.     change_ping = 2;                                               // 第三屏
  697.     num_flag = 3;                                                  // 屏切换标志位3
  698.   }  
  699. }