PIC12F1571 RA0-RA2做输入口功能不正常;做输出口功能。软件用MPLAB X IDE V5.15,有配置外设触发。void main(void)
{
OPTION_REG=0X47;
ANSELA=0x00;
INTCON=0x00; //中断控制寄存器
PORTA=0x00; //1100 1111
WPUA =0xFF;
TRISA=0xCF; //1100 1111=RA0-3输入=1;RA4-5输出=0
OpenWinFB=0;
CloseWinFB=0;
ADIE=1; //1 = 允许ADC 中断
TMR1GIE=1; //1 = 允许Timer1 门控采集中断
TMR1IE=1; //1 = 允许Timer1 上溢中断
INTCONbits.IOCIE = 1; //1 = 允许电平变化中断
INTCONbits.IOCIF = 1; //1 = 至少有一个电平变化中断引脚改变了状态
INTCONbits.PEIE = 1; //外设中断允许
INTCONbits.INTE = 1; //允许INT 外部中断
INTCONbits.GIE = 1; //系统中断允许
TMR0IE = 1; //TMR0使能
while (1)
{
// ADC_PowerForward = get_adc_contiue(0);//电源正方向取样AN0
// ADC_PowerReverse = get_adc_contiue(1);//电源反方向取样AN1
NOP();
NOP();
if(RA0)//判断电压的方向=正方向
{
PowerForwardFlag=1;
OpenWinFB=1;
}
if( RA1 )//判断电压的方向=正方向
{
PowerReverseFlag=1;
CloseWinFB=1;
}
/*
if( (ADC_PowerForward > 150 ) && ( ADC_PowerReverse < 8 ) )//判断电压的方向=正方向
{
__delay_ms(5);
if(ADC_PowerForward > 150 )
{
PowerForwardFlag=1;
OpenWinFB=1;
}
}
else{ PowerForwardFlag=0;OpenWinFB=0;}
if( (ADC_PowerReverse > 150 ) && ( ADC_PowerForward < 8 ) )//判断电压的方向=正方向
{
__delay_ms(5);
if(ADC_PowerReverse > 150 )
{
PowerReverseFlag=1;
CloseWinFB=1;
}
}
else{PowerReverseFlag=0; CloseWinFB=0;}
* /
/*
if(PowerForwardFlag)//正方向
{
OpenWinFB=1;
}
if(PowerReverseFlag)//反方向
{
CloseWinFB=1;
}
*/
}
} |