c - rfid and lcd interfacing with atmega16? -
i doing project on rfid module(em18). problem unable take card number on lcd display.it shows random value(hex or other constant same card again ). how manage , display proper value(exact value) of card on lcd(16*2)?
#define f_cpu 16000000ul #define usart_baudrate 9600 #define baud_prescale (((f_cpu / (usart_baudrate * 16ul))) - 1) #include <avr/io.h> #include <util/delay.h> #define lcd_data porta // lcd data port #define ctrl portb #define en pb1 // enable signal #define rw pb2 // read/write signal #define rs pb0 // register select signal void lcd_cmd(unsigned char cmd); void init_lcd(void); void lcd_write(unsigned char data); void usart_init(); unsigned int usart_getch(); unsigned char i, card[10]; void getcard_id(void); void lcd_display(void); int main(void) { ddra=0xff; // lcd_data port output port ddrb=0x07; // ctrl out put init_lcd(); // initialization of lcd _delay_ms(50); // delay of 50 mili seconds lcd_write_string("hello world!!!"); lcd_cmd(0xc0); _delay_ms(50); lcd_write_string("rfid project"); usart_init(); // initiailztion of usart while(1) { getcard_id(); // function rfid card no. serial port lcd_cmd(0xc0); // go in second line , zeroth position on lcd lcd_display(); // function write rfid card no. on lcd } return 0; } void getcard_id(void) //function 10 byte id no. rfid card { for(i=0;i<10;i++) { card[i]= usart_getch(); // receive card value byte byte } return;`` } unsigned int usart_getch() { while ((ucsra & (1 << rxc)) == 0); // nothing until data have been received.. // , ready read udr return(udr); // return byte } void usart_init() //usart initialization { ubrrh=00; //ubrrl=77; ubrrl=103;// 16mhz crystal ucsrb |= (1 << rxen) | (1 << txen); // turn on transmission , reception circuitry ucsrc |= (1 << ursel) | (1<<usbs) | (1 << ucsz0) | (1 << ucsz1); // use 8-bit character sizes ubrrl = baud_prescale; ubrrh = (baud_prescale >> 8); } void lcd_display(void) //function displaying id no. on lcd { for(i=0;i<10;i++) { lcd_write(card[i]); // display card value byte byte } return; } void init_lcd(void) { lcd_cmd(0x38); //initializtion of 16x2 lcd in 8bit mode _delay_ms(1); lcd_cmd(0x01); //clear lcd _delay_ms(1); lcd_cmd(0x0e); //cursor on _delay_ms(1); lcd_cmd(0x80); // ---8 go first line , --0 0th position _delay_ms(1); return; } void lcd_cmd(unsigned char cmd) { lcd_data=cmd; ctrl =(0<<rs)|(0<<rw)|(1<<en); _delay_ms(5); ctrl =(0<<rs)|(0<<rw)|(0<<en); _delay_ms(5); return; } void lcd_write(unsigned char data) { lcd_data= data; ctrl = (1<<rs)|(0<<rw)|(1<<en); _delay_ms(5); ctrl = (1<<rs)|(0<<rw)|(0<<en); _delay_ms(5); return ; } void lcd_write_string(unsigned char *str) // take address value of string in pointer *str { int i=0; while(str[i]!='\0') // loop go on till null characters in string { lcd_write(str[i]); // sending data on lcd byte byte i++; } return; }
Comments
Post a Comment