EE-222 MICROPROCESSOR SYSTEMS ASSIGNMENT#02 REPORT SUBMITTED TO:DR.REHAN AHMED
SUBMITTED BY:SYED SAAD GILLANI (237887) SHER SHAH EJAZ (212230)
In this assignment, we learnt to interface a 16x2 LCD with an ATMEGA16a microcontroller. LCD is an electronic display used in embedded applications to display information. HARDWARE COMPONENTS REQUIRED: 1. 2. 3. 4.
BREADBOARD WIRES 16x2 LCD DISPLAY ATMEGA16a
WORKING: This task is achieved using the I/O pins and two special registers namely command register and data register. The command register stores the command instructions given to the LCD. A command is an instruction given to LCD to do a predefined task like initializing it, clearing its screen, setting the cursor position, controlling display etc. The data register stores the data to be displayed on the LCD. The data is the ASCII value of the character to be displayed on the LCD. LCD works in 8-bit mode i.e., the data transferred to the LCD must be in 8-bit data form. You can connect PortA of your ATmega16 to the eight data pins (D0-D7) of the LCD and PortB to the control pins (Rs, R/W and En).
PROTEUS SIMULATION:
PATCHED WORKING HARDWARE CIRCUIT:
SOURCE CODE: #define F_CPU 1000000UL #include
#include void sendCommand(unsigned char command); void sendData(unsigned char data); void intializeLCD(); void sendSentence(char* str); int main() { DDRB=0xFF; DDRD=0xFF; intializeLCD(); _delay_ms(20); sendCommand(0x80); char array[]={"Syed Saad 237887"}; sendSentence(array); sendCommand(0xC0); char array1[]={"Sher Shah 212230"}; sendSentence(array1); while(1) { int shift=36; for (int i=0;i<shift;i++)
{ sendCommand(0x18); _delay_ms(100); } } }
void sendCommand(unsigned char command) { PORTB=command; PORTD &=~ (0x01); PORTD &=~ (0x02); PORTD |= (0x04); _delay_ms(10); PORTD &=~ (0x04); } void sendSentence(char* str) { // int i=0; while(str[i]!=0) { sendData(str[i]); i++; } } void sendData(unsigned char data) { PORTB=data; PORTD |= (0x01); PORTD &=~ (0x02); PORTD |= (0x04); _delay_ms(10); PORTD &=~ (0x04); } void intializeLCD() { sendCommand(0x38); sendCommand(0x0C); sendCommand(0x06); sendCommand(0x01); sendCommand(0x8F); }
CHALLENGES FACED: 1. The LCD display contrast was difficult to adjust and we had to use a potentiometer to maintain the contrast and brightness at the required level. 2. Some difficulties were faced during the implementation of the code. 3. Soldering the LCD was another challenge faced.