📄 main.c
字号:
/*****************************************************************************************
ST7LITE39 ITC 应用程序(以下程序参考或采用ST公司MCD Application Team提供的相关子程序)
*****************************************************************************************/
#include "ST7lib_config.h"
//函数原型声明
void EI3_IT_Routine(void);
void EI2_IT_Routine(void);
void main(void);
volatile unsigned int count;
void main (void)
{
unsigned char Pin = 0;
ITC_Init (); /* 初始化ITC */
/* PA4和PA2是推挽(push-pull)输出 */
IO_Output(IO_PUSH_PULL,IO_PORT_A,((unsigned char)IO_PIN_4 |
(unsigned char)IO_PIN_2 ));
ITC_ConfigureInterrupt(IT_PortB,Pin, IT_EDGE_F);
/*设置port B(PB0~PB7,不包括PB4)的 EI2/EI3下降沿触发*/
EnableInterrupts; /*使能中断*/
}
/*******************************************************************************
EI3中断服务程序( 用于点亮 D2 LED)
REV2.0板上开关和端口的对应关系:
SW4--PB3
SW3--PB2
SW2--PB1
SW1--PB0
*******************************************************************************/
#ifdef _COSMIC_ /* Cosmic编译器*/
@interrupt /* Cosmic中断处理 */
#else
#error "Unsupported Compiler!" /* 编译器未知 */
#endif
void EI3_IT_Routine (void)
{
unsigned int i;
IO_Write (IO_PORT_A,IO_PIN_2,IO_DATA_LOW); /* 在PA2打开LED*/
for ( i=0;i<=1000;i++) /* 延时 */
{
Nop
}
IO_Write (IO_PORT_A,IO_PIN_2,IO_DATA_HIGH); /* 在PA2关闭LED */
ClearInterrupts
}
/*******************************************************************************
EI2中断服务程序( 用于点亮 D4 LED)
REV2.0板上开关和端口的对应关系:
SW4--PB3
SW3--PB2
SW2--PB1
SW1--PB0
*******************************************************************************/
#ifdef _COSMIC_ /* Cosmic编译器*/
@interrupt /* Cosmic中断处理 */
#else
#error "Unsupported Compiler!" /* 编译器未知 */
#endif
void EI2_IT_Routine (void)
{
unsigned char Temp;
count++;
if(count == 5000)
{
Temp = IO_Read (IO_PORT_A ); /* 切换PA4 */
if (Temp & 0x08)
{
IO_Write (IO_PORT_A,IO_PIN_4,IO_DATA_LOW); /* 在PA4打开LED */
}
else
{
IO_Write (IO_PORT_A,IO_PIN_4,IO_DATA_HIGH); /* 在PA4关闭LED */
}
count = 0;
}
ClearInterrupts
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -