//PA4口中断初始化
void Driver_ExtIntOn(void)
{
//PA4 上拉输入
PA_DDR &= CLRBIT4;
PA_CR1 |= SETBIT4;
//下降沿触发
EXTI_CR1 |= SETBIT1;
EXTI_CR1 &= CLRBIT0;
//开启端口中断
PA_CR2 |= SETBIT4;
}
volatile bool ExiFlag = False;
//中断服务程序
@far @interrupt void Driver_EXI_Interrupt(void)
{
//--- 外部中断处理 ----
//置中断标志
ExiFlag = True;
}
struct interrupt_vector const _vectab[] = {
{0x82, (interrupt_handler_t)_stext}, /* reset */
{0x82, NonHandledInterrupt}, /* trap */
{0x82, NonHandledInterrupt}, /* irq0 */
{0x82, NonHandledInterrupt}, /* irq1 */
{0x82, NonHandledInterrupt}, /* irq2 */
{0x82, Driver_EXI_Interrupt}, /* irq3 */
{0x82, NonHandledInterrupt}, /* irq4 */
{0x82, NonHandledInterrupt}, /* irq5 */
{0x82, NonHandledInterrupt}, /* irq6 */
{0x82, NonHandledInterrupt}, /* irq7 */
{0x82, NonHandledInterrupt}, /* irq8 */
{0x82, NonHandledInterrupt}, /* irq9 */
{0x82, NonHandledInterrupt}, /* irq10 */
{0x82, NonHandledInterrupt}, /* irq11 */
{0x82, NonHandledInterrupt}, /* irq12 */
{0x82, NonHandledInterrupt}, /* irq13 */
{0x82, NonHandledInterrupt}, /* irq14 */
{0x82, NonHandledInterrupt}, /* irq15 */
{0x82, NonHandledInterrupt}, /* irq16 */
{0x82, NonHandledInterrupt}, /* irq17 */
{0x82, NonHandledInterrupt}, /* irq18 */
{0x82, NonHandledInterrupt}, /* irq19 */
{0x82, NonHandledInterrupt}, /* irq20 */
{0x82, NonHandledInterrupt}, /* irq21 */
{0x82, NonHandledInterrupt}, /* irq22 */
{0x82, NonHandledInterrupt}, /* irq23 */
{0x82, NonHandledInterrupt}, /* irq24 */
{0x82, NonHandledInterrupt}, /* irq25 */
{0x82, NonHandledInterrupt}, /* irq26 */
{0x82, NonHandledInterrupt}, /* irq27 */
{0x82, NonHandledInterrupt}, /* irq28 */
{0x82, NonHandledInterrupt}, /* irq29 */
};
代码的添加和终端的映射是一一对应的。
//LED控制 输入1 点亮; 0 熄灭;
void Driver_LEDCont(bool flag)
{
static bool startflag = 1;
if(startflag)
{
PD_DDR |= SETBIT1;
PA_DDR |= SETBIT1;
PA_DDR |= SETBIT2;
PD_DDR |= SETBIT5;
PD_DDR |= SETBIT3;
PD_CR1 |= SETBIT1;
PA_CR1 |= SETBIT1;
PA_CR1 |= SETBIT2;
PD_CR1 |= SETBIT5;
PD_CR1 |= SETBIT3;
startflag = 0;
}
if(flag)
{
PD_ODR &= CLRBIT1;
PA_ODR &= CLRBIT1;
PA_ODR &= CLRBIT2;
PD_ODR &= CLRBIT5;
PD_ODR &= CLRBIT3;
}
else
{
PD_ODR |= SETBIT1;
PA_ODR |= SETBIT1;
PA_ODR |= SETBIT2;
PD_ODR |= SETBIT5;
PD_ODR |= SETBIT3;
}
}
main()
{
//程序启动STM8默认以HSI分频2M执行速率进行
Driver_LEDCont(1);
//开启外部中断
Driver_ExtIntOn();
//开总中断
_asm("rim");
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//在stm8_interrupt_vector.c文件中 写入中断接入函数Driver_EXI_Interrupt
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//等待中断
while(1)
{
static u16 Timer = 0;
if(ExiFlag)
{
Timer = 0xfff;
ExiFlag = False;
}
if(!(PA_IDR&CHSBIT4))
Timer = 0xfff;
if(Timer)
{
if(!--Timer)
{
static bool flag = 0;
//循环控制LED灯状态
flag = !flag;
Driver_LEDCont(flag);
}
}
}
}
上一篇:STM8单步调试的问题
下一篇:STM8的数据@near @tiny定义
推荐阅读最新更新时间:2024-03-16 16:12
设计资源 培训 开发板 精华推荐
- PC产业驶入创新超车道,英特尔蓉城撬动AI新引擎
- 与产业聚力共赢,英特尔举行新质生产力技术生态大会
- “新”享5G-A万兆网络前沿体验 高通携手产业伙伴亮相第二届链博会
- 英飞凌推出符合ASIL-D标准的新型汽车制动系统和电动助力转向系统三相栅极驱动器 IC
- 南芯科技推出80V升降压转换器,持续深耕工业储能市场
- 法雷奥与罗姆联合开发新一代功率电子领域
- 贸泽电子开售能为电动汽车牵引逆变器提供可扩展性能的 英飞凌HybridPACK Drive G2模块
- 德州仪器新型 MCU 可实现边缘 AI 和先进的实时控制, 提高系统效率、安全性和可持续性
- 瑞萨推出高性能四核应用处理器, 增强工业以太网与多轴电机控制解决方案阵容
- 研华全新模块化电脑SOM-6833助力5G路测设备升级