Mrunal Ahirrao
Full Member level 2
- Joined
- Nov 26, 2012
- Messages
- 133
- Helped
- 2
- Reputation
- 4
- Reaction score
- 2
- Trophy points
- 1,298
- Location
- India
- Activity points
- 2,213
sbit LED at RB3_bit;
unsigned char rdata[12];
unsigned char idata[]="84008159124E";
unsigned short i;
void interrupt()
{
if(PIR1.RCIF==1)
{
rdata[i]=RCREG;
i++;
}
}
void main()
{
CMCON = 7; // Disable Comparators
TRISB = 0b00000110;
SPBRG=25; // Fill SPBRG register to set the baud rate
RCSTA.SPEN=1; // To activate serial port (Tx and Rx pins)
RCSTA.CREN=1; // To enable continuous reception
PIE1.RCIE=1; // To enable the Reception (Rx) Interrupt
INTCON.GIE=1;
INTCON.PEIE=1;
TXSTA.BRGH=1;
TXSTA.SYNC=0;
do{
if(rdata==idata)
{
LED=1;
}
}while(1);
}
EM -18 RFID Cards work on 12 byte data transfer
And first you check a basic code of sending and receiving it to PC via UART using Mikeo C ,
so that it's assured that there is some problem after that we'll discuss on RFID Interfacing
void main() {
unsigned char MyError, Temp;
CMCON = 7; // Disable Comparators
TRISB = 0b00000010;
UART1_Init(9600);
Delay_ms(100);
UART1_Write_Text("Testing UART! ");
newline();
do {
UART1_Write_Text("Type in a Number: ");
while(!UART1_Data_Ready());
Temp = UART1_Read();
newline();
UART1_Write_Text("You entered: ");
UART1_Write(Temp);
newline();
} while(1); } // End main()
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 void newline(){ UART1_Write(0x0D); UART1_Write(0x0A); } void main(){ unsigned char MyError, number[24], i; CMCON = 7; // Disable Comparators TRISA = 0xFF; PORTA = 0x00; TRISB = 0x02; PORTB = 0x00; UART1_Init(9600); Delay_ms(100); UART1_Write_Text("Testing UART!"); newline(); while(1){ UART1_Write_Text("Type in a Number: "); while(!UART1_Data_Ready()); while(number[i] != 0x0D) number[i++] = UART1_Read(); number[i] = '\0'; newline(); UART1_Write_Text("You entered: "); UART1_Write_Text(number); newline(); } }
Any other Code you tried like LED blinking and all other using Mikro C like i wanted to know that whether the hex file are created Actually i am thinking other side that whether MikroC is working or not,
or else do one thing there is a library in Mplab_IDE
You can use that also first check that thing also
Meanwhile also define newline() function in your code
Thanks for the code. But nothing is displayed on PC.Try this code for testing UART.
Fosc = 4 MHz and baudrate = 9600 bps
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 void newline(){ UART1_Write(0x0D); UART1_Write(0x0A); } void main(){ unsigned char MyError, number[24], i; CMCON = 7; // Disable Comparators TRISA = 0xFF; PORTA = 0x00; TRISB = 0x02; PORTB = 0x00; UART1_Init(9600); Delay_ms(100); UART1_Write_Text("Testing UART!"); newline(); while(1){ UART1_Write_Text("Type in a Number: "); while(!UART1_Data_Ready()); while(number[i] != 0x0D) number[i++] = UART1_Read(); number[i] = '\0'; newline(); UART1_Write_Text("You entered: "); UART1_Write_Text(number); newline(); } }
Code C - [expand] 1 2 3 while(i < 12) number[i++] = UART1_Read(); number[i] = '\0';
The last character should be 0x0D else it will not come out of UART read loop. Use below code. It reads 12 characters.
Code C - [expand] 1 2 3 while(i < 12) number[i++] = UART1_Read(); number[i] = '\0';
unsigned char i,unsigned char card[12];
for(i=0;i<12;i++)
{
card[i] = Receive Function for UART(); // receive card value byte by byte ;;12 Byte
}
It works fine for me. Check your hardware.
Just use a simple for loop
it might help you as EM-18 module ID- cards are of 12 bytes
so apply the following loop
Try thisCode:unsigned char i,unsigned char card[12]; for(i=0;i<12;i++) { card[i] = Receive Function for UART(); // receive card value byte by byte ;;12 Byte }
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?