LCD 16x2 interfacing with AVR Atmega16a microcontroller using 4-bits mode - LCD16x2 4bits Mode Driver
- A driver for alphanumeric characters LCD 16x2 modules with the internal HD-44780U controller using 4-bits mode.
- 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.
- 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.
- 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.
- compiled for AVR/GNU C Compiler (avr-gcc) for 8 bits AVR micro-controllers
- 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
- All functions have been tested and verified on AVR Atmega16a microcontroller.
"youtube link"
- Files: lcd.h and lcd.c are the only files for the driver.
- File: main.c is for driver testing and verification.