/LCD16x2-4bits-Driver-AVR

LCD 16x2 interfacing with AVR Atmega16a micro controller using 4-bits mode - LCD16x2 4bits Mode Driver

Primary LanguageC

LCD16x2-4bits-Driver-AVR

LCD 16x2 interfacing with AVR Atmega16a microcontroller using 4-bits mode - LCD16x2 4bits Mode Driver

image

Description:

  • A driver for alphanumeric characters LCD 16x2 modules with the internal HD-44780U controller using 4-bits mode.

Target microcontrollers:

  • This library uses only I/O ports & registers, so it can be used for all 8-bits AVRs family microcontrollers and some other simple 8-bits microcontrollers by editing the I/O ports & registers definitions macros in lcd.h file.

Features:

  • Use 4-bits mode for minimum microcontroller pins usage (uses only 7 port pins).
  • Allow the user to select which microcontroller port pins to connect the while LCD pins.
  • Tested and verified with the Smallest delay for this slow LCD modules (as the biggest delay for commands/data never exceeds 2ms).
  • Contains all the LCD HD44780U controller possible functions from clear, shifting, cursor modes .. etc.

Functions Supported:

  • initializing LCD.
  • send commands to LCD.
  • send single character data to LCD.
  • send a string to LCD.
  • clear LCD.
  • set cursor mode (on, off, blinking).
  • shift the cursor to right and left.
  • shift displayed data to right and left.
  • move the DDRAM address of LCD to any position.

Requirements:

  • compiled for AVR/GNU C Compiler (avr-gcc) for 8 bits AVR micro-controllers

How to use:

  • All LCD configurations related to I/O interfacing are placed in lcd.h file

Change the I/O registers to the LCD port you want to use in lcd

#define LCD_DATA_DDR		DDRA						// LCD data/command port direction register		
#define LCD_DATA_PORT		PORTA						// LCD data/command port register
#define LCD_DATA_PIN		PINA						// LCD data/command pin register	
#define LCD_CONTROL_DDR		DDRB						// LCD control port direction register	
#define LCD_CONTROL_PORT	PORTB						// LCD control port register	
#define RS										0		// LCD RS pin
#define RW										1		// LCD R/W pin
#define EN										2		// LCD EN pin
  • The library is compiled for a specific LCD D4-D7 pins connection to microcontroller pins by using pre-compiled user-defined macros as follows:

Use this code if you connect LCD D4-D7 pins to microcontroller port pins 0-3

#define USE_MCU_PORT_HIGH_OR_LOW_NIBBLE			0		// 0>use port 0,1,2,3 pins .. 1>use port 4,5,6,7 pins
#define LCD_D4_PIN								0		// make it 0 if USE_MCU_PORT_HIGH_OR_LOW_NIBBLE = 0 .. 4 if USE_MCU_PORT_HIGH_OR_LOW_NIBBLE = 1
#define LCD_D5_PIN								1		// make it 1 if USE_MCU_PORT_HIGH_OR_LOW_NIBBLE = 0 .. 5 if USE_MCU_PORT_HIGH_OR_LOW_NIBBLE = 1
#define LCD_D6_PIN								2		// make it 2 if USE_MCU_PORT_HIGH_OR_LOW_NIBBLE = 0 .. 6 if USE_MCU_PORT_HIGH_OR_LOW_NIBBLE = 1
#define LCD_D7_PIN								3		// make it 3 if USE_MCU_PORT_HIGH_OR_LOW_NIBBLE = 0 .. 7 if USE_MCU_PORT_HIGH_OR_LOW_NIBBLE = 1

OR edit to this code instead if you connect LCD D4-D7 pins to microcontroller port pins 4-7

#define USE_MCU_PORT_HIGH_OR_LOW_NIBBLE			1		// 0>use port 0,1,2,3 pins .. 1>use port 4,5,6,7 pins
#define LCD_D4_PIN								4		// make it 0 if USE_MCU_PORT_HIGH_OR_LOW_NIBBLE = 0 .. 4 if USE_MCU_PORT_HIGH_OR_LOW_NIBBLE = 1
#define LCD_D5_PIN								5		// make it 1 if USE_MCU_PORT_HIGH_OR_LOW_NIBBLE = 0 .. 5 if USE_MCU_PORT_HIGH_OR_LOW_NIBBLE = 1
#define LCD_D6_PIN								6		// make it 2 if USE_MCU_PORT_HIGH_OR_LOW_NIBBLE = 0 .. 6 if USE_MCU_PORT_HIGH_OR_LOW_NIBBLE = 1
#define LCD_D7_PIN								7		// make it 3 if USE_MCU_PORT_HIGH_OR_LOW_NIBBLE = 0 .. 7 if USE_MCU_PORT_HIGH_OR_LOW_NIBBLE = 1

Testing and verification:

  • All functions have been tested and verified on AVR Atmega16a microcontroller.

Demo:

"youtube link"

NOTE:

  • Files: lcd.h and lcd.c are the only files for the driver.
  • File: main.c is for driver testing and verification.

COPYRIGHTS:

Feel free to use all files in this project repository for purpose of #EDUCATION only.

For any #COMMERCIAL or #NON_EDUCATIONAL use for any code in these files, please contact me at amr.mostaafaa@gmail.com