About CY8CKIT-042-BLE-A bluetooth low energy pioneer kit?--About Code ?-Thanks

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Robin_Peng
Level 5
Level 5
Distributor - Macnica(GC)
100 replies posted 50 replies posted 50 questions asked

Hi Sir.

I have some basic questions,The development kit I use is CY8CKIT-042-BLE-A. The chip I use is CY8C4247LQI-BL463.

1、I use the alarm function in RTC. When the alarm time is reached, it is interrupted and cleared after interruption, but why does the flag state of this interruption never change when I debug?alarmFLag is 0 at the beginning, 1 after the interrupt, and then always 1

pastedImage_0.png

pastedImage_2.png

pastedImage_1.pngpastedImage_3.png

Thanks

0 Likes
4 Replies
Roy_Liu
Moderator
Moderator
Moderator
5 comments on KBA First comment on KBA 10 questions asked

Are you sure the "AlarmFlag = 0" in the last picture is executed when you expect the AlarmFlag value go back to 0?

Roy Liu
0 Likes
Robin_Peng
Level 5
Level 5
Distributor - Macnica(GC)
100 replies posted 50 replies posted 50 questions asked

Hi Sir,

AlarmFlag is 0 when it is initially initialized. When an interrupt occurs, AlarmFlag becomes 1. After that, AlarmFlag is always in the state of 1, even if it is cleared to 0 in the main function, the program is set to 1 hour and 58 minutes alarm.The  alarm  code is modified according to RTC_P4_WDT_Example.Thanks.

void mcu_sleep(void)

{

    ADC_Stop();

    OP1_Stop();

    OP2_Stop();

    OP4_Stop();

    IDAC_8bit_Stop();

    //------------

    ADC_IRQ_Disable();

    BLE_bless_isr_Disable();

 

    isr_timer_Stop();

    Timer_1_Stop();

  isr_sw_ClearPending();

    SW_ClearInterrupt();

    //PLUG_SetInterruptMode(PLUG_0_INTR,PLUG_INTR_NONE);

    PLUG_SetInterruptMode(PLUG_0_INTR,PLUG_INTR_FALLING);

    PLUG_SetInterruptMode(PLUG_1_INTR,PLUG_INTR_FALLING);

  isr_plug_ClearPending();

    PLUG_ClearInterrupt();

  //isr_power_ClearPending();

    //CySysLvdClearInterrupt();

  isr_timer_ClearPending();

    ADC_IRQ_ClearPending();

    BLE_bless_isr_ClearPending();

  //^^^^^^^^^^^^^^^^^^^^^^^^

    //------------

    LCD_all(0);

    LCD_CS_Write(1);

    LCD_WR_Write(1);

    //lcd_command(LCD_OFF);

    //lcd_command(LCD_SYS_DIS);

   

    //Call the function that manages the BLESS power modes

    //CyBle_EnterLPM(CYBLE_BLESS_DEEPSLEEP);

    //CyBle_StopTimer();

    CyBle_Stop();

    //--------------

    //Internal low power oscillator is stopped as it is not used in this project

    CySysClkIloStop();//内部32K

    LCD_CS_Write(0);

    LCD_WR_Write(0);

    LCD_DATA_Write(0);

   

    //E2_SCL_Write(0);

    //E2_SDA_Write(0);

    AUDIO_SDA_Write(0);

    KG_Write(0);

    //CySysClkWriteSysclkDiv(CY_SYS_CLK_SYSCLK_DIV8);

    NO_USE1_SetDriveMode( NO_USE1_DM_DIG_HIZ);

    NO_USE2_SetDriveMode( NO_USE2_DM_DIG_HIZ);

    NO_USE3_SetDriveMode( NO_USE3_DM_DIG_HIZ);

    NO_USE4_SetDriveMode( NO_USE4_DM_DIG_HIZ);

    NO_USE5_SetDriveMode( NO_USE5_DM_DIG_HIZ);

    PULSE_Write(1);

    VCCD_KG_Write(1);//1 off

    VCCA_KG_Write(1);// 1 off

    plug_count=3;//

    sw_count=15;//

sleep:

    wake_up_f=0;

    CySysPmDeepSleep();

   

    if((wake_up_f==1)&& (alarmFlag == 1u)&&(clock_f== 0))

    {

        wake_up_f=0;

        RTC_ClearAlarmStatus();

    }

   

    if(wake_up_f==1) goto sleep;

    CySysClkIloStart();//内部32K

 

}

void UpdateTimeIsrHandler(void)

{

    /* Toggle pin state */

    RTC_Update();

}

void AlarmIsrHandler(void)

{

    alarmFlag = 1u;

    /* Clear interrupts state */

    RTC_ClearAlarmStatus();

}

void EnableRtcOperation(void)

{

    /* Configure COUNTER0 to generate interrupt every second. */

    CySysWdtDisable(CY_SYS_WDT_COUNTER0_MASK);

    CySysWdtSetClearOnMatch(CY_SYS_WDT_COUNTER0, 1u);

    CySysWdtEnable(CY_SYS_WDT_COUNTER0_MASK);

   

    /* Eegister UpdateTimeIsrHandler() by the COUNTER0. */

    CySysWdtSetInterruptCallback(CY_SYS_WDT_COUNTER0, UpdateTimeIsrHandler);

   

    /* Enable the COUNTER0 ISR handler. */

    CySysWdtEnableCounterIsr(CY_SYS_WDT_COUNTER0);

}

int main()

{

    CyDelay(500);

    sys_init();

    CyDelay(2000);//wait for running of rtc clock.

    RTC_Start();

    CyDelay(100);

   

    read_device_info();

    glucose_code=GLU_M_CODE;

    year=0x19;month=0x10;date=0x16;

    hour=0x12;minute=0x58;second=0; 

    rtc_settime();

   

    #ifdef LOW_POWER_MODE   

        CYBLE_LP_MODE_T         lpMode;

        CYBLE_BLESS_STATE_T     blessState;

    #endif

   

    apiResult = CyBle_Start(AppCallBack);

    CyGlobalIntEnable;

    //下面是重新上电后需要清0的项.

    temp_adjust_glu=0;

    temp_adjust_f=0;

   

    //CySysWdtSetClearOnMatch(CY_SYS_WDT_COUNTER0, 0u);

    //CySysWdtSetMode(CY_SYS_WDT_COUNTER0, CY_SYS_WDT_MODE_INT_RESET);

    /* Enable WDT COUNTER0 */

    //CySysWdtEnable(CY_SYS_WDT_COUNTER0_MASK);

   

    //CySysWdtEnableCounterIsr(CY_SYS_WDT_COUNTER0);

    /* Register EnableRtcOperation() by the COUNTER0. */

    //CySysWdtSetInterruptCallback(CY_SYS_WDT_COUNTER0, WDT_Interrupt);

    /* Start RTC component */

   // RTC_Start();

   

    /* Ignore second mask to call alarm */

   // RTC_SetAlarmMask((uint32)~RTC_ALARM_SEC_MASK);

    //-----------------

    for(;1;)

    {

        CySysWdtSetClearOnMatch(CY_SYS_WDT_COUNTER0, 0u);

    CySysWdtSetMode(CY_SYS_WDT_COUNTER0, CY_SYS_WDT_MODE_INT_RESET);

    /* Enable WDT COUNTER0 */

    CySysWdtEnable(CY_SYS_WDT_COUNTER0_MASK);

   

    CySysWdtEnableCounterIsr(CY_SYS_WDT_COUNTER0);

    /* Register EnableRtcOperation() by the COUNTER0. */

  CySysWdtSetInterruptCallback(CY_SYS_WDT_COUNTER0, EnableRtcOperation);

   

        //CyDelay(50);//

        //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

        plug_count=3;//

        sw_count=15;//

       

        while(PLUG_Read()!=3) ;//

        mcu_sleep();

       

        read_device_info();

        sys_init();

       

        CyBle_Start(AppCallBack);

        GlsInit();

        CtsInit();

        LCD_all(0);

        d_sys=0;

        ble_count=0;

        rtc_gettime();

        device_state=0;

        //----------

        CyDelay(200);

        a=read_power();

        if(a<2650)//

        {

            LCD_glucose_data(DISABLE_DOT,888);

            LCD_battery(VIEW_ON);

            for(i=0;i<6;i++)

            {

                LCD_battery(VIEW_ON);

                CyDelay(500);

                LCD_battery(VIEW_OFF);

                CyDelay(500);

            }

            battery_f=1;

            sw_count=15;

            plug_count=3;

            d_sys=0;

            LCD_battery(VIEW_ON);

        }

        else {battery_f=0;LCD_battery(VIEW_OFF);}

       

        //------------

        for(;1;)

        {

            //^^^^^^^^^^^^^^^^

            CyBle_ProcessEvents();

            if(CyBle_GetState() == CYBLE_STATE_CONNECTED)

            {

               GlsProcess();

            }

            else;

           

            if(time_count!=time_count_old)//0.01s-------------------------------------------------------

            {

                time_count_old=time_count;

           

                if(glucose_haveblood_f)

                {

                    if((glucose_time_count)%(1000/TC_PERIOD_MS)==0) LCD_glucose_data(DISABLE_DOT,(glucose_ton-glucose_time_count)/(1000/TC_PERIOD_MS));

                    else ;

                    //------

                    switch(glucose_time_count)

                    {

                        //.....

                  //-----

                        default: break;

                    }

                }

                //----------

                if((time_count%(500/TC_PERIOD_MS))==0)//0.5s======================================

                {

                    if(set_time_f) ;

                    else

                    {

                        /*#ifndef NO_AUDIO

                        if(audio_switch) dis_other(TRUMPET,ON);

                        else             dis_other(TRUMPET,OFF);

                        #endif

                   

                        if(blue_switch)  dis_other(WIFI,ON);

                        else             dis_other(WIFI,OFF);*/

                    }

               

                    if((d_sys==6)&&(glucose_haveblood_f==0))

                    {

                        LCD_blood(VIEW_XOR);//

                    }

                    if((d_sys>=1)&&(d_sys<=9))

                    {

                        rtc_gettime();

                        LCD_time();

                        LCD_COL(VIEW_XOR);//

                    }

                   

                    flash_f^=1;

                    if(cyBle_state==2)

                    {

                        ble_count+=1;

                    }

                    else ;

                   //------------------

                }

                //----0.5s  end-============================================================

            }

            if((d_sys==0)&&(jz_f==0)&&(battery_f==0))

            {

                if((sw_count!=15)||(plug_count!=3))

                {

                    d_sys=10;

                }

            }

     

            if((d_sys==0)&&(jz_f=='Y')&&(battery_f==0))

  {

  if(sw_count!=15)

  {

                    if((sw_count&1)==0)  //M

  {

                        while(SW_M_PRESS)//M

     {  

     if(glucose_time_count1>(6000/TC_PERIOD_MS)) break;

     }

     if(glucose_time_count1>(6000/TC_PERIOD_MS))//

     {

     d_sys=14;

                            who_flash=0;

                            glucose_time_count1=0;

                           

                            rtc_gettime();

         LCD_time();

                            LCD_trumpet(VIEW_ON);

                            LCD_B(VIEW_ON);

     }

                    }

                   

  if((sw_count&2)==0)  //

                    {

                        while(SW_KF_PRESS)//

     {

     if(glucose_time_count1>(6000/TC_PERIOD_MS)) break;

     }

     if(glucose_time_count1>(6000/TC_PERIOD_MS))//

     {

     d_sys=10;

                            glucose_time_count1=0;

     }

                        else

                        {

                            sw_kf_f=1;

                            sw_ch_f=0;

                            d_sys=15;

                            glucose_time_count1=0;

                        }

                    }

  if((sw_count&4)==0) //

  {

                        while(SW_CH_PRESS)//

     {

     if(glucose_time_count1>(6000/TC_PERIOD_MS)) break;

     }

     if(glucose_time_count1>(6000/TC_PERIOD_MS))//

     {

     d_sys=13;

                            glucose_time_count1=0;

     }

                        else

                        {

                            sw_kf_f=0;

                            sw_ch_f=1;

                            d_sys=17;

                            glucose_time_count1=0;

                        }

                    } 

                    if((sw_count&8)==0)  //T

  {

                        while(SW_T_PRESS)//T

     {  

     if(glucose_time_count1>(6000/TC_PERIOD_MS)) break;

     }

     if(glucose_time_count1>(6000/TC_PERIOD_MS))//

     {

     d_sys=14;

                            who_flash=0;

                            glucose_time_count1=0;

                           

                            rtc_gettime();

         LCD_time();

                            LCD_trumpet(VIEW_ON);

                            LCD_B(VIEW_ON);

     }

                        else

                        {

                            //set_time='N';

                            rtc_gettime();

                            T_year=year;

                            T_month=month;

                            T_date=date;

                            T_hour=hour;

                            T_minute=minute;

                            T_second=second;

                            glucose_time_count1=0;

                           

                            if(T_minute+58>60)

                            {

                                R_minute=T_minute+58-60;

                                R_hour=T_hour+2;

                                if(R_hour>23) R_hour=R_hour-0x24;

                            }

                            else

                            {

                                R_minute=T_minute+58;

                                R_hour=T_hour+1;

                                if(R_hour>23) R_hour=R_hour-0x24;

                            }

                           

                            year=T_year;

                            month=T_month;

                            date=T_date;

                            hour=T_hour;

                            minute=T_minute;

                            second=T_second;

                            //TIME_HR_MIN_SEC = T_hour|T_minute|T_second;//

                            //DATE_MONTH_DAY_YEAR = T_month|T_day|T_year;

                            CySysWdtSetClearOnMatch(CY_SYS_WDT_COUNTER0, 0u);

                            CySysWdtSetMode(CY_SYS_WDT_COUNTER0, CY_SYS_WDT_MODE_INT_RESET);

                            CySysWdtEnable(CY_SYS_WDT_COUNTER0_MASK);

                            CySysWdtEnableCounterIsr(CY_SYS_WDT_COUNTER0);

                            CySysWdtSetInterruptCallback(CY_SYS_WDT_COUNTER0, EnableRtcOperation);

                            /* Start RTC component */

                            RTC_Start();

                           

                            rtc_settime();

                            /* Set Date and Time */

                            //RTC_SetDateAndTime(TIME_HR_MIN_SEC,DATE_MONTH_DAY_YEAR);

   

                            /* Ignore second mask to call alarm */

                            RTC_SetAlarmMask((uint32)~RTC_ALARM_SEC_MASK);

                           

                            //ALARM_TIME_HR_MIN_SEC=R_hour|R_minute|T_second;

                           // ALARM_DATE_MONTH_DAY_YEAR=DATE_MONTH_DAY_YEAR;

                           

                            //alarmTimeDate.time = ALARM_TIME_HR_MIN_SEC;

                           // alarmTimeDate.date = ALARM_DATE_MONTH_DAY_YEAR;

                           

                            year=T_year;

                            month=T_month;

                            date=T_date;

                            hour=R_hour;

                            minute=R_minute;

                            second=T_second;

                            dateTime.time=0;

                            dateTime.time=hour;dateTime.time<<=8;

                            dateTime.time|=minute;dateTime.time<<=8;

                            dateTime.time|=second;

  

                            dateTime.date=0;

                            dateTime.date=year;dateTime.date<<=8;

                            dateTime.date|=month;dateTime.date<<=8;

                            dateTime.date|=date;

                            dateTime.date|=0x20000000;    

                           

                            /* Set Alarm Date and Time */

                            RTC_SetAlarmDateAndTime(&dateTime);

                            /* Set RTC time update period */

                            RTC_SetPeriod(1u, TICK_EACH_1_HZ);

                            /* Set function AlarmIsrHandler to be called when alarm triggers */

                            RTC_SetAlarmHandler(AlarmIsrHandler); 

                        }

                    }

  sw_count=15;

  }

              

                if(plug_count!=3)

                {

                    if((plug_count&2)==0)         plug_kf_f=1;//

                    else if((plug_count&1)==0)    plug_ch_f=1;//

                    else  

                    {

                        plug_kf_f=0;

                        plug_ch_f=0;

                    }

                   

                    if(plug_kf_f||plug_ch_f)

                    {

                        a=read_plug();

     if(a>2000)

         {//

     d_sys=19;

     }

     else

     {//

                            d_sys=1;

     }

                    } 

                    plug_count=3;

                }

               

              /*  if(sw_T_f==1)

                {

                    rtc_gettime();

                    //set_time='N';

                    if(T_minute+58>60)

                    {

                        R_minute=T_minute+58-60;

                        R_hour=T_hour+2;

                        if(R_hour>23) R_hour=R_hour-0x24;

                    }

                    else

                    {

                        R_minute=T_minute+58;

                        R_hour=T_hour+1;

                        if(R_hour>23) R_hour=R_hour-0x24;

                    }

                    rtc_gettime();

                    if((hour==R_hour)&&(minute==R_minute))

                    {

                        LCD_clock(VIEW_XOR);

                        LCD_time();

                        LCD_count(1);

                       

                        glucose_time_count1=0;

                        add2audio(36);

                        add2audio(36);

                        add2audio(37);

                        add2audio(37);

                       

                        ddelay_count=0;

         ddelay_data=(12000/TC_PERIOD_MS); 

                        d_sys=24;

                    }

                }

                if(sw_T_f==2)

                {

                    LCD_clock(VIEW_XOR);

                    LCD_time();

                    LCD_count(2);

                    //set_time='N';

                    if(T_minute+59>60)

                    {

                        R_minute=T_minute+59-60;

                        R_hour=T_hour+2;

                        if(R_hour>23) R_hour=R_hour-0x24;

                    }

                    else

                    {

                        R_minute=T_minute+59;

                        R_hour=T_hour+1;

                        if(R_hour>23) R_hour=R_hour-0x24;

                    }

                    rtc_gettime();

                    if((hour==R_hour)&&(minute==R_minute))

                    {

                        glucose_time_count1=0;

                        add2audio(36);

                        add2audio(36);

                        add2audio(37);

                        add2audio(37);

                       

                        ddelay_count=0;

         ddelay_data=(12000/TC_PERIOD_MS); 

                        d_sys=25;

                    }      

                }

                if(sw_T_f==3)

                {

                    LCD_clock(VIEW_XOR);

                    LCD_time();

                    LCD_count(3);

                     //set_time='N';

                    R_minute=T_minute;

                    R_hour=T_hour+2;

                    if(R_hour>23) R_hour=R_hour-0x24; 

   

                    rtc_gettime();

                    if((hour==R_hour)&&(minute==R_minute))

                    {

                        glucose_time_count1=0;

                        add2audio(36);

                        add2audio(36);

                        add2audio(37);

                        add2audio(37);

                       

                        ddelay_count=0;

         ddelay_data=(12000/TC_PERIOD_MS); 

                        d_sys=21;

                    }   

                   

                   

                }  

                */ 

               

                if((alarmFlag == 1u)&&(clock_f==0))

                {

                    alarmFlag  = 0u;

                    add2audio(36);

                    add2audio(36);

                    add2audio(37);

                    add2audio(37);

                       

                    ddelay_count=0;

     ddelay_data=(12000/TC_PERIOD_MS); 

                    d_sys=21;

                    clock_f=1;

                }

                else

                {

                    if(alarmFlag == 0u)

                    {

                        clock_f=0;

                    }

                    CySysPmDeepSleep();

                } 

  }

            switch(d_sys)

            { 

                case 1://

               

                    LCD_all(15);//

                    //add2audio(5);

                    if(audio_switch)

                    {

                        if(PLUG_KF)       add2audio(1);//

                        else if(PLUG_CH)  add2audio(2);//

                        else;

                    }

       sys_delay(2000/TC_PERIOD_MS,2);

    break;   

                   

                case 2:

                   

                    LCD_all(0);//

  rtc_gettime();

  LCD_time();

                   

                    if(audio_switch) LCD_trumpet(VIEW_ON);

                    else             LCD_trumpet(VIEW_OFF);

                    if(blue_switch)  LCD_B(VIEW_ON);

                    else             LCD_B(VIEW_OFF);

                   

                    if(PLUG_KF)

                    {

                        LCD_KF(VIEW_ON);

                        LCD_CH(VIEW_OFF);

                    }

                    else if(PLUG_CH)

                    {

                        LCD_KF(VIEW_OFF);

                        LCD_CH(VIEW_ON);

                    }

                    else;

                   

                    glucose_temperature=read_temp();

  if(temp_adjust_f=='X') //

                    {

                        sys_delay(1000/TC_PERIOD_MS,4);

                    }

                    else //

                    {

                        d_sys=3;

                        LCD_glucose_data(ENABLE_DOT,glucose_temperature+temp_adjust_glu);

                    }

                break;

                   

                case 3://

                    if(flash_f) LCD_temp(VIEW_ON);

                    else        LCD_temp(VIEW_OFF);

                   

                    if(PLUG_KF)

                    {

                        LCD_KF(VIEW_ON);

                        LCD_CH(VIEW_OFF);

                    }

                    else if(PLUG_CH)

                    {

                        LCD_KF(VIEW_OFF);

                        LCD_CH(VIEW_ON);

                    }

                    else;

                   

                    key_value=read_key();

                    if(key_value==KEY_VALUE_KF)

                    {

                        glucose_time_count1=0;

                        temp_adjust_glu+=1;

                        if((glucose_temperature+temp_adjust_glu)>500)

                        {

                            temp_adjust_glu=20-glucose_temperature;

                        }

                        else;

                        LCD_glucose_data(ENABLE_DOT,glucose_temperature+temp_adjust_glu); //                

                    }

                    else if(key_value==KEY_VALUE_CH)

                    {

                        glucose_time_count1=0;

                        temp_adjust_glu-=1;

                        if((glucose_temperature+temp_adjust_glu)<20)

                        {

                            temp_adjust_glu=500-glucose_temperature;

                        }

                        else ;

                        LCD_glucose_data(ENABLE_DOT,glucose_temperature+temp_adjust_glu);                      

                    }

                    else;

                    //------

                    if(glucose_time_count1>(6000/TC_PERIOD_MS))

                    {

                        d_sys=4;

                        glucose_temperature+=temp_adjust_glu;

                    }

                break;

               

                case 4:

                    if(PLUG_KF)

                    {

                        LCD_KF(VIEW_ON);

                        LCD_CH(VIEW_OFF);

                    }

                    else if(PLUG_CH)

                    {

                        LCD_KF(VIEW_OFF);

                        LCD_CH(VIEW_ON);

                    }

                    else;

                   

                    if((glucose_temperature>=TEMPERATURE_MIN)&&(glucose_temperature<=(TEMPERATURE_MAX)))

                    {

  glucose_time_count1=0;

  glucose_code=GLU_M_CODE;

                        d_sys=5;

                    }

                    else

                    {

                        if(glucose_temperature<TEMPERATURE_MIN)

                        {

                            add2audio(35);//

                            LCD_glucose_data(BYTE_E,11);//

                        }

                        else if(glucose_temperature>(TEMPERATURE_MAX))

                        {

                            add2audio(35);//

                            LCD_glucose_data(BYTE_E,12);//

                        }

                        else ;

                        ddelay_count=0;

                        ddelay_data=(3000/TC_PERIOD_MS);

                        d_sys=21;//

                    }

                break;

                /*case 4://

                    glucose_v_star=read_plug_ave();

                    if(glucose_v_star>=2000)

                    {

                        CyDelay(20);

                        if(glucose_v_star>=2000)

                        {

                            clear_data(FACTORY_STATE+1);//

                            ddelay_count=0;

                            ddelay_data=(3000/TC_PERIOD_MS);

                            d_sys=19;

                        }

                        else ;

                    }

                    else

                    {

                        d_sys=5;

                    }

                break;*/

               

                case 5://

                   

                    if(PLUG_KF)

                    {

                        LCD_KF(VIEW_ON);

                        LCD_CH(VIEW_OFF);

                    }

                    else if(PLUG_CH)

                    {

                        LCD_KF(VIEW_OFF);

                        LCD_CH(VIEW_ON);

                    }

                    else;

                   

                    LCD_temp(VIEW_OFF);

                    //LCD_DOT(VIEW_OFF);

                    LCD_glucose_data(BYTE_SPACE,0x07);

                   

                    glucose_v_star=read_plug_ave();

                    CyDelay(10);

                    glucose_v_star=read_plug_ave();

                    if((glucose_v_star>=min_400)&&(glucose_v_star<=max_400))

                    {

                        d_sys=6;//

                        add2audio(8);//    

                    }

                    else

                    {

                        add2audio(35);//

                        LCD_glucose_data(BYTE_E,7);//

                        ddelay_count=0;

                        ddelay_data=(3000/TC_PERIOD_MS);

                        d_sys=21;//

                    }

                break;

                   

                case 6://

                    //

                    if(((PLUG_Read()&1)==0)||((PLUG_Read()&2)==0))

                    {//

                        if(PLUG_KF)

                        {

                            LCD_KF(VIEW_ON);

                            LCD_CH(VIEW_OFF);

                        }

                        else if(PLUG_CH )

                        {

                            LCD_KF(VIEW_OFF);

                            LCD_CH(VIEW_ON);

                        }

                        else;

                       

                        if(glucose_haveblood_f==0)

                        {

                            if(read_plug_ave()>=400+25)

                            {

                                glucose_haveblood_f=1;

                                GLUCOSE_KG_OFF;

                                LCD_blood(VIEW_OFF);

                                LCD_glucose_data(DISABLE_DOT,glucose_ton/(1000/TC_PERIOD_MS));

                   

                                //Timer_1_Start();

                                //isr_timer_Start();

                                //isr_timer_ClearPending();

                                set_plug_d_hiz();

                                d_sys=7;//wait

                                //-------------

                                glucose_time_count=0;

                                glucose_time_count_old=0;

                                PULSE_Write(1);//

                                TEST_DELAY;

                                PULSE_Write(0);

                            }

                        }

                     //--

                    }

                    else if(((PLUG_Read()&1)==0)&&((PLUG_Read()&2)==0))

                    {

                        //

                        LCD_blood(VIEW_OFF);

                        add2audio(35);//

                        LCD_glucose_data(BYTE_E,13);

                        ddelay_count=0;

                        ddelay_data=(4000/TC_PERIOD_MS);

                        d_sys=21;

                    }

                    else

                    {  //

                        CyDelay(10);

                        if(((PLUG_Read()&1)==0)|| ((PLUG_Read()&2)==0));

                        else

                        {  //

                            LCD_blood(VIEW_OFF);

                            add2audio(35);//

                            LCD_glucose_data(BYTE_E,0);//

                            ddelay_count=0;

                            ddelay_data=(4000/TC_PERIOD_MS);

                            d_sys=21;

                        }

                    }

                   //

                   

                break;

                   

                case 7:

  ;//wait

  break;

                   

                case 8://

                    //.....

                   

                   

                break;

               

                case 9://

                   

                break;

                 

                case 10://

  

                   

                case 11:

                   

                break;

               

                case 12:

                 

                break;

               

                case 13://

                   

                    year=soft_ver[0];

  month=soft_ver[1];

  date=soft_ver[2];

                    LCD_soft();

                   

                    LCD_glucose_data(BYTE_c,GLU_M_CODE);

                    LCD_count(read_temp());

                    ddelay_count=0;

                    ddelay_data=(5000/TC_PERIOD_MS);

                    d_sys=21;

               

                break;

                   

                case 14://

                   

                    if(set_time!='N')

                    {

                    key_value=read_key();

  if((sw_count&1)==0)

  {//-

                        if(key_value==KEY_VALUE_M)

                        {

     who_flash+=1;

     if(who_flash>=7) who_flash=0;

     glucose_time_count1=0;

                        }

  }

  else if(key_value==KEY_VALUE_KF)

  {//+

  sw_add(who_flash);

  glucose_time_count1=0;

                        flash_f=1;

  }

                    else if(key_value==KEY_VALUE_CH)

                    {

                        sw_sub(who_flash);

  glucose_time_count1=0;

                        //screen_time();

                        flash_f=1;

                    }

  else ;

  sw_flash(who_flash);

  if(glucose_time_count1>(7000/TC_PERIOD_MS))//7s

  {

  second=0;

  haveset_time_f='S';

  if(bcd2h(date)>date_max(bcd2h(year),bcd2h(month))) date=h2bcd(date_max(bcd2h(year),bcd2h(month)));

  rtc_settime();

  write_device_info();

  LCD_glucose_data(BYTE_SPACE,0x07);

  set_time_f=0;

  d_sys=21;

  glucose_time_count1=0;

  }

                    }

                break;

                   

                case 15:

                   

                    CyDelay(SW_DELAY);

                    read_dis_glucose_kf(0,1);

                    d_sys=16;

                    key_count=0;

                    glucose_time_count1=0;

                    LCD_KF(VIEW_ON);

               

                break;

               

                case 16:

                   

                    key_value=read_key();

  if(key_value==KEY_VALUE_KF)

  {

  key_count+=1;

  if(key_count>5) key_count=0;else ;

  if(key_count==0)

                        {

                            read_dis_glucose_kf(glucose_read_kf,1);

                            LCD_average(VIEW_OFF);

                        }

  else if(key_count==1) {view_average(7); LCD_average(VIEW_ON);}

  else if(key_count==2) {view_average(14);LCD_average(VIEW_ON);}

  else if(key_count==3) {view_average(28);LCD_average(VIEW_ON);}

                        else if(key_count==4) {view_average(60);LCD_average(VIEW_ON);}

  else if(key_count==5) {view_average(90);LCD_average(VIEW_ON);}

  else ;

  glucose_time_count1=0;

  }

  else if(key_value==KEY_VALUE_M)

  {

  glucose_read_kf+=1;

  if(glucose_read_kf>=150) glucose_read_kf=0;

  read_dis_glucose_kf(glucose_read_kf,1);

  glucose_time_count1=0;

                        LCD_average(VIEW_OFF);

  }

  else;

  if(glucose_time_count1>(6000/TC_PERIOD_MS))//6s

  {

  d_sys=0;

  glucose_time_count1=0;

                        glucose_read_kf=0;

  }

                   

                break;

               

                case 17:

                    CyDelay(SW_DELAY);

                    read_dis_glucose_ch(0,1);

                    d_sys=18;

                    key_count=0;

                    glucose_time_count1=0;

                    LCD_CH(VIEW_ON);

                   

                break;

                   

                case 18:

                    key_value=read_key();

  if(key_value==KEY_VALUE_CH)

  {

  key_count+=1;

  if(key_count>5) key_count=0;else ;

  if(key_count==0)

                        {

                            read_dis_glucose_ch(glucose_read_ch,1);

                            LCD_average(VIEW_OFF);

                        }

  else if(key_count==1) {view_average(7); LCD_average(VIEW_ON);}

  else if(key_count==2) {view_average(14);LCD_average(VIEW_ON);}

  else if(key_count==3) {view_average(28);LCD_average(VIEW_ON);}

                        else if(key_count==4) {view_average(60);LCD_average(VIEW_ON);}

  else if(key_count==5) {view_average(90);LCD_average(VIEW_ON);}

  else ;

  glucose_time_count1=0;

  }

  else if(key_value==KEY_VALUE_M)

  {

  glucose_read_ch+=1;

  if(glucose_read_ch>=150) glucose_read_ch=0;

  read_dis_glucose_ch(glucose_read_ch,1);

  glucose_time_count1=0;

                        LCD_average(VIEW_OFF);

  }

  else;

  if(glucose_time_count1>(6000/TC_PERIOD_MS))//6s

  {

  d_sys=0;

                        ble_count=0;

  glucose_time_count1=0;

                        glucose_read_ch=0;

  }

               

                break;

                

                case 19:

                    plug_count=3;

       write_ee_clear();

       temp_adjust_f='X';

    temp_adjust_glu=0;

    glucose_write_kf=0;

                    glucose_write_ch=0;

    write_device_info();

    CyDelay(20);//20

                    ddelay_count=0;

                    ddelay_data=(1000/TC_PERIOD_MS);

       d_sys=21;    

                break;

                

                case 20:

                    if(ddelay_count>ddelay_data)

     {

     d_sys=21;

                        ddelay_count=0;

         ddelay_data=(3000/TC_PERIOD_MS);                      

     }

                break;

                   

                case 21:

                    if(ddelay_count>ddelay_data)

     {

     d_sys=0;

                        ble_count=0;

     }

                    else;

                   

                    if((PLUG_KF)||(PLUG_CH))

                    {

                        ddelay_count=0;

                    }

                    else ;

                   

                    if((sw_count&8)==0)

                    {

                        d_sys=0;

                        ble_count=0;

                        set_time=0;

                        sw_T_f=0; 

                    }

                    else ;

                   

                break;

                   

                case 22://

     if((ddelay_count>=ddelay_data)&&(ddelay_data!=0))

     {

     d_sys=d_sys_buff;

     ddelay_data=0;

                        ble_count=0;

     }

     break;

               

                case 23:

                   

                    if(ddelay_count>ddelay_data)

     {

     d_sys=0;

                        ble_count=0;

     }

                    else;

                   

                break;

                   

                case 24: 

                    if(ddelay_count>ddelay_data)

     {

     d_sys=0;

                        ble_count=0;

                        sw_T_f=2;

     }

                    else;

                   

                    if((sw_count&8)==0)

                    {

                        d_sys=0;

                        ble_count=0;

                        set_time=0;

                        sw_T_f=0; 

                    }

                    else ;

                   

                break;

                   

                case 25:

                    if(ddelay_count>ddelay_data)

     {

     d_sys=0;

                        ble_count=0;

                        sw_T_f=3;

     }

                    else;

                   

                    if((sw_count&8)==0)

                    {

                        d_sys=0;

                        ble_count=0;

                        set_time=0;

                        sw_T_f=0; 

                    }

                    else ;

 

                break;  

                   

        

                   

      

                   

            }

            if(d_sys==0)

  {

                if(cyBle_state!=CYBLE_STATE_CONNECTED) break;

  else if((cyBle_state==CYBLE_STATE_CONNECTED)&&(ble_count>BLE_WAIT_COUNT)) break;

  else ;

  }

  else ;

           

            if(battery_f) break;

           

        }

    }

}

Thanks

0 Likes
Robin_Peng
Level 5
Level 5
Distributor - Macnica(GC)
100 replies posted 50 replies posted 50 questions asked

Hi Sir,

I am sure the "AlarmFlag = 0" in the last picture is executed when I expect the AlarmFlag value go back to 0.I stepped through the debugging.

0 Likes
Aashita_R
Moderator
Moderator
Moderator
50 likes received 100 solutions authored 250 replies posted

Hi RoPe_2386886​,

I checked the code example RTC_P4_WDT_Example and found that the alarmFlag is set once the execution enters the "AlarmIsrHandler" function. The code example worked correctly and the alarm was triggered which led to the setting of alarmFlag to 0 inside the if statement in the main(). The issue with your code might be that the execution is not entering the AlarmIsrHandler due to some reason. Please check this accordingly in your project.

Also, Please check if the clock_f variable is preventing the setting of the alarmFlag since it is used in your code for the condition of the if statement. I have attached my project where I modified the alarm time to check the working of the code example. Please go through it once and let us know if you are facing the issue again.

Best Regards,

Aashita