整个代码如下。#include "stm8s.h"
#include "stm8s_gpio.h"
#include "stdio.h"
#pragma vector=0x05
__interrupt void PortA_InterruptHandler(void)
{
GPIO_DeInit(GPIOB);
}
/************************************************/
/************ CLK SWITCH CODE*******************/
void ClkSelectInit()
{
ErrorStatus SwitchClkFlag;
CLK_DeInit();
CLK_ClockSwitchCmd(ENABLE); //ENABLE AUTOMATIC SWITCH CLOCKSOURCE
SwitchClkFlag=CLK_ClockSwitchConfig(CLK_SWITCHMODE_AUTO, CLK_SOURCE_HSI, ENABLE, CLK_CURRENTCLOCKSTATE_ENABLE);
if(SwitchClkFlag==SUCCESS)
CLK_HSICmd(ENABLE);
}
/***********************************************/
/************GPIOA init CODE*******************/
void GpioInit()
{
GPIO_DeInit(GPIOA); //PortA DATA Reset Init;
GPIO_Init(GPIOA, GPIO_PIN_1, GPIO_MODE_OUT_PP_LOW_SLOW); // GPIOA bit 1 is output
GPIO_Init(GPIOA, GPIO_PIN_2, GPIO_MODE_IN_PU_IT); //GPIOA BIT 2 external interrupt pull-up resistant.
GPIO_WriteHigh(GPIOA, GPIO_PIN_1); //port bit 1 is high level;
}
/*********************************************/
/***********GPIO Interrupt Setting Code************/
void GpioInterruptInit()
{
EXTI_DeInit();
EXTI_SetExtIntSensitivity(EXTI_PORT_GPIOA, EXTI_SENSITIVITY_FALL_ONLY);//setting portA have a interrupt,fall trigger.
}
/********************************************/
/**********Main *********Code***************/
int main(void)
{
ClkSelectInit();
GpioInit();
GpioInterruptInit();
enableInterrupts();
while(1);
}
|