Advertisement
atmegaMANJU

rfid1

Aug 7th, 2014
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.56 KB | None | 0 0
  1. #define F_CPU 12000000UL
  2.  
  3. #define USART_BAUDRATE 9600
  4. #define BAUD_PRESCALE (((F_CPU / (USART_BAUDRATE * 16UL))) - 1)
  5. #define LCD_DATA PORTC
  6.  
  7.  
  8. #include<avr/io.h>
  9. #include<util/delay.h>
  10. #include "lcd_lib.h"
  11.  
  12.  
  13. void usart_init();
  14. unsigned int usart_getch();
  15.  
  16. unsigned char i,j, card[13];
  17. void getcard_id(void);
  18.  
  19.  
  20. int main(void)
  21. {
  22.             //LCD_DATA port as output port
  23.     DDRC=0xFF;     
  24.     DDRA=0x07;
  25.     usart_init();   // initiailztion of USART
  26.    
  27.     i=j;
  28.      LCDinit(); // initialization of LCD
  29.      _delay_ms(100); // delay of 50 milli seconds
  30.      LCDclr();
  31.     while(1)
  32.    {
  33.      getcard_id();
  34.     if(card[0]==2)
  35.     {
  36.      LCDGotoXY(0,1);
  37.      LCDdisplay(card);
  38.      
  39.      }
  40.      return 0;
  41.    }
  42. }
  43.  
  44. void getcard_id(void)   //Function to get 12 byte ID no. from rfid card
  45. {  
  46.     for(i=0;i<12;i++)
  47.     {
  48.         card[i]= usart_getch(); // receive card value byte by byte
  49.          
  50.  
  51.     }
  52.  
  53.     return;
  54. }
  55.  
  56.  
  57.  
  58.  
  59. void usart_init()
  60. {
  61.     UCSRB |= (1 << RXEN) | (1 << TXEN);   // Turn on the transmission and reception circuitry
  62.     UCSRC |= (1 << URSEL) | (1<<USBS) | (1 << UCSZ0) | (1 << UCSZ1);
  63.                                                             // Use 8-bit character sizes
  64.  
  65.     UBRRL = BAUD_PRESCALE;  // Load lower 8-bits of the baud rate value..
  66.                             // into the low byte of the UBRR register
  67.     UBRRH = (BAUD_PRESCALE >> 8); // Load upper 8-bits of the baud rate value..
  68.                                   // into the high byte of the UBRR register
  69. }
  70.  
  71. unsigned int usart_getch()
  72. {
  73.     while ((UCSRA & (1 << RXC)) == 0); // Do nothing until data have been received..
  74.                        // and is ready to be read from UDR
  75.     return(UDR); // return the byte
  76.    
  77.  
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement