/**************************************************************************** LCD-AVR-8d-s.c - Use an HD44780U based LCD with an Atmel ATmega processor Copyright (C) 2013 Donald Weiman (weimandn@alfredstate.edu) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ /**************************************************************************** File: LCD-AVR-8d-s.c Date: September 16, 2013 Target: ATmega328 Compiler: avr-gcc (AVR Studio 6) Author: Donald Weiman Summary: 8-bit data interface, busy flag not implemented. Requires an 8-bit port for data pins. Includes a simple write string routine. */ /******************************* Program Notes ****************************** This program uses an 8-bit data interface but does not use the busy flag to determine when the LCD controller is ready. The LCD RW line (pin 5) is not connected to the uP and it must be connected to GND for the program to function. All time delays are longer than those specified in most datasheets in order to accommodate slower than normal LCD modules. This requirement is well documented but almost always ignored. The information is in a note at the bottom of the right hand (Execution Time) column of the instruction set. *************************************************************************** The eight data lines must be implemented, in sequence, on a single 8-bit port. The Enable and Register Select lines may be implemented on any two available pins of any other port. These are the connections used for this program: ----------- ---------- | ATmega328 | | LCD | | | | | | PD7|---------------->|D7 | | PD6|---------------->|D6 | | PD5|---------------->|D5 | | PD4|---------------->|D4 | | PD3|---------------->|D3 | | PD2|---------------->|D2 | | PD1|---------------->|D1 | | PD0|---------------->|D0 | | | | | | PB1|---------------->|E | | | GND --->|RW | | PB0|---------------->|RS | ----------- ---------- **************************************************************************/ #define F_CPU 16000000UL #include #include // LCD interface (should agree with the diagram above) // make sure that the LCD RW pin is connected to GND #define lcd_data_port PORTD // lcd Data pins #define lcd_data_ddr DDRD #define lcd_E_port PORTB // lcd Enable pin #define lcd_E_bit PORTB1 #define lcd_E_ddr DDRB #define lcd_RS_port PORTB // lcd Register Select pin #define lcd_RS_bit PORTB0 #define lcd_RS_ddr DDRB // LCD module information #define lcd_LineOne 0x00 // start of line 1 #define lcd_LineTwo 0x40 // start of line 2 //#define lcd_LineThree 0x14 // start of line 3 (20x4) //#define lcd_lineFour 0x54 // start of line 4 (20x4) //#define lcd_LineThree 0x10 // start of line 3 (16x4) //#define lcd_lineFour 0x50 // start of line 4 (16x4) // LCD instructions #define lcd_Clear 0b00000001 // replace all characters with ASCII 'space' #define lcd_Home 0b00000010 // return cursor to first position on first line #define lcd_EntryMode 0b00000110 // shift cursor from left to right on read/write #define lcd_DisplayOff 0b00001000 // turn display off #define lcd_DisplayOn 0b00001100 // display on, cursor off, don't blink character #define lcd_FunctionReset 0b00110000 // reset the LCD #define lcd_FunctionSet8bit 0b00111000 // 8-bit data, 2-line display, 5 x 7 font #define lcd_SetCursor 0b10000000 // set cursor position // Program ID uint8_t program_author[] = "Donald Weiman"; uint8_t program_version[] = "LCD-AVR-8d-s (gcc)"; uint8_t program_date[] = "Sep 16, 2013"; // Function Prototypes void lcd_write_8(uint8_t); void lcd_write_instruction_8d(uint8_t); void lcd_write_character_8d(uint8_t); void lcd_write_string_8d(uint8_t *); void lcd_init_8d(void); /******************************* Main Program Code *************************/ int main(void) { // configure the microprocessor pins for the data lines lcd_data_ddr = 0xFF; // all 8 data lines - output // configure the microprocessor pins for the control lines lcd_E_ddr |= (1<