STM32用定时器做一个秒表,无法实现暂停功能,每次暂停后都会从零开始计数。

void TIM3_IRQHandler(void)
{
if(TIM_GetITStatus(TIM3,TIM_IT_Update)==SET)
{

    key=KEY_Scan(0);
    if(key==1)
    {   
        if(counter==0)
        {
            LCD_ShowString(60,160,210,16,24,"FIRST");
            LCD_ShowxNum(175,160,count,2,24,0); 
            LCD_ShowxNum(135,160,second,2,24,0); 
            LCD_ShowString(160,160,210,16,24,":");
        }
        else
        {
            LCD_ShowString(60,190,210,16,24,"SECOND");
            LCD_ShowxNum(175,190,count,2,24,0); 
            LCD_ShowxNum(135,190,second,2,24,0); 
            LCD_ShowString(160,190,210,16,24,":");
        }
        counter++;
        if(counter>=2)
        {
            counter=0;
        }
        while(1)
        {
            key=KEY_Scan(0);
            if(key==1)
                break;  

            {
                GPIO_ResetBits(GPIOA,GPIO_Pin_7);
                delay_ms(50);
                GPIO_SetBits(GPIOA,GPIO_Pin_7);
                delay_ms(50);
            }                   
        }
    }
    else
        count++;

    if(count>=100)
    {
        count= 0;
        second++;

    }
    if(second>=60)
        second=0;
        }

声明个static变量计数。