用的STM8S208(UM0482)的开发板学习的时候用的风驰的STM8的教程在学 但是学到中断的时候发现按风驰的例子我修改对应的IO来调的时候不行像教程那样。查了很久没有办法,只能发帖请各位老师帮帮忙,下面是程序 。key_exti.h
#include "key_exti.h"
void Buttom_Init(void)
{
GPIO_Init(GPIOC,Buttom0|Buttom1|Buttom2,GPIO_MODE_IN_PU_IT);
EXTI_SetExtIntSensitivity(EXTI_PORT_GPIOC, EXTI_SENSITIVITY_FALL_ONLY);
}
key_exti.c
#ifndef __KEY_EXTI_H
#define __KEY_EXTI_H
#include "stm8s.h"
#define Buttom0 GPIO_PIN_0
#define Buttom1 GPIO_PIN_1
#define Buttom2 GPIO_PIN_2
void Buttom_Init(void);
#endif
led.c
#include "led.h"
void LED_Init(void)
{
GPIO_Init(GPIOH,(led1|led2|led3|led4),\
GPIO_MODE_OUT_PP_HIGH_FAST);//定义LED的管脚的模式
}
void SetLedOFF(void)
{
GPIO_Write(GPIOH, 0xff);
}
void Led_Reverse(GPIO_Pin_TypeDef LedPins)
{
GPIO_WriteReverse(GPIOH, LedPins);
}
led.h
#ifndef __LED_H
#define __LED_H
#include "stm8s_gpio.h"
#define ON 0
#define OFF 1
#define bit_set 1
#define bit_reset 0
#define led1 GPIO_PIN_0
#define led2 GPIO_PIN_1
#define led3 GPIO_PIN_2
#define led4 GPIO_PIN_3
#define LED1(ON_OFF) if(ON_OFF==ON)GPIO_WriteLow(GPIOH,led1);\
else GPIO_WriteHigh(GPIOH, led1)
#define LED2(ON_OFF) if(ON_OFF==ON)GPIO_WriteLow(GPIOH, led2);\
else GPIO_WriteHigh(GPIOH, led2)
#define LED3(ON_OFF) if(ON_OFF==ON)GPIO_WriteLow(GPIOC,led3);\
else GPIO_WriteHigh(GPIOH, led3)
#define LED4(ON_OFF) if(ON_OFF==ON)GPIO_WriteLow(GPIOH, led4);\
else GPIO_WriteHigh(GPIOH, led4)
void LED_Init(void);
void SetLedOFF(void);
void Led_Reverse(GPIO_Pin_TypeDef LedPins);
main.c
#include "stm8s.h"
#include "intrinsics.h"
#include "uart.h"
#include "led.h"
#include "key_exti.h"
void Delay(u32 nCount);
/* Private defines -----------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
int main(void)
{
/* Infinite loop */
/*设置内部时钟16M为主时钟*/
CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV1);
/*!<Set High speed internal clock */
Buttom_Init();
Uart_Init();
LED_Init();
__enable_interrupt();
SetLedOFF();
UART1_SendString("Key_Exti外部中断---STM8 Development Board of FengChi Electron",\
sizeof("Key_Exti外部中断---STM8 Development Board of FengChi Electron"));
Delay(0xffff);
UART1_SendByte('\n');
Delay(0xffff);
while (1)
{
}
}
void Delay(u32 nCount)
{
/* Decrement nCount value */
while (nCount != 0)
{
nCount--;
}
}
|