Mohamed M. Fathy Ahmed Abdelsalam
Published

AVR 4-Bit LCD Interface in C Language

Interfacing an LCD to AVR microcontroller using only one port (PORT B).

BeginnerFull instructions provided1 hour969
AVR 4-Bit LCD Interface in C Language

Things used in this project

Hardware components

ATmega328
Microchip ATmega328
×1
RGB Backlight LCD - 16x2
Adafruit RGB Backlight LCD - 16x2
×1

Software apps and online services

codevision AVR

Story

Read more

Schematics

Connection Diagram

Code

C code for the LCD interface

C/C++
#include <90s8515.h>
#include <stdio.h>
#include <delay.h>
void lcd_send_data(unsigned char );
void lcd_send_comm(unsigned char );
void lcd_init(void);
void main()
{
DDRC=0xff;  
lcd_init();
lcd_send_data('H'); 
lcd_send_data('E');
lcd_send_data('L');
lcd_send_data('L');
lcd_send_data('o');
lcd_send_data(' ');
lcd_send_data('M');
lcd_send_data('O');
lcd_send_comm(0Xc0);  
lcd_send_data('H');
lcd_send_data('A');
lcd_send_data('M');
lcd_send_data('E');
lcd_send_data('D');
while(1);
  
}   
void lcd_init(void)
{
lcd_send_comm(0x2c);
lcd_send_comm(0X0C);
lcd_send_comm(0X80);     
lcd_send_comm(0X01);   
}
void lcd_send_data(unsigned char data)
{
unsigned char z;
delay_ms(3);
z=0xf0 & data;
PORTC=z;
PORTC.0=1;
PORTC.1=1;
PORTC.1=0;
delay_ms(3);
z=data<<4;
PORTC=z;
PORTC.0=1;
PORTC.1=1;
PORTC.1=0;
}
void lcd_send_comm(unsigned char comm)
{
unsigned char y;
delay_ms(3);
y=0xf0 & comm;
PORTC=y;
PORTC.0=0;
PORTC.1=1;
PORTC.1=0;
delay_ms(3);
y=comm<<4;
PORTC=y;
PORTC.0=0;
PORTC.1=1;
PORTC.1=0;
}

Credits

Mohamed M. Fathy Ahmed Abdelsalam
8 projects • 22 followers
Contact

Comments

Please log in or sign up to comment.