- #include "stm8s.h"
- #include "ht1621.h"
- unsigned char const smg_number[10]={0xaf,0x06,0xcb,0x4f,0x66,0x6d,0xed,0x07,0xef,0x6f};//0123456789
- unsigned char Hour2,Hour1,Min1,Min2,Sec2,Sec1;
- unsigned char Hour,Min,Sec,ST_Sec,ST_flag,ST_fig;
- unsigned char Half_SecFlag=1,Key_exit_fig,SecFlag;
- unsigned char Key_Count,Key_flag,Key_long_flag,Key_fig;
- extern unsigned int count2;
- extern unsigned char Key_mode;
- void Data_process(void)
- {
- Hour2=Hour/10;
- Hour1=Hour%10;
- Min2=Min/10;
- Min1=Min%10;
- Sec2=Sec/10;
- Sec1=Sec%10;
- }
- void Display(void)
- {
- Ht1621WrOneNum(9,smg_number[Sec2]);Ht1621WrOneNum(12,smg_number[Sec1]);
- Ht1621WrOneNum(6,smg_number[Min1]);
- if(Half_SecFlag)
- {
- Ht1621WrOneData(8,0);
- }
- else
- {
- Ht1621WrOneData(8,0x04);//col
- }
- if(Min2==0)
- {
- Ht1621WrOneNum(4,0);
- }
- else
- {
- Ht1621WrOneNum(4,smg_number[Min2]);
- }
- if(ST_flag)
- {
- Ht1621WrCmd(LCDOFF);ST_flag=0;GPIO_WriteLow(GPIOB, GPIO_PIN_3);
- halt();
- }
- }
- void GPIO_int(void)
- {
- GPIO_Init(GPIOB, GPIO_PIN_HNIB, GPIO_MODE_OUT_PP_HIGH_FAST);
- GPIO_Init(GPIOB, GPIO_PIN_3, GPIO_MODE_OUT_PP_LOW_FAST);
- GPIO_Init(GPIOD, GPIO_PIN_4, GPIO_MODE_OUT_PP_HIGH_FAST);
- GPIO_Init(GPIOC, GPIO_PIN_LNIB, GPIO_MODE_IN_PU_IT);
- EXTI_SetExtIntSensitivity(EXTI_PORT_GPIOC, EXTI_SENSITIVITY_FALL_ONLY);
- }
- void TIM4_int(void)
- {
- //TIM4_TimeBaseInit(TIM4_PRESCALER_128, 77);//5ms
- TIM4_TimeBaseInit(TIM4_PRESCALER_128, 15);//1ms
- TIM4_ClearFlag(TIM4_FLAG_UPDATE);
- TIM4_ITConfig(TIM4_IT_UPDATE, ENABLE);
- TIM4_Cmd(ENABLE);
- }
- void TIM1_int(void)
- {
- TIM1_TimeBaseInit(19, TIM1_COUNTERMODE_UP, 50000, 0);//500ms
- TIM1_ITConfig(TIM1_IT_UPDATE, ENABLE);
- TIM1_GenerateEvent(TIM1_EVENTSOURCE_UPDATE);
- //TIM1_Cmd(ENABLE);
- }
- void Beep_int(void)
- {
- BEEP_DeInit();
- BEEP_LSICalibrationConfig(128000);
- BEEP_Init(BEEP_FREQUENCY_2KHZ);
- }
- void main(void)
- {
- /* Infinite loop */
- GPIO_int();
- Ht1621_Init();
- Ht1621_all_on();
- GPIO_WriteHigh(GPIOB, BackLight);
- Half_SecFlag=1;//ST_fig=1;
- TIM4_int();
- TIM1_int();
- Beep_int();BEEP_Cmd(ENABLE);Ht1621_all_on();
- rim();
- while (1)
- {
- if(ST_fig==1)
- {
- ST_fig=0;
- Ht1621_all_off();
- BEEP_Cmd(DISABLE);
- }
- if(Key_flag==1)
- {
- TIM1_Cmd(ENABLE);
- ST_Sec=0;
- count2=0;
- }
- if(Key_flag==2)
- {
- TIM1_Cmd(DISABLE);
- Half_SecFlag=0;//COL
- ST_Sec=0;
- Key_flag=0;
- }
- /*if(Key_long_flag==1)
- {
- //Beep_int();
- BEEP_Cmd(ENABLE);Ht1621_all_on();TIM4_int();
- TIM1_int();
- if(ST_fig==1)
- {
- ST_fig=0;
- Ht1621_all_off();Min=0;Sec=0;
- BEEP_Cmd(DISABLE);
- }
- }*/
- Display();Data_process();
- }
- }
- #ifdef USE_FULL_ASSERT
- /**
- * @brief Reports the name of the source file and the source line number
- * where the assert_param error has occurred.
- * @param file: pointer to the source file name
- * @param line: assert_param error line source number
- * @retval : None
- */
- void assert_failed(u8* file, u32 line)
- {
- /* User can add his own implementation to report the file name and line number,
- ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
- /* Infinite loop */
- while (1)
- {
- }
- }
- #endif
- /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
- /unsigned int count=0;unsigned char BSec;
- extern unsigned char SecFlag,Key_Flag,Key_Flag2,Key_long_flag;
- extern unsigned char Hour,Min,Sec,ST_Sec,ST_flag,ST_fig,Key_flag,Key_fig;
- unsigned int Key_cnt,Key_mode,Beep_fig;
- INTERRUPT_HANDLER(TIM4_UPD_OVF_IRQHandler, 23)
- {
- TIM4_ClearITPendingBit(TIM4_IT_UPDATE);
- if (GPIO_ReadInputPin(GPIOC, GPIO_PIN_1)== RESET)
- {
- Key_cnt++;
- if(Key_cnt==20)//20ms
- {
- Key_mode++;Beep_fig=50;Key_fig=1;
- if(Key_mode==1)
- {
- ST_flag=0;Key_flag=1;
- }
- if(Key_mode==2)
- {
- Key_mode=0;ST_flag=0;
- Key_flag=2;
- }
- }
- if(Key_cnt>=3*1000)//4s200*5
- {
- if(Key_cnt>4000)//800*5
- Key_long_flag=1;
- Key_flag=0;Key_fig=0;Key_mode=0;//TIM4_Cmd(DISABLE);
- BEEP_Cmd(ENABLE);Ht1621_all_on();Min=0;Sec=0;ST_Sec=0;
- if(ST_fig==1)
- {
- ST_fig=0;//TIM4_Cmd(ENABLE);
- Ht1621_all_off();Min=0;Sec=0;
- BEEP_Cmd(DISABLE);Display();
- }
- }
- }
- else
- {Key_cnt=0;Key_long_flag=0;}
- if(Key_fig)
- {
- if(Beep_fig)
- {
- BEEP_Cmd(ENABLE);
- Beep_fig--;
- }
- else //(!Beep_fig)
- {
- BEEP_Cmd(DISABLE);
- Beep_fig=0;
- }
- }
- if(Key_flag==0)
- {
- count2++;
- if(count2==1000)
- {
- count2=0;ST_Sec++;
- if(ST_Sec==2)
- {
- ST_fig=1;
- }
- if(ST_Sec==10)
- {
- ST_Sec=0;ST_flag=1;
- }
- }
-
- }
-
-
- }
復制代碼
|