djinni
Newbie level 4
- Joined
- Mar 27, 2009
- Messages
- 6
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,281
- Location
- Indonesia
- Activity points
- 1,345
Hello, I am working on a project using atmega8535 involving the use of rfid. I want to display the rfid tag serial number on 16 x 2 lcd, but I am unable to accomplish it. I have even try to connect the rfid module with MAX 232, but it does not work. Can anyone please check for any errors I make in the programming?
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 #define F_CPU 8000000UL #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 PB2 // enable signal #define rw PB1 // 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[12]; void getcard_id(void); void LCD_display(void); int main(void) { DDRA=0xff; //LCD_DATA port as output port DDRB=0x07; //ctrl as out put init_LCD(); //initialization of LCD _delay_ms(50); // delay of 50 milliseconds UCSRA=0x00; // USART initialization UCSRB=0x10; UCSRC=0x86; UBRRH=0x00; UBRRL=0x33; LCD_write_string("Unique ID No."); //Function to display string on LCD while(1) { getcard_id(); // Function to get RFID card no. from serial port LCD_cmd(0xC0); // to go in second line and zeroth position on LCD LCD_display(); // a function to write RFID card no. on LCD } 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 } return; } void LCD_display(void) //Function for displaying ID no. on LCD { for(i=0;i<12;i++) { LCD_write(card[i]); // display card value byte by 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 to first line and --0 is for 0th position _delay_ms(1); return; } void LCD_cmd(unsigned char cmd) { LCD_DATA=cmd; ctrl =(0<<rs)|(0<<rw)|(1<<en); _delay_ms(1); ctrl =(0<<rs)|(0<<rw)|(0<<en); _delay_ms(50); return; } void LCD_write(unsigned char data) { LCD_DATA= data; ctrl = (1<<rs)|(0<<rw)|(1<<en); _delay_ms(1); ctrl = (1<<rs)|(0<<rw)|(0<<en); _delay_ms(50); 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 } void LCD_write_string(unsigned char *str) // take address value of the string in pointer *str { int i=0; while(str[i]!='\0') // loop will go on till the NULL characters is soon in string { LCD_write(str[i]); // sending data on LCD byte by byte i++; } return; }
Last edited by a moderator: