Mhadhu
Junior Member level 2
My code is working properly except in the transmission of green code. I have placed the authorised ID tag code in ucCharBuff[0] to ucCharBuff[9] and green code to be transmitted to rfid for 4 cycles in ucCharBuff[10] to ucCharBuff[19]. Whenever authorised card is exposed the green code has to be transmitted and the door has to be opened. Everything is working fine except the green code is not able to be transmitted.
Code:
Code:
Code:
#include <p18f97j60.h>
#include<delays.h>
#include<usart.h>
#pragma config XINST=OFF
#pragma config WDT=OFF, FOSC2=ON, FOSC=HSPLL, ETHLED=OFF
#pragma config WDTPS=256
#pragma interrupt interrupthandler
void interrupthandler();
void function();
void data();
unsigned char a[10];
unsigned char ucCharBuff[20];
unsigned char ucaBuffer[10];
int i = 0;
int j = 0;
int b;
int k = 0;
void delay();
void main(void) {
OSCTUNE = 0x40;
TRISG = 0;
PORTG = 0X40;
TRISC = 0X04;
TRISJ = 0;
PORTJ = 0X00;
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;
ADCON1 = 0X0F; // dISABLING ANALOG INPUTS
CMCON = 0X07; //disabling comparator
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;
ucCharBuff[10] = 0x02; //green code
ucCharBuff[11] = 0x90;
ucCharBuff[12] = 0x00;
ucCharBuff[13] = 0x25;
ucCharBuff[14] = 0x04;
ucCharBuff[15] = 0x00;
ucCharBuff[16] = 0x02;
ucCharBuff[17] = 0x01;
ucCharBuff[18] = 0x04;
ucCharBuff[19] = 0xb6;
while (1) {
}
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[i] = RCREG1;
}
for (j = 0; j < 9; j++) {
if (a[j] == ucCharBuff[j]) {
function();
}
}
}
}
void function() {
for (i = 10; i < 19; i++) {
PORTJ=0X01;
while (!(TXSTA1bits.TRMT));
PORTJ=0X02;
TXREG1 = ucCharBuff[i];
}
for (i = 0; i < 10; i++) {
delay();
}
Delay100TCYx(1000);
PORTG = 0X00;
for (i = 0; i < 20; i++) {
delay();
}
PORTG = 0X40;
WDTCONbits.SWDTEN = 1;
for (j = 0; j < 100; j++) {
Delay10KTCYx(1000);
}
PIE1bits.RC1IE = 0;
WDTCONbits.SWDTEN = 0;
}
void delay() {
Delay10KTCYx(1000);
}
Last edited by a moderator: