我选用PIC12F615设计一款分频电路,想使用InterruptOnChange中断来检测输入信号的变化,
现输入信号是0-5V方波,问题是检测不到输入变化,、请各位分析下我的Firmware有什么问题。谢谢void system_init01(void)
{
ANSELbits.ANS = 0; //
TRISIObits.TRISIO2 = 1; // Input
TRISIObits.TRISIO5 = 1; // Input
TRISIObits.TRISIO4 = 1; // Input
TRISIObits.TRISIO0 = 0; // Output
TRISIObits.TRISIO1 = 0; // Output
WPUbits.WPU0 = 1; // 1 = Pull-up enabled
WPUbits.WPU1 = 1; // 1 = Pull-up enabled
WPUbits.WPU2 = 1; // 1 = Pull-up enabled
WPUbits.WPU4 = 1; // 1 = Pull-up enabled
WPUbits.WPU5 = 1; // 1 = Pull-up enabled
IOCbits.IOC0 = 1; // 1 = Interrupt-on-change enabled
IOCbits.IOC1 = 1; // 1 = Interrupt-on-change enabled
INTCONbits.GPIE = 1; // 1 = Enables the GPIO change interrupt
INTCONbits.GPIF = 0; // 1 = When at least one of the GPIO <5:0> pins changed state (must be cleared in software)
}
bit Roll_IOC_Edge_Changed(void)
{
if(INTCONbits.GPIF == 1)
{
ioc_edge_count++;
ioc_edge_count %= (unsigned int)(pulse_per_cycle*4);
INTCONbits.GPIF = 0;
return 1;
}
else
{
return 0;
}
}
//-----------
void main(void) {
system_init01();
GPIObits.GP0 = 0;
GPIObits.GP1 = 0;
INTCONbits.GIE = 1; //1 = Enables all unmasked interrupts
while(1)
{
#ifdef NON_DIVIDE
GPIObits.GP0 = GPIObits.GP2;
GPIObits.GP1 = GPIObits.GP5;
#else
if(Roll_IOC_Edge_Changed())
{
//if(ioc_edge_count < Encoder_Cycle_Second)
if(ioc_edge_count < 8)
{
GPIObits.GP0 = 0; // A phase
}
else
{
GPIObits.GP0 = 1; // A phase
}
//if((ioc_edge_count < Encoder_Cycle_Third) && (ioc_edge_count >= Encoder_Cycle_First))
if((ioc_edge_count < 24) && (ioc_edge_count >= 16))
{
GPIObits.GP1 = 0; // B phase
}
else
{
GPIObits.GP1 = 1; // B phase
}
}
#endif
}
}
|