嗨,谢谢大家。“Kdt…尝试一个PORTB IOC引脚为您的触发输入边缘。P.S.为什么你使用“大规模”PIC18F45 K20这样一个简单的任务?我在波尔图尝试过,效果不错。我想通过使用PoTa来做同样的事情,但是在仔细阅读数据表之后,我想我不能。我使用PIC18F45 K20,因为我只是张贴了这部分代码,因为我遇到了中断问题,但是最后使用它有点复杂,这个PIC有广告。低功耗的优势!我的主要问题是我的所有条目都是物理连接到波尔塔和一个外部系统,我用一个方形信号驱动它们,它们可以从10秒到50ms不等。在我的原始代码(不中断)下,我检测到上升沿,并且执行我的条件。但是当采集系统是快或慢的时候,我错过了一些上升的边缘。这就是为什么我有使用中断的想法,所以只有当我检测到上升的边缘将不再做别的事情时,我才会执行我的条件。问题是,没有改变硬件的方法,有没有办法做到这一点?这里是我的代码,没有中断:空main(空隙){/*初始化模块,Mat Eyres和HordLoges *//HORLoges HalyStuleSyIn();//GPIO HalthGPIOION();/*变量Loals*/unChar char MeM1=0;而(1){MeM1= PoTa;S(5);//如果这个延迟太长或太短,我会错过上升沿…如果(波尔塔)!= MEM1){()PARABABIT.RA0&(MEM1和AM&0X01)PARABABIT.RA1&(MEM1和AM&0x02)PARABABIT.RA2&(MEM1和AM&0X04)PrababITS.RA3&(MEM1和AM&0x08)PrababITS.RA4&(MEM1和AM&0x10)Prababist.Ra&&;(MEM1和A&0x20)){PrdBoSt.RD0=1;//首脉冲重置端口;RC1=1;PrdBoSt.RD7=1;PrdBoSt.Rd3=1;PrtCbStudio。RC3=1;PrdButs.RD5=1;=0;//鳍脉冲重置端口;RC1=0;PrdBoTS。RD7=0;PrdBosits。RD3=0;PrtCbStudio。RC3=0;PrdBosits。RD5=0;γ-DelayyMS(10);} PtdBrd.Rd1=!PARABABIT.RA0&(MEM1和AM&0X01);/ /首次脉冲PORTCITS。RC0=!PARABABIT.RA1&(MEM1和AM&0x02);PARABABIT.RA2&(MEM1和AM&0X04);PARABABIT.RA3&(MEM1和AM&0x08);PARABABIT.RA4&(MEM1和AM&0x10);PARABABIT.RA5&(MEM1和AM&0X20);γ-DelayyMS(20);PORTD=0;/ /鳍去脉冲POTC=0;}
以上来自于百度翻译
以下为原文
Hi , thanks everyone.
"Kdt .... try one of the PortB IOC pins for your trigger input edges.
P.S. why are you using the "MASSIVE" PIC18F45K20 for such a simple task ?"
I tried this on PortB and it is working fine. i wanted to do the same thing by using PortA, but after reading carefully the datasheet i think i can't.
i am using the PIC18F45K20 because i posted just this part of the code because i am having problems with interruption but for the end using it is a little bit more complex and this PIC has the advantage to be low power!
My main issue is that all my entries are physically connected to PortA and by an external system, i am driving them with a square signal which can vary from 10µs to 50ms.
On my original code(without interruption) i detect a rising edge and i execute my conditions. but when the acquisition system is quick or slow i miss some rising edge.
That's why i had the idea of using interruptions, so that i will execute my condition only when i detect the rising edge will do nothing else before.
the problem is , is there a way to do this without changing my hardware?
Here is my code without interruption :
void main ( void)
{
/* Initialisations des modules matériels et des horloges */
// Horloges
HAL_SYSTEM_Init();
// GPIO
HAL_GPIO_Init();
/* Variables locales*/
unsigned char mem1 =0;
while(1)
{
mem1 = PORTA;
__delay_ms(5); //if this delay is too long or too short i miss rising edges....
if (PORTA!=mem1)
{
if ( (!PORTAbits.RA0 && (mem1 && 0x01))||
(!PORTAbits.RA1 && (mem1 && 0x02))||
(!PORTAbits.RA2 && (mem1 && 0x04))||
(!PORTAbits.RA3 && (mem1 && 0x08))||
(!PORTAbits.RA4 && (mem1 && 0x10))||
(!PORTAbits.RA5 && (mem1 && 0x20))
)
{
PORTDbits.RD0=1;//debut pulse reset
PORTCbits.RC1=1;
PORTDbits.RD7=1;
PORTDbits.RD3=1;
PORTCbits.RC3=1;
PORTDbits.RD5=1;
__delay_ms(20);
PORTDbits.RD0=0;// fin pulse reset
PORTCbits.RC1=0;
PORTDbits.RD7=0;
PORTDbits.RD3=0;
PORTCbits.RC3=0;
PORTDbits.RD5=0;
__delay_ms(10);
}
PORTDbits.RD1= !PORTAbits.RA0 && (mem1 && 0x01); // debut pulse
PORTCbits.RC0= !PORTAbits.RA1 && (mem1 && 0x02);
PORTDbits.RD2= !PORTAbits.RA2 && (mem1 && 0x04);
PORTDbits.RD4= !PORTAbits.RA3 && (mem1 && 0x08);
PORTCbits.RC2= !PORTAbits.RA4 && (mem1 && 0x10);
PORTDbits.RD6= !PORTAbits.RA5 && (mem1 && 0x20);
__delay_ms(20);
PORTD=0; // fin de pulse
PORTC=0;
}