Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- i did the same way, but i dont know whats wrong in my code!!!
- #define F_CPU 12000000UL
- #define USART_BAUDRATE 9600
- #define BAUD_PRESCALE (((F_CPU / (USART_BAUDRATE * 16UL))) - 1)
- #define LCD_DATA PORTC
- #include<avr/io.h>
- #include<util/delay.h>
- #include "lcd_lib.h"
- void usart_init();
- unsigned int usart_getch();
- unsigned char i,j, card[13];
- void getcard_id(void);
- int main(void)
- {
- //LCD_DATA port as output port
- DDRC=0xFF;
- DDRA=0x07;
- usart_init(); // initiailztion of USART
- i=j;
- LCDinit(); // initialization of LCD
- _delay_ms(100); // delay of 50 milli seconds
- LCDclr();
- while(1)
- {
- getcard_id();
- if(card[0]==2)
- {
- LCDGotoXY(0,1);
- LCDdisplay(card);
- _delay_ms(500);
- }
- return 0;
- }
- }
- void getcard_id(void) //Function to get 12 byte ID no. from rfid card
- {
- for(i=0;i<12;i++)
- {
- card[i]= usart_getch(); // receive card value byte by byte
- PORTA|=(1<<0);
- PORTA^=(1<<0);
- _delay_ms(100);
- PORTA^=(1<<0);
- _delay_ms(100);
- PORTA^=(1<<0);
- _delay_ms(100);
- }
- return;
- }
- void usart_init()
- {
- UCSRB |= (1 << RXEN) | (1 << TXEN); // Turn on the transmission and reception circuitry
- UCSRC |= (1 << URSEL) | (1<<USBS) | (1 << UCSZ0) | (1 << UCSZ1);
- // Use 8-bit character sizes
- UBRRL = BAUD_PRESCALE; // Load lower 8-bits of the baud rate value..
- // into the low byte of the UBRR register
- UBRRH = (BAUD_PRESCALE >> 8); // Load upper 8-bits of the baud rate value..
- // into the high byte of the UBRR register
- }
- unsigned int usart_getch()
- {
- while ((UCSRA & (1 << RXC)) == 0); // Do nothing until data have been received..
- // and is ready to be read from UDR
- return(UDR); // return the byte
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement