1. #include<avr/io.
h>
2. #include
3. #include
4. void usartinit();
5. //unsigned char a;
6. unsigned char value[15];
7. unsigned int b;
8. unsigned int k=0,i=0,j,l;
9. unsigned char value1[]={"140071D1A612"}; //Predefined ID
10. unsigned char value2[]={"51005D6899FD"};
11.
12. int main ()
13. {
14. DDRC=0xFF;
15. DDRB=0xFF;
16. PORTB=0x00;
17. usartinit();
18.
19. while(1)
20. {
21. while((UCSRA)&(1<<RXC))
22. {
23. value[i]=UDR;
24. _delay_ms(1);
25. i++;
26. if(i==12)
27. {
28. value[i]='';
29. for(j=0;value1[j]!='';j++)
30. {
31. if(value[j]==value1[j])
32. k++;
33. }
34. if(k==12) //Match with the predefined ID
35. {
36. PORTB|=(1<<0)|(1<<1)|(1<<2); //Master have access to all rooms
37. _delay_ms(5000);
38. PORTB=0x00;
39. }
40. else
41. {
42. k=0;
43. for(j=0;value2[j]!='';j++)
44. {
45. if(value[j]==value2[j])
46. k++;
47. }
48. if(k==12)
49. {
50. PORTB|=(1<<1); //Student have access to class rooms only
51. _delay_ms(5000);
52. PORTB=0x00;
53. }
54. else
55. {
56. PORTB|=(1<<2); //Guest have access to lobby only
57. _delay_ms(5000);
58. PORTB=0x00;
59. }}}}}}
60. void usartinit()
61. {
62. UBRRH=00;
63. UBRRL=77;
64. UCSRB|=(1<<RXEN);
65. UCSRC|=(1<<URSEL)|(1<<UCSZ0)|(1<<UCSZ1);
66. }