1、PIC单片机开发环境
使用MPLAB IDE,编译套件使用MPLAB C30
入门熟悉可以参考官方手册 dsPIC LANGUAGE TOOLS GETTING STARTED,里面详细描述了软件安装、工程新建、编译、调试等,简单易懂。
2、中断函数编写
示例代码中的中断函数如下
/****** START OF INTERRUPT SERVICE ROUTINES *********/
/* Replace the interrupt function names with the */
/* appropriate names depending on interrupt source. */
/* The names of various interrupt functions for */
/* each device are defined in the linker script. */
/* Interrupt Service Routine 1 */
/* No fast context save, and no variables stacked */
void __attribute__((interrupt, auto_psv)) _ADCInterrupt(void)
{
/* Interrupt Service Routine code goes here */
}
那么编译器是如何区分是什么中断呢,上述的是ADC的中断,那么_ADCInterrut 是在哪里定义的呢?
注释里指明了各种中断函数名在链接脚本中有定义,那么我们就可以从链接脚本中寻找我们要的中断函数名。
(链接脚本目录:MPLAB安装目录下 MPLAB C30\support\gld\xxx.gld,根据使用的器件型号选择对应的链接文件)
另外也可以从官方帮助手册中找到对应的中断向量表,Non-SMPS dsPIC30F DSCs Interrupt Vectors
3、时钟配置
方法1:通过编程配置
方法2:通过器件配置寄存器配置,MPLAB IDE中的Configure菜单中选定Configuration Bits,进行选择即可