|
- /* Includes ------------------------------------------------------------------*/
- #include "stm8l10x.h"
- //定義LED、按鍵接口
- #define LED_GPIO_PORT GPIOD
- #define LED_GPIO_PINS GPIO_Pin_0
- #define KEY_GPIO_PORT GPIOB
- #define KEY_GPIO_PINS GPIO_Pin_1
- /*******************************************************************************
- ****入口參數(shù):無
- ****出口參數(shù):無
- ****函數(shù)備注:不精確延時(shí)函數(shù)
- ****版權(quán)信息:藍(lán)旗嵌入式系統(tǒng)
- *******************************************************************************/
- void Delay(__IO uint16_t nCount)
- {
- /* Decrement nCount value */
- while (nCount != 0)
- {
- nCount--;
- }
- }
- /*******************************************************************************
- ****入口參數(shù):無
- ****出口參數(shù):無
- ****函數(shù)備注:主函數(shù),PD0接LED,灌流,LED大約1S閃爍頻率
- ****版權(quán)信息:藍(lán)旗嵌入式系統(tǒng)
- *******************************************************************************/
- void main(void)
- {
- GPIO_Init(LED_GPIO_PORT, LED_GPIO_PINS, GPIO_Mode_Out_PP_Low_Slow);//初始化LED,GPD0低速推挽輸出
-
- CLK_PeripheralClockConfig (CLK_Peripheral_TIM4,ENABLE); //使能外設(shè)時(shí)鐘,STM8L外設(shè)時(shí)鐘默認(rèn)關(guān)閉,使用前需使能
-
- TIM4_DeInit();
- TIM4_TimeBaseInit(TIM4_Prescaler_128, 0xff);//16M/8/128=15.625K,0xff=255,255*(1/15.625)=0.01632S,大約61次中斷是1S
-
- TIM4_ITConfig(TIM4_IT_Update, ENABLE);//向上溢出中斷使能,中斷向量號(hào)25
- TIM4_Cmd(ENABLE);//TIM4使能
- enableInterrupts();//開啟中斷總開關(guān)
- while(1)
- {
-
- }
- }
-
- /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
復(fù)制代碼
|
|