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
#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);
}
TXSTA1bits.TRMT = 0;
TXREG1 = ucCharBuff[i];
#pragma code high_vector=0x08
void interrupt_at_high_vector(void) //interrupt vector
{
_asm
goto high_isr
_endasm
}
#pragma code //interrupt routine
#pragma interrupt high_isr
void high_isr()
{
INTCONbits.GIE = 0; //Disabling interrupts
if (PIR1bits.RC1IF == 1)
{
for (i = 0; i < 10; i++)
{
a[i] = RCREG1;
}
}
PIE1bits.RC1IE = 1;
PIR1bits.RC1IF = 0;
}
#include<p18f97j60.h>
#include<usart.h>
#include<delays.h>
#pragma config XINST=OFF
#pragma config WDT=OFF, FOSC2=ON, FOSC=HSPLL, ETHLED=OFF, STVR = ON
#pragma interrupt high_isr
#pragma config WDTPS=128
unsigned int i;
volatile unsigned char a[10];
volatile unsigned int m;
unsigned char ucCharBuff[10];
void function();
void high_isr(void);
#pragma code high_vector=0x08
void interrupt_at_high_vector(void) //interrupt vector
{
_asm
goto high_isr
_endasm
}
#pragma code //interrupt routine
#pragma interrupt high_isr
void high_isr() {
if (PIR1bits.RC1IF == 1) {
PORTJ = 0X01;
[B] INTCONbits.PEIE = 0;[/B]
for (i = 0; i < 10; i++) {
a[i] = RCREG1;
}
Delay10KTCYx(10000);
Delay10KTCYx(10000);
Delay10KTCYx(10000);
Delay10KTCYx(10000);
Delay10KTCYx(10000);
PIR1bits.RC1IF = 0;
PORTJ = 0X00;
m = 1;
}
}
void main()
{
OSCTUNE = 0X40;
TRISJ = 0;
PORTJ = 0X00;
TRISG = 0;
PORTG = 0X00;
RCONbits.IPEN = 0;
PIE1bits.RCIE = 1;
[B] INTCON = 0XC0;[/B]
Open1USART(
USART_TX_INT_ON & //Enabling USART
USART_RX_INT_ON &
USART_ASYNCH_MODE &
USART_EIGHT_BIT &
USART_CONT_RX &
USART_BRGH_LOW,
67);
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) {
WDTCONbits.SWDTEN = 1; //Watchdog timer.
if (m == 1)
{
WDTCONbits.SWDTEN = 0;
for (i = 0; i < 10; i++)
{
if (a[i] == ucCharBuff[i])
function();
}
m = 0;
}
}
Close1USART();
}
void function()
{
PORTG = 0X40;
Delay10KTCYx(10000);
Delay10KTCYx(10000);
Delay10KTCYx(10000);
Delay10KTCYx(10000);
Delay10KTCYx(10000);
PORTG = 0X00;
}
#include<p18f97j60.h>
#include<usart.h>
#include<delays.h>
#pragma config XINST=OFF
#pragma config WDT=OFF, FOSC2=ON, FOSC=HSPLL, ETHLED=OFF, STVR = ON
#pragma interrupt high_isr
#pragma config WDTPS=128
unsigned int i, counter = 0, counter2 = 0;
volatile unsigned char a[10];
volatile unsigned int m;
unsigned char ucCharBuff[10];
void function();
void high_isr(void);
#pragma code high_vector=0x08
void interrupt_at_high_vector(void) //interrupt vector
{
_asm
goto high_isr
_endasm
}
#pragma code //interrupt routine
#pragma interrupt high_isr
void high_isr() {
if (PIR1bits.RC1IF == 1) {
PORTJ = 0X01;
INTCONbits.PEIE = 0;
//for (i = 0; i < 10; i++) {
a[counter] = RCREG1;
counter++;
//}
//Delay10KTCYx(10000);
//Delay10KTCYx(10000);
//Delay10KTCYx(10000);
//Delay10KTCYx(10000);
//Delay10KTCYx(10000);
PIR1bits.RC1IF = 0;
PORTJ = 0X00;
//m = 1;
}
}
void main()
{
OSCTUNE = 0X40;
TRISJ = 0;
PORTJ = 0X00;
TRISG = 0;
PORTG = 0X00;
RCONbits.IPEN = 0;
PIE1bits.RCIE = 1;
INTCON = 0XC0;
Open1USART(USART_TX_INT_ON & USART_RX_INT_ON & USART_ASYNCH_MODE & USART_EIGHT_BIT & USART_CONT_RX & USART_BRGH_LOW, 67);
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) {
if(counter == 10) {
for (i = 0; i < 10; i++)
{
if (a[i] == ucCharBuff[i])
counter2++;
}
if(counter2 == 10) {
function();
counter2 = 0;
}
counter = 0;
}
}
}
void function()
{
PORTG = 0X40;
Delay10KTCYx(10000);
Delay10KTCYx(10000);
Delay10KTCYx(10000);
Delay10KTCYx(10000);
Delay10KTCYx(10000);
PORTG = 0X00;
}
for (i = 0; i < 10; i++) {
a[i] = RCREG1;
counter++;
}
a[0] = '0'
a[1] = '1'
a[2] = '2'
a[3] = '3'
a[4] = '4'
a[5] = '5'
a[6] = '6'
a[7] = '7'
a[8] = '8'
a[9] = '9'
[code]
but according to your code it will be like
[code]
a[0] = '9'
a[1] = '9'
a[2] = '9'
a[3] = '9'
a[4] = '9'
a[5] = '9'
a[6] = '9'
a[7] = '9'
a[8] = '9'
a[9] = '9'
[code]
because the last character of the assumed rfid is 9, so, all the elements of a[] is replaced with '9'. I want to ask why you are not using ReadUSART() and WriteUSART() functions?
void high_isr() {
if (PIR1bits.RC1IF == 1) {
PORTJ = 0X01;
INTCONbits.PEIE = 0;
for (i = 0; i < 10; i++) {
a[i] = RCREG1;
}
Delay10KTCYx(10000);
Delay10KTCYx(10000);
Delay10KTCYx(10000);
Delay10KTCYx(10000);
Delay10KTCYx(10000);
PIR1bits.RC1IF = 0;
PORTJ = 0X00;
m = 1;
}
}
void high_isr()
{
if (PIR1bits.RC1IF == 1)
{
PORTJ = 0X01;
INTCONbits.PEIE = 0;
for (i = 0; i < 10; i++)
{
ucaBuffer[i] = RCREG1;
m = 1;
}
PIR1bits.RC1IF = 0;
PORTJ = 0X00;
m = 1;
}
}
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?