Advertisement
atmegaMANJU

rfid

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