1 main.c文件代码:
/* ======================================== * * Copyright YOUR COMPANY, THE YEAR * All Rights Reserved * UNPUBLISHED, LICENSED SOFTWARE. * * CONFIDENTIAL AND PROPRIETARY INFORMATION * WHICH IS THE PROPERTY OF your company. * 说明:PSoc4自带PWM模块测试引脚中断输入功能 * 1. 中断输入引脚 ----- P0.7 * 2. PWM输出引脚 ----- P2.7 * 3. LED指示引脚 ----- P0.2 * * * 注:如果工程编译报错请用工程目录下"如果工程 * 报错请用该文档内容替换INT_PinIOin.c中所有内 * 容"文件按文件名要求替换指定文件内容. * ======================================== */ #include int main() { /* Place your initialization/startup code here (e.g. MyInst_Start()) */ INT_PinIOin_Start(); PWM_1_Start(); CyGlobalIntEnable; /* CyGlobalIntEnable; */ /* Uncomment this line to enable global interrupts. */ for(;;) { /* Place your application code here. */ } } /* [] END OF FILE */
2. ISR函数
/******************************************************************************* * Function Name: INT_PinIOin_Interrupt ******************************************************************************** * * Summary: * The default Interrupt Service Routine for INT_PinIOin. * * Add custom code between the coments to keep the next version of this file * from over writting your code. * * Parameters: * None * * Return: * None * *******************************************************************************/ CY_ISR(INT_PinIOin_Interrupt) { /* Place your Interrupt code here. */ /* `#START INT_PinIOin_Interrupt` */ if(Dig_Out_Read()) { INTOUT_Write(0); } else { INTOUT_Write(1); } INT_PinIOin_ClearPending(); INT_in_ClearInterrupt(); /* `#END` */ }
接好外部的跳线后,运行该程序的效果是绿色LED灯闪烁,附上工程代码如下:
——回复可见内容——