cllunlu
Member level 4
Hi Everyone,
I have Project that two UHF antenna (they send wiegand data to microcontroller via RB4-RB7 IOC)
I have already read wiegand data from antenna succesfully.
Now I have to do when data is received and if readed tag is known, relay will be on for 2 second and after that will be off, and microcontroller wont be any process for before readed tag in 10 second. if readed tag is not known microcontroller wont do any process.
I write code but have some mistakes. Anyone help?
I am using pic18f24k50 and 12 Mhz external crystal.
I couldnt Show some functions to readability.
I have Project that two UHF antenna (they send wiegand data to microcontroller via RB4-RB7 IOC)
I have already read wiegand data from antenna succesfully.
Now I have to do when data is received and if readed tag is known, relay will be on for 2 second and after that will be off, and microcontroller wont be any process for before readed tag in 10 second. if readed tag is not known microcontroller wont do any process.
I write code but have some mistakes. Anyone help?
I am using pic18f24k50 and 12 Mhz external crystal.
I couldnt Show some functions to readability.
Code:
void start_timer1()
{
timer1=0;
TMR0IE_bit=1;
}
void interrupt(void)
{
if(IOCIF_bit) // RB4-RB7 interrupt
{
IOCIE_bit = 0;
IOCIF_bit = 0;
if(!RB4_bit) // Data is received from RB4
{
wiegand[wCounter]='0';
wCounter++;
while(RB4_bit==0);
}
else if(!RB5_bit) // Data is received from RB5
{
wiegand[wCounter]='1';
wCounter++;
while(RB5_bit==0);
}
if(wCounter==26)
{
finish=1;
}
else
{
IOCIE_bit = 1;
}
}
if (TMR0IF_bit)
{
TMR0IF_bit = 0; // timer calculation from mikroElektronika software and it is true.
TMR0H = 0x48; // microcontroller is pic18f24k50, external crystal 12Mhz, 1 second timer interrupt
TMR0L = 0xE5;
timer1++;
}
}
unsigned short control_last_tag()
{
unsigned short result=0;
if(finish==1)
{
if((receivedTag[0]==lastTag1[0]) && (receivedTag[1]== lastTag1[1]) && (receivedTag[2]==lastTag1[2]))
{
if(timer1==0)
result=1;
}
else
{
result=1;
}
}
else if(finish==2)
{
if((receivedTag[0]==lastTag2[0]) && (receivedTag[1]== lastTag2[1]) && (receivedTag[2]==lastTag2[2]))
{
if(timer2==0)
result=1;
}
else
{
result=1;
}
}
return result;
}
void isRec_tag()
{
unsigned short isRec=0;
unsigned int currentAddr=startAddr;
while(currentAddr<=finishAddr) // control from start adress to finish address in eeprom, tag data is find?
{
currentAddr++;
if(EEPROM_Read(currentAddr)==receivedTag[0])
{
currentAddr++;
if(EEPROM_Read(currentAddr)==receivedTag[1])
{
currentAddr++;
if(EEPROM_Read(currentAddr)==receivedTag[2]) // Tag data is find.
{
if(control_last_tag()==1) // Control last readed tag. Microcontroller wont any process, if readed tag is read in 10 second again.
{
if(finish==1)
{
RELAY1=ON;
start_timer1();
}
if(finish==2)
{
RELAY2=ON;
start_timer2();
}
write_last_tag(); // Update last readed tag
}
}
else
currentAddr+=1;
}
else
currentAddr+=2;
}
else
currentAddr+=3;
}
}
void main()
{
init();
while(1)
{
LED0 = ~LED0;
Delay_ms(500);
if(finish>0) // if all of tag data is received. If finish is 1, antenna-1 send data
{ // If finish is 2, antenna-2 send data
wCounter=0;
calc_tag_data(); // Calculate received wiegand data to tag id
isRec_tag(); // Control that readed tag is known?
finish=0;
IOCIE_bit = 1; // IOC interrupt is on;
}
if(timer1==2) // if timer is value 2 second
RELAY1=OFF;
if(timer1==10) // if timer is value 10 second
{
timer1=0;
TMR0IE_bit=0;
}
}
}
void init()
{
/******* IOC RB4-RB7 interrupt ***************/
IOCIE_bit = 1;
PEIE_bit = 1;
GIE_bit = 1;
IOCB4_bit = 1;
IOCB5_bit = 1;
IOCIF_bit = 0;
/*********************************************/
/************* TIMER1 ************************/
T0CON = 0x85;
TMR0H = 0x48;
TMR0L = 0xE5;
}