Mhadhu
Junior Member level 2
- Joined
- Jan 3, 2013
- Messages
- 21
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,281
- Activity points
- 1,461
I have interfaced my PIC with RFID. I have to switch off the rfid whenever a valid ID tag is exposed. I have done everything right. But my program works only on certain power on's properly. Or sometimes it stops working in the middle of checking. I mean saying that it stops working when u expose the card more than 5 to 10 times. Or if i switch off and on the power it works only once. Can anyone check my code and tell where am wrong??
#include <p18f97j60.h>
#include<delays.h>
#include<usart.h>
#pragma config XINST=OFF
#pragma config WDT=OFF, FOSC2=ON, FOSC=HSPLL, ETHLED=OFF
#pragma interrupt interrupthandler
void interrupthandler();
void function();
unsigned char a[10];
unsigned char ucCharBuff[10];
int i = 0;
int j = 0;
void main(void) {
OSCTUNE = 0x40;
TRISG = 0;
PORTG = 0X40;
Open1USART(
USART_TX_INT_ON & //Enabling USART
USART_RX_INT_ON &
USART_ASYNCH_MODE &
USART_EIGHT_BIT &
USART_CONT_RX &
USART_BRGH_LOW,
67);
RCONbits.IPEN = 0;
INTCONbits.GIE = 1; //Enabling interrupts
INTCONbits.PEIE = 1;
PIE1bits.RC1IE = 1;
// RCSTA1bits.CREN = 0;
Delay100TCYx(100000);
ucCharBuff[0] = 0x34; // rfid tag code is stored in ucCharBuff.
ucCharBuff[1] = 0x32;
ucCharBuff[2] = 0x30;
ucCharBuff[3] = 0x30;
ucCharBuff[4] = 0x41;
ucCharBuff[5] = 0x34;
ucCharBuff[6] = 0x33;
ucCharBuff[7] = 0x35;
ucCharBuff[8] = 0x42;
ucCharBuff[9] = 0x31;
// while (1) {
// // PORTG= 0X40;
// }
Close1USART();
}
#pragma code interruptvectorhigh=0x08
void interruptvector(void) //interrupt vector
{
_asm
goto interrupthandler
_endasm
}
#pragma code
//interrupt routine
#pragma interrupt interrupthandler
void interrupthandler() {
if (PIR1bits.RC1IF == 1) {
PIR1bits.RC1IF = 0;
for (i = 0; i < 10; i++) {
a = RCREG1;
}
for (j = 0; j < 10; j++) {
if (a[j] == ucCharBuff[j])
function();
}
}
}
void function() {
PORTG = 0X00;
for (j = 0; j < 15; j++) {
Delay10KTCYx(1000);
}
PORTG = 0X40;
PIE1bits.RC1IE = 0;
}
#include <p18f97j60.h>
#include<delays.h>
#include<usart.h>
#pragma config XINST=OFF
#pragma config WDT=OFF, FOSC2=ON, FOSC=HSPLL, ETHLED=OFF
#pragma interrupt interrupthandler
void interrupthandler();
void function();
unsigned char a[10];
unsigned char ucCharBuff[10];
int i = 0;
int j = 0;
void main(void) {
OSCTUNE = 0x40;
TRISG = 0;
PORTG = 0X40;
Open1USART(
USART_TX_INT_ON & //Enabling USART
USART_RX_INT_ON &
USART_ASYNCH_MODE &
USART_EIGHT_BIT &
USART_CONT_RX &
USART_BRGH_LOW,
67);
RCONbits.IPEN = 0;
INTCONbits.GIE = 1; //Enabling interrupts
INTCONbits.PEIE = 1;
PIE1bits.RC1IE = 1;
// RCSTA1bits.CREN = 0;
Delay100TCYx(100000);
ucCharBuff[0] = 0x34; // rfid tag code is stored in ucCharBuff.
ucCharBuff[1] = 0x32;
ucCharBuff[2] = 0x30;
ucCharBuff[3] = 0x30;
ucCharBuff[4] = 0x41;
ucCharBuff[5] = 0x34;
ucCharBuff[6] = 0x33;
ucCharBuff[7] = 0x35;
ucCharBuff[8] = 0x42;
ucCharBuff[9] = 0x31;
// while (1) {
// // PORTG= 0X40;
// }
Close1USART();
}
#pragma code interruptvectorhigh=0x08
void interruptvector(void) //interrupt vector
{
_asm
goto interrupthandler
_endasm
}
#pragma code
//interrupt routine
#pragma interrupt interrupthandler
void interrupthandler() {
if (PIR1bits.RC1IF == 1) {
PIR1bits.RC1IF = 0;
for (i = 0; i < 10; i++) {
a = RCREG1;
}
for (j = 0; j < 10; j++) {
if (a[j] == ucCharBuff[j])
function();
}
}
}
void function() {
PORTG = 0X00;
for (j = 0; j < 15; j++) {
Delay10KTCYx(1000);
}
PORTG = 0X40;
PIE1bits.RC1IE = 0;
}