Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

PIC16F877A & RS232 RFID READER, HiTech C

Status
Not open for further replies.

reachrajesh

Junior Member level 2
Joined
Aug 12, 2013
Messages
20
Helped
1
Reputation
2
Reaction score
1
Trophy points
3
Activity points
252
This codes only works for first input, for 2nd input onwards, it does not working.....


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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
/************************ RFID BASED ELECTRONIC TOLL GATE SYSTEM **********************************************/
 
#include<htc.h>
#include<pic16f877a.h>
 
#include<string.h>
#include<stdio.h>
#define _XTAL_FREQ 20e6
 
 
 
//========================================================================
//  Configuration
//========================================================================
__CONFIG ( 0x3F32 );                //configuration for the  microcontroller
 
 
//=========================================================================                                 
//  Define
//=========================================================================
#define rs          RC0             //RS pin of the LCD display
#define rw          RC1             //R/W pin of the LCD display    
#define e           RC2             //E pin of the LCD display
#define lcd_data    PORTB           //LCD 8-bit data PORT
 
 
 
//===========================================================================
//  Function prototype              (every function must have a function prototype)
//===========================================================================
void delay(unsigned long data);         
void send_config(unsigned char data);
void send_char(unsigned char data);
void lcd_goto(unsigned char data);
void lcd_clr(void);
void send_string(const char *s);
unsigned char uart_rec(void);
 
 
 
//===========================================================================
//  Main function                   (main fucntion of the program)
//===========================================================================
void main(void)
{
    //assign variable
    unsigned char i,temp,database;              
    unsigned char data[12];                     //12 bytes of data received from RFID Reader.
                                                //The data include start of heading, RFID ID, 
                                                //and start of text
    
    unsigned char id_1[12]={"0003475374"};      //define the Tag ID here
    unsigned char id_2[12]={"0003471976"};      //change this ID to the tag ID that user want to read
    
    unsigned char user_1[10]={"USER1-WCM"}; //define the Tag user here
    unsigned char user_2[10]={"USER2-WCM"}; //change this user name to the tag ID owner name
 
    //set I/O input output
    TRISB = 0b00000000;                 //configure PORTB I/O direction
    TRISC = 0b10000000;                 //configure PORTC I/O direction
    TRISA = 0b11110011;                 //configure PORTA I/O direction
    
    //setup USART
    SPBRG = 0x81;                       //set baud rate to 9600 for 20Mhz
    BRGH = 1;                           //baud rate high speed option
    TXEN = 1;                           //enable transmission
    CREN = 1;                           //enable reception
    SPEN = 1;                           //enable serial port
    
 
    
    //configure lcd
    send_config(0b00000001);            //clear display at lcd
    send_config(0b00000010);            //lcd return to home 
    send_config(0b00000110);            //entry mode-cursor increase 1
    send_config(0b00001100);            //display on, cursor off and cursor blink off
    send_config(0b00111000);            //function set
            
    //set initial condition
 
    
    lcd_clr();                          //clear lcd
    lcd_goto(0);                        //set the lcd cursor to location 0
    send_string("RFID");        //display welcome note
    lcd_goto(20);                       //set the lcd cursor to location 20
    send_string("TOLL COLLECTION");         //display welcome note
 
    delay(200000);                      //delay for display the welcome note
 
    //infinity loop 
    while(1)    
    {
        CREN = 1;                               //enable reception from UART
        lcd_clr();                              //clear lcd
        lcd_goto(0);                            //set lcd cursor to location 0
        send_string("Place your ID");           //display note
        lcd_goto(20);                           //set lcd cursor to location 20
        send_string("on the reader.");          //display note
        
        for(i=0;i<12;i+=1)data[i]=uart_rec();   //wait for 12 character data receive from RFID reader
                                                //The data receive are start of heading, RFID ID, 
                                                //and start of text
 
 
                
        lcd_clr();                              //clear lcd
        lcd_goto(20);                           //set lcd cursor to location 20
        send_string("Processing......");        //display "Processing...."
        delay(40000);                           //delay
        
        database=0;                             //clear the value of database and start scanning            
        
        //comparing with the 1st id
        temp=0;                                 //comparing the received data with the saved id.
                                                //only byte 2-11 which is RFID ID data, will be used to compare between 
                                                //receive data and saved id.
        for(i=1;i<11;i+=1)                      //comparing digit by digit
        {   
            if((data[i])!=(id_1[i-1]))temp=1;   //if the id is different from the id define above,
        }                                       //then set temp=1;
        if(temp==0) database=1;                 //if temp=0, mean the id match, set the database=1
        
        //comparing with the 2nd id
        temp=0;                                 //comparing the received data with the saved id
                                                //only byte 2-11 which is RFID ID data, will be used to compare between 
                                                //receive data and saved id.
        for(i=1;i<11;i+=1)                      //comparing digit by digit
        {
            if((data[i])!=(id_2[i-1]))temp=1;   //if the id is different from the id define above,
        }                                       //then set temp=1;
        if(temp==0) database=2;                 //if temp=0, mean the id match, set the database=1      
        
        lcd_clr();                              //clear lcd 
        CREN = 0;                               //disable reception from UART
 
 
        switch(database)                        
        {
            case 1:                                         //id 1 match
        
                lcd_goto(0X01);                             //set lcd cursor to location 0
                send_string("ID:");                         //display "ID: "
                for(i=0;i<10;i+=1)send_char(id_1[i]);       //display tag ID
                lcd_goto(20);                               //set lcd cursor to location 20
                send_string("user: ");                      //display "user: "
                for(i=0;i<10;i+=1)send_char(user_1[i]);     //display user name
            
                break;
            case 2:                                         //id_2 match
        
                lcd_goto(0);                                //set lcd cursor to location 0
                send_string("ID: ");                        //display "ID: "
                for(i=0;i<10;i+=1)send_char(id_2[i]);       //display tag ID
                lcd_goto(20);                               //set lcd cursor to location 20
                send_string("user: ");                      //display "user: "
                for(i=0;i<10;i+=1)send_char(user_2[i]);     //display user name 
            
                break;
            default:                                        //id doesnt match 
                lcd_goto(0);                                //set lcd cursor to location 0
                send_string("ID: ");                        //display "ID: "
                for(i=1;i<11;i+=1)send_char(data[i]);       //display tag ID
                lcd_goto(20);                               //set lcd cursor to location 20
                send_string("user not found");              //display "user not found"
            
                break;
        }
        delay(300000);                                      //delay
 
    }
        
}
 
//===========================================================================
//  Functions
//===========================================================================
 
void delay(unsigned long data)          //delay function, the delay time
{                                       //depend on the given value
    for( ;data>0;data-=1);
}
 
void send_config(unsigned char data)    //send lcd configuration 
{
    rw=0;                               //set lcd to write mode
    rs=0;                               //set lcd to configuration mode
    lcd_data=data;                      //lcd data port = data
    e=1;                                //pulse e to confirm the data
    delay(50);
    e=0;
    delay(50);
}
 
void send_char(unsigned char data)      //send lcd character
{
    rw=0;                               //set lcd to write mode
    rs=1;                               //set lcd to display mode
    lcd_data=data;                      //lcd data port = data
    e=1;                                //pulse e to confirm the data
    delay(10);
    e=0;
    delay(10);
}
 
void lcd_goto(unsigned char data)       //set the location of the lcd cursor
{                                       //if the given value is (0-15) the 
    if(data<16)                         //cursor will be at the upper line
    {                                   //if the given value is (20-35) the 
        send_config(0x80+data);         //cursor will be at the lower line
    }                                   //location of the lcd cursor(2X16):
    else                                // -----------------------------------------------------
    {                                   // | |00|01|02|03|04|05|06|07|08|09|10|11|12|13|14|15| |
        data=data-20;                   // | |20|21|22|23|24|25|26|27|28|29|30|31|32|33|34|35| |
        send_config(0xc0+data);         // -----------------------------------------------------    
    }
}
 
void lcd_clr(void)                      //clear the lcd
{
    send_config(0x01);
 
    delay(600); 
}
 
void send_string(const char *s)         //send a string to display in the lcd
{          
    unsigned char i=0;
    while (s && *s)send_char (*s++);
 
}
 
unsigned char uart_rec(void)            //receive uart value
{
    unsigned char rec_data;
    while(RCIF==0);                     //wait for data
    rec_data = RCREG;               
    return rec_data;                    //return the data received
}

 

Re: PIC16F877A &amp; RS232 RFID READER, HiTech C

any one tell me why this code is not working for second input..

- - - Updated - - -

any one tell me why this code is not working for second input..
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top