KEMBAR78
unsigned Char A : Usartinit | PDF
0% found this document useful (0 votes)
39 views2 pages

unsigned Char A : Usartinit

This code is controlling access to different rooms (the lobby, classrooms, and all rooms) based on received ID codes. It initializes UART communication and sets the GPIO pins for the LEDs. It then enters a loop that receives characters over UART, compares the received value to predefined ID codes, and controls the LEDs on the GPIO pins accordingly - granting access to all rooms for one ID, classrooms only for another ID, and the lobby only for an unmatched ID.

Uploaded by

Manjeet Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views2 pages

unsigned Char A : Usartinit

This code is controlling access to different rooms (the lobby, classrooms, and all rooms) based on received ID codes. It initializes UART communication and sets the GPIO pins for the LEDs. It then enters a loop that receives characters over UART, compares the received value to predefined ID codes, and controls the LEDs on the GPIO pins accordingly - granting access to all rooms for one ID, classrooms only for another ID, and the lobby only for an unmatched ID.

Uploaded by

Manjeet Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

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. }

You might also like