|
STM8單鍵長短按操作帶液晶顯示- #include "stm8s.h"
- #include "ht1621.h"
- #include "ht1621.c"
- 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;
- unsigned char Half_SecFlag;
- unsigned char Key_Count,Key_flag,Key_long_flag;
- extern unsigned int count2;
- 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(4,smg_number[Min2]);Ht1621WrOneNum(6,smg_number[Min1]);
- if((Half_SecFlag!=0))
- {
- Ht1621WrOneData(8,0x04);
- }
- else
- {
- Ht1621WrOneData(8,0x00);
- }
- if(ST_flag)
- {
- Ht1621WrCmd(LCDOFF);ST_flag=0;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_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_off();
- GPIO_WriteHigh(GPIOB, BackLight);
- Ht1621WrOneData(8,0x04);//col
-
- TIM4_int();
- TIM1_int();
- Beep_int();
-
- rim();
-
- while (1)
-
- {
- Data_process();
- Display();
-
- if(Key_flag==1)
- {
- TIM1_Cmd(ENABLE);ST_Sec=0;count2=0;
- }
- if(Key_flag==2)
- {
- TIM1_Cmd(DISABLE);
- Key_flag=0; ST_Sec=0;
- }
- if(Key_long_flag==1)
- {
- Min=0;Sec=0;Key_long_flag=0;
- }
- /*if (GPIO_ReadInputPin(GPIOC, GPIO_PIN_2) == RESET)
- {
- Delay(0xffff);
- if (GPIO_ReadInputPin(GPIOC, GPIO_PIN_2) == RESET)
- {
- //GPIO_WriteReverse(GPIOB, GPIO_PIN_3);
- //TIM4_Cmd(DISABLE);
- Key_Flag=1;
- Key_Count++;
- if(Key_Count==1)
- {TIM4_Cmd(ENABLE);}
- if(Key_Count==2)
- {TIM4_Cmd(DISABLE);}
- if(Key_Count==3)
- {Min=0;Sec=0;Key_Count=0;}
- }
- while(!GPIO_ReadInputPin(GPIOC, GPIO_PIN_2));//BEEP_Cmd(DISABLE);
- }
- if (GPIO_ReadInputPin(GPIOC, GPIO_PIN_1) == RESET)
- {
- Delay(0xffff);//BEEP_Cmd(ENABLE);
- if (GPIO_ReadInputPin(GPIOC, GPIO_PIN_1) == RESET)
- {
- //TIM4_Cmd(ENABLE);
- Min++;Key_Flag2=1;
- if(Min==60)
- {
- Min=0;
- }
- }
- while(!GPIO_ReadInputPin(GPIOC, GPIO_PIN_1));//BEEP_Cmd(DISABLE);
- Key_Flag2=0;
- }*/
-
- }
-
- }
- #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,count2;
- unsigned char BSec;
- extern unsigned char Hour,Min,Sec,Sec_4,Min_4,Half_SecFlag;
- INTERRUPT_HANDLER(TIM1_UPD_OVF_TRG_BRK_IRQHandler, 11)
- {
- /* In order to detect unexpected events during development,
- it is recommended to set a breakpoint on the following instruction.
- */
- count++;
- TIM1_ClearFlag(TIM1_FLAG_UPDATE);
- if(count==1)
- {
- BSec++;count=0;Half_SecFlag=~Half_SecFlag;
- if(BSec==2)
- {Sec++;BSec=0;
- if(Sec==60)
- {Sec=0;Min++;
- if(Min==60)
- {
- Min=0;
- }
- }
- }
- }
- }
- //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,Key_flag;
- unsigned int Key_cnt,Key_mode;
- 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==4)//20ms
- {
- Key_mode++;
- if(Key_mode==1)
- {
- Key_flag=0;ST_flag=0;Key_flag=1;
- }
- if(Key_mode==2)
- {
- Key_mode=0;ST_flag=0;Key_flag=0;
- Key_flag=2;
- }
- }
- if(Key_cnt>=3*200)//4s
- {
- if(Key_cnt>800)
- Key_long_flag=1;
- }
- }
- else
- {Key_cnt=0;Key_long_flag=0;}
- if(Key_flag==0)
- {
- count2++;
- if(count2==200)
- {
- count2=0;ST_Sec++;
- if(ST_Sec==10)
- {
- ST_Sec=0;ST_flag=1;
- }
- }
-
- }
-
-
- }
復(fù)制代碼
|
|