帮我看看HLVD模块的使用

[复制链接]
5047|2
 楼主| hahahaluo 发表于 2008-1-29 10:38 | 显示全部楼层 |阅读模式
pic18f2480,mcc18。<br /><br />void&nbsp;HandlerHigh&nbsp;()<br />{<br />//HLVD中断--------------------------------<br />if(PIR2bits.HLVDIF&nbsp;==&nbsp;1&nbsp;&&&nbsp;hlvd_intFlag&nbsp;==&nbsp;0)<br />&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;PIR2bits.HLVDIF&nbsp;=&nbsp;0;<br />&nbsp;&nbsp;&nbsp;&nbsp;hlvd_intFlag&nbsp;=&nbsp;1;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />}<br /><br />void&nbsp;init_hlvd(void)<br />{<br />TRISAbits.TRISA5&nbsp;=&nbsp;1;&nbsp;//设定RA5为输入<br /><br />HLVDCONbits.HLVDEN&nbsp;=&nbsp;0;//高低电压检测使能关闭<br /><br />HLVDCONbits.HLVDL3&nbsp;=&nbsp;1;//高低电压检测门限值<br />HLVDCONbits.HLVDL2&nbsp;=&nbsp;1;//<br />HLVDCONbits.HLVDL1&nbsp;=&nbsp;1;//<br />HLVDCONbits.HLVDL0&nbsp;=&nbsp;0;//<br /><br />HLVDCONbits.VDIRMAG&nbsp;=&nbsp;0;//电压跌落时,事件发生<br /><br />HLVDCONbits.HLVDEN&nbsp;=&nbsp;1;//高低电压检测使能打开<br /><br />INTCONbits.GIE&nbsp;=&nbsp;1;//全局中断打开<br />INTCONbits.PEIE&nbsp;=&nbsp;1;//外围设备中断打开<br /><br />IPR2bits.HLVDIP&nbsp;=&nbsp;1;//HLVD使用高中断<br />PIE2bits.HLVDIE&nbsp;=&nbsp;1;//HLVD中断打开,<br />PIR2bits.HLVDIF&nbsp;=&nbsp;0;//HLVD中断溢出标志位<br /><br />}<br /><br />void&nbsp;main(void)&nbsp;<br />{&nbsp;<br />init_hlvd();<br />for(;;)<br />&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;if(hlvd_intFlag)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;LATCbits.LATC2&nbsp;=&nbsp;!LATCbits.LATC2;&nbsp;//LED2闪烁<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;while(!HLVDCONbits.IVRST);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;hlvd_intFlag&nbsp;=&nbsp;0;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;delay(200);//约450ms<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />}&nbsp;<br /><br />程序过程:<br />初始化后,如果电压低于4.48-4.69V,进入中断,led2闪一次。<br />1.mcu电源电压5V,led2不闪。<br />2.mcu电源电压4.3v,led2不闪。<br />3.将HLVDL3:0=1111,mcu电源4.5V,RA5引脚5v,led2不闪,(RA5引脚3V,led2不闪)<br /><br />弄了好久,咋都进不了中断,请教版主。
499767 发表于 2008-1-30 17:45 | 显示全部楼层

是完整的中断程序么?

具体程序内容没有细看如果一直都不进不了中断,不知道你在前面是否有配置过程, 给你个例成看看,<br />//================================================================================<br />//中断入口设置。低优先级入口<br />//================================================================================<br />#pragma&nbsp;code&nbsp;low_vector=0x18&nbsp;&nbsp;&nbsp;//用#pragma伪指令定义一个名字叫low_vector的段,并把这个段放到0x18地址起始的代码空间<br />void&nbsp;interrupt_at_low_vector(void)&nbsp;//低优先级中断向量函数<br />{<br />&nbsp;&nbsp;_asm&nbsp;GOTO&nbsp;low_isr&nbsp;_endasm&nbsp;&nbsp;//内嵌汇编指令<br />}<br />#pragma&nbsp;code&nbsp;//这里不是多余的,它是告诉连接器回到默认的代码段,如果不加的话,连接器就会傻傻地把后面的代码紧跟着上面的代码一直放下去。而LKR文件里定义了向量区最多到0x29地址,所以如果没加此行通常会报错<br />#pragma&nbsp;interruptlow&nbsp;low_isr&nbsp;&nbsp;&nbsp;&nbsp;//这里使用interruptlow这个关键词来声明low_isr这个函数是低优先级中断服务函数,用了关键词后,这个函数将会由编译器自动产生基本的现场保护,并且这个函数的返回将是使用RETFIE返回的<br />//===========================================================<br />//函数:<br />//函数功能:中断函数<br />//===========================================================<br />void&nbsp;low_isr&nbsp;(void)<br />&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;if(PIR1bits.RC1IF==1)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;USART1_receive_int();<br />&nbsp;}
 楼主| hahahaluo 发表于 2008-1-31 14:06 | 显示全部楼层

感谢499767,

感谢499767,单独使用芯片的串口中断,这个能够进入,只是低电压检测的HLVD中断进不去,<br /><br />这些语句,程序中是有的。<br />#pragma&nbsp;code&nbsp;VectorHigh&nbsp;=&nbsp;0x08<br />void&nbsp;VectorHigh&nbsp;(void)<br />{<br />&nbsp;&nbsp;_asm<br />&nbsp;&nbsp;&nbsp;&nbsp;goto&nbsp;HandlerHigh&nbsp;//jump&nbsp;to&nbsp;interrupt&nbsp;routine<br />&nbsp;&nbsp;_endasm<br />}<br />#pragma&nbsp;code<br /><br />#pragma&nbsp;interrupt&nbsp;HandlerHigh//用于接收的高中断,<br />void&nbsp;HandlerHigh&nbsp;()<br />{<br />}<br /><br />最后问问499767,你有没有HLVD中断的例程?让我参考参考找找原因
您需要登录后才可以回帖 登录 | 注册

本版积分规则

15

主题

41

帖子

0

粉丝
快速回复 在线客服 返回列表 返回顶部