helloleong
New Member
Hi, im writing c-code to receive the 26 bits wiegand data in pulse wave form. PIC16F272, MPLAB IDE v8.50, MPLAB in circuit debugger ICD2, Hi-Tech ANSI C Compiler. And im using the PORTB interrupt to detect the card as the code below.
RB5 is D0
RB4 is D1
The problem was when I sawp the card the module did generate 26 bits, but the PIC software only could capture until 6 bits. Im using the watch window and run to watch the bits. Something weird happen, when i change the EMCardNo to unsigned long int the counter at watch window didnot change at all but the EMCardNo did change its value, but the value was is not consistent for the same card.
And when i change to unsigned char, the EMCardNo and counter did change its value but not consistent also.
Did anybody face this problem before? Does it got to do with the c-compiler library? And how can i check on the simulator timing for the if condition to run how many sec?
Thanks everybody.
Code:
unsigned long int EMCardNo;
void interrupt isr(void)
{
CLRWDT(); //Clear watchdog timer
//----- PORTB Interrupt -----//
if (RBIE && RBIF && 0x30) //Mask off other bits
{
temp=PORTB; //Read PORTB
temp&=0x30; //Leave only the necessary bit
if(temp && 0x20) //D0=0
{
EMCardNo=0;
EMCardNo=EMCardNo<<1;
EMCardNoCounter++;
}
else //D1=0
{
EMCardNo=1;
EMCardNo=EMCardNo<<1;
EMCardNoCounter++;
}
RBIF = 0; //Clear interrupt flag
Delay_Routine(6); //Wait until pulse end 50usec
}
}
RB5 is D0
RB4 is D1
The problem was when I sawp the card the module did generate 26 bits, but the PIC software only could capture until 6 bits. Im using the watch window and run to watch the bits. Something weird happen, when i change the EMCardNo to unsigned long int the counter at watch window didnot change at all but the EMCardNo did change its value, but the value was is not consistent for the same card.
And when i change to unsigned char, the EMCardNo and counter did change its value but not consistent also.
Did anybody face this problem before? Does it got to do with the c-compiler library? And how can i check on the simulator timing for the if condition to run how many sec?
Thanks everybody.