Trying to Interface an LCD with an Atmega8A

Go To Last Post
63 posts / 0 new

Pages

Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello!

 

I have been trying for some time to wire a LCD up to my Atmega8A and have had no success. Here is a photo of my current set up:

 

 

Here is the code I am using:

#define F_CPU	4000000UL
#include <avr/delay.h>
#include <avr/io.h>
 
/*LCD function declarations */
void LCD_send_command(unsigned char cmnd);
void LCD_send_data(unsigned char data);
void LCD_init();
void LCD_goto(unsigned char y, unsigned char x);
void LCD_print(char *string);
void LCD_blink();
void LCD_scroll(unsigned char direction);
 
#define LCD_DATA_PORT	PORTD
#define LCD_DATA_DDR	DDRD
#define LCD_DATA_PIN	PIND
 
#define LCD_CNTRL_PORT	PORTC
#define LCD_CNTRL_DDR	DDRC
#define LCD_CNTRL_PIN	PINC
 
#define LCD_RS_PIN		0
#define LCD_RW_PIN		1
#define LCD_ENABLE_PIN	2
 
int main(void)
{
	unsigned char i; 
 
    LCD_init();
	LCD_goto(1,2);
	LCD_print("AVR TUTORIALS");
	LCD_goto(2,3);
	LCD_print("WELCOMES YOU");
 
	while(1)
    {
        for(i=0;i<2;i++)
			LCD_blink();
 
		for(i=0;i<2;i++)
			LCD_scroll(0);
 
		for(i=0;i<4;i++)
			LCD_scroll(1);
 
		for(i=0;i<2;i++)
			LCD_scroll(0);
    }
}
 
/* This function sends a command 'cmnd' to the LCD module*/
void LCD_send_command(unsigned char cmnd)
{
	LCD_DATA_PORT = cmnd;
	LCD_CNTRL_PORT &= ~(1<<LCD_RW_PIN);
	LCD_CNTRL_PORT &= ~(1<<LCD_RS_PIN);
 
	LCD_CNTRL_PORT |= (1<<LCD_ENABLE_PIN);
	_delay_us(2);
	LCD_CNTRL_PORT &= ~(1<<LCD_ENABLE_PIN);
	_delay_us(100);
}
 
/* This function sends the data 'data' to the LCD module*/
void LCD_send_data(unsigned char data)
{
	LCD_DATA_PORT = data;
	LCD_CNTRL_PORT &= ~(1<<LCD_RW_PIN);
	LCD_CNTRL_PORT |= (1<<LCD_RS_PIN);
 
	LCD_CNTRL_PORT |= (1<<LCD_ENABLE_PIN);
	_delay_us(2);
	LCD_CNTRL_PORT &= ~(1<<LCD_ENABLE_PIN);
	_delay_us(100);
}
 
void LCD_init()
{
	LCD_CNTRL_DDR = 0xFF;
	LCD_CNTRL_PORT = 0x00;
	LCD_DATA_DDR = 0xFF;
	LCD_DATA_PORT = 0x00;
 
	_delay_ms(10);
	LCD_send_command(0x38);
	LCD_send_command(0x0C);
	LCD_send_command(0x01);
	_delay_ms(10);
	LCD_send_command(0x06);
}
 
/* This function moves the cursor the line y column x on the LCD module*/
void LCD_goto(unsigned char y, unsigned char x)
{
	unsigned char firstAddress[] = {0x80,0xC0,0x94,0xD4};
 
	LCD_send_command(firstAddress[y-1] + x-1);
	_delay_ms(10);	
}
 
void LCD_print(char *string)
{
	unsigned char i;
 
	while(string[i]!=0)
	{
		LCD_send_data(string[i]);
		i++;
	}
}
 
void LCD_blink()
{
	LCD_send_command(0x08);
	_delay_ms(250);
	LCD_send_command(0x0C);
	_delay_ms(250);
}
 
void LCD_scroll(unsigned char direction)
{
	if(direction == 0)
		LCD_send_command(0x18);
	else
		LCD_send_command(0x1C);
 
	_delay_ms(500);
}

I am not super experienced with electronics and have no idea why this isnt working. I am running on a Mac using crosspack to upload my code. I set my clock to run on the internal RC oscillator at 4MHz and a startup time of 6ck + 64ms. Any and all help is appreciated!

 

Thank You!

 

 

- TheWT

Last Edited: Wed. Mar 4, 2015 - 09:53 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

From the number of jumper wires I suspect a wiring problem. This [link](http://extremeelectronics.co.in/...) has a tutorial explaining what I suspect you want to do. Are you able to blink a LED just so you can prove the processor is alive? 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes, I have blinked an led before and ill take a look at the link

 

- TheWT

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Your display is not being initialized properly.  You really should use the initialization sequence recommended in the datasheet flowcharts as opposed to the sequence used in their examples.

 

For more information follow the LCD Initialization link at http://web.alfredstate.edu/weimandn.  There are programming examples there as well.

 

Don

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Also loads more (proven/working) LCD code links here:

 

http://www.johanekdahl.se/rwiki/...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ok, so I tried the following code:

/* Simple LCD character display module demonstrator using
 * the 8-bit interface. No handling of the busy flag is
 * done - all timing contraints are handled by delay loops.
 * This code should be good to run at up to 8 MHz.
 * Above that you might have to tweak the timing of things
 * including, but not restricted to, the existing delays.
 */

#include <avr/io.h>
#include <util/delay.h>

/* Here are some defines for the data connections,
 * DB0..7 on the LCD display module. These should be wired
 * up to the eight bits of any port A..D. You need to alter
 * these to fit your wire up of your display.
 */
#define LCD_DATA_PORT PORTD
#define LCD_DATA_DDR  DDRD

/* Here are some defines for the control connections
 * (RS, R/W and E on the LCD display module). These can be wired
 * to any pins on any port A..D (all to the same port though).
 * You need to alter these to fit your wire up of your display.
 */
#define LCD_CTRL_PORT PORTC
#define LCD_CTRL_DDR  DDRC
#define LCD_RS        0
#define LCD_RW        1
#define LCD_E         2

/*
 * YOU SHOULD NOT NEED TO ALTER ANYTHING BEYOND THIS POINT!
 */

/* Here are some defines for the LCD instructions we'll use.
 */
#define LCD_FUNCTION_SET      0x38 // 0b00111000
#define LCD_DISPLAY_OFF       0x08 // 0b00001000
#define LCD_DISPLAY_ON        0x0F // 0b00001111
#define LCD_DISPLAY_CLEAR     0x01 // 0b00000001
#define LCD_ENTRY_MODE_SET    0x06 // 0b00000110
#define LCD_CURSOR_HOME       0x02 // 0b00000010
#define LCD_

/* LcdSendByte
 *
 * Sends a 8-bit byte to the display.
 *
 * Parameters:
 *	uint8_t theByte	The byte to send to the display
 *
 * Returns:
 *	nothing
 */
void LcdSendByte(uint8_t theByte)
{
    // Short delay needed here...
    _delay_us(50);
    // Output the byte
    LCD_DATA_PORT = theByte;
    // Toggle the E line
    LCD_CTRL_PORT |= (1<<LCD_E);   // Going up..
    // Short delay needed here...
    _delay_us(50);
    LCD_CTRL_PORT &= ~(1<<LCD_E);  // ..and down.
}

/* LcdSendInstruction
 *
 * Sends an instruction to the display.
 *
 * Parameters:
 *	uint8_t command	This byte is sent to the display as
 *					an instruction (RS low).
 * Returns:
 *	nothing
 */
void LcdSendInstruction(uint8_t theInstruction)
{
    // RS low
    LCD_CTRL_PORT &= ~(1<<LCD_RS);
    
    // Send it
    LcdSendByte(theInstruction);
}

/* LcdSendCharacter
 *
 * Sends a character to the display.
 *
 * Parameters:
 *	uint8_t nibble	This byte is sent to the display as
 *					a character (RS high).
 * Returns:
 *	nothing
 */
void LcdSendCharacter( uint8_t theChar )
{
    // RS high
    LCD_CTRL_PORT |= (1<<LCD_RS);
    
    // Send it
    LcdSendByte(theChar);
}

void LcdInitialize(void)
{
    // initialize LCD control lines
    LCD_CTRL_PORT &= ~(1<<LCD_RS);
    LCD_CTRL_PORT &= ~(1<<LCD_RW);
    LCD_CTRL_PORT &= ~(1<<LCD_E);
    
    // initialize LCD control lines to output
    LCD_CTRL_DDR |= (1<<LCD_RS);
    LCD_CTRL_DDR |= (1<<LCD_RW);
    LCD_CTRL_DDR |= (1<<LCD_E);
    
    // initialize LCD data port to output
    LCD_DATA_DDR = 0xFF;
    
    // First part of init sequence is 3 x Function Set with
    // stipulated waits (no Busy Flag available).
    _delay_ms(15);
    LcdSendInstruction( LCD_FUNCTION_SET );
    _delay_ms(5);
    LcdSendInstruction( LCD_FUNCTION_SET );
    _delay_us(100);
    LcdSendInstruction( LCD_FUNCTION_SET );
    _delay_ms(5);
    
    // We are now in 8-bit mode, and the busy flag is available.
    // Do the rest of the init sequence.
    LcdSendInstruction( LCD_FUNCTION_SET );
    LcdSendInstruction( LCD_DISPLAY_OFF );
    LcdSendInstruction( LCD_DISPLAY_CLEAR );
    _delay_ms(5);
    LcdSendInstruction( LCD_ENTRY_MODE_SET );
    LcdSendInstruction( LCD_DISPLAY_ON );
}

char message[] = "8-bit avr-gcc";

int main(void)
{
    LcdInitialize();
    
    volatile int i = 0;
    while (message[i] != 0)
    {
        LcdSendCharacter(message[i]);
        i++;
    }
    
    while(1);
    return 0;
}

and I still get bocks on the first row. I have RS, RW, and E wired to PortC on pins 0, 1, and 2. The data pins are wired on DDRD in order from 0-7 but still no text.

- TheWT

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

TheOnlyWT wrote:
Ok, so I tried the following code: [...] and I still get b[l]ocks on the first row. I have RS, RW, and E wired to PortC on pins 0, 1, and 2. The data pins are wired on DDRD in order from 0-7 but still no text.
Hi, WT... Welcome to the forums!

 

Several thoughts:

  1. Find the datasheet for your particular LCD.  You need to understand how to properly set the display contrast level to avoid "boxes".
  2. We're all assuming here that your LCD controller is the ubiquitous Hitachi HD44780.  You should confirm or deny that here to avoid possible confusion.  The datasheet is the "bible".
  3. A quick look at your code showed no problems to my eye (other than some delays which are longer than necessary, but that's far better than having delays that are shorter than necessary!).
     

    Then I realized that you're simply using Johan Ekdahl's 8-bit C code, which I'd assumed he'd tested.  Then I read this comment on his website, where you got that code:

     

     

       Work In Progress! Please note that this page is a work in progress. Do not trust anything here just yet!

     

     

    That makes me wonder whether he's actually tested this code (or the 4-bit variant) with real hardware.

  4. You're using 8-bit mode.  Frankly, there's no reason to waste 8 precious pins on an MCU for 8-bit LCD data.  You'd be better off using the 4-bit mode and saving 4 MCU pins.  I don't know of anyone who uses 8-bit mode.  And some libraries don't even bother to support 8-bit mode.

  5. If you switch to a proven library, confirm that you have a HD44780 LCD controller, and find that it doesn't work, then it's almost certainly a problem in your display contrast setup, a problem in your wiring, a broken MCU, or a broken LCD.

FWIW, my humble suggestion would be to re-wire for 4-bit mode, figure out the proper contrast setting, switch to using Peter Fleury's (well-proven, including by myself) "LCD library for HD44870 [sic] based LCD's [sic]", and tell us how that goes.  Otherwise, you get to the point where you depend on someone hooking up an LCD in 8-bit mode and trying that code, and I suspect that will be a long wait. frown

 

Aside @JohanEkdahl: Minor fix needed on your website...  Please remove "assembler" where it says "4-bit interface, written in assembler C".

 

Whatever path you take, please let us know how it goes and we'll provide more help as needed.  Good luck!

 

EDIT: Various cosmetic tweaks, mostly line spacing.  "WYSIWYG" editor is NOT WYSIWYG for numbered lists!

 

Regards,
Bill

 

Last Edited: Sun. Mar 1, 2015 - 01:15 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes, I am using the hitachi HD44780 LCD. The microcontroller does work as I have wired it on other projects and it has worked. And I would love to use a library, I just havent figured out how to link it in my makefile. I am going to rewire the LCD for 4-bit mode and see if that works. And any advice on how to get the makefile/library to work would be amazing!

 

Thank you!

 

EDIT: I rewired it to 4-bit and built the code below using the makefile from Peter's LCD library and flashed the .hex file to a new atmega8:

 

/*************************************************************************
Title:    Testing output to a HD44780 based LCD display.
Author:   Peter Fleury  <pfleury@gmx.ch>  http://tinyurl.com/peterfleury
File:     $Id: test_lcd.c,v 1.8 2015/01/31 18:04:08 peter Exp $
Software: AVR-GCC 4.x
Hardware: HD44780 compatible LCD text display
          AVR with external SRAM interface if memory-mapped LCD interface is used
          any AVR with 7 free I/O pins if 4-bit IO port mode is used
**************************************************************************/
#include <stdlib.h>
#include <avr/io.h>
#include <avr/pgmspace.h>
#include <util/delay.h>
#include "lcd.h"



int main(void)
{

    /* initialize display, cursor off */
    lcd_init(LCD_DISP_ON);


    //clear the screen
    lcd_clrscr();
          
    /* put string to display (line 1) with linefeed */
    lcd_puts("IF YOU SEE THIS\n");

    /* cursor is now on second line, write second line */
    lcd_puts("IT IS WORKING!");

}

my pins are set up according to Peter's 4-bit tutorial at http://homepage.hispeed.ch/peter... but I am using PORTD but still no text on the screen...

- TheWT

Last Edited: Sun. Mar 1, 2015 - 05:28 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

TheOnlyWT wrote:
Yes, I am using the hitachi HD44780 LCD. The microcontroller does work as I have wired it on other projects and it has worked.
Excellent.

 

TheOnlyWT wrote:
And I would love to use a library, I just havent figured out how to link it in my makefile.
You said you're running on a Mac using 'crosspack'.  I'm not familiar with compiling for AVRs on the Mac (I'm a Linux guy), but if you show us the makefile, one of us (maybe myself even) can undoubtedly suggest how to update it.

 

TheOnlyWT wrote:
but still no text on the screen...
But have you adjusted the LCD's contrast level?  Without that, you might see nothing at all, the proper text (in various levels of contrast from "almost unreadable" to "crisp 'n' clear"), or solid boxes.  If you can't find the datasheet or need help with this, let us know, but don't skip that step.  It's very important.

 

Regards,

Bill

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Forgot to also mention...  Since you're continuously clearing the display and writing to it, you should probably throw a '_delay_us(1000)' or similar after you write both lines to the LCD.  I'm not sure what the LCD display would look like otherwise!

 

EDIT: Waitaminute!  You're changing the code on me!  smiley  Now you're just falling off the end.  Don't do that either.  If you want, initialize the LCD and write 2 lines outside the 'do forever' loop, but put a 'do forever' loop (even a null one) after that -- don't just fall off the end of the 'main()' routine.

 

Bill

Last Edited: Sun. Mar 1, 2015 - 05:52 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I got rid of the whole infinite loop and just initialized the lcd, cleared the screen, then called the 2 draw commands. And I have a variable resistor hooked up to the contrast and have cycled through it and havent seen text. I'm not really sure what contrast I'm looking for to be honest. The code in my previous post is the most up to date code I have. And here is the makefile I am using:

 

# ----------------------------------------------------------------------------
# Makefile for lcd library
# Author: Peter Fleury
# File:   $Id: Makefile.lcd,v 1.5 2015/01/31 19:59:32 peter Exp $
#
# Adjust MCU and F_CPU below to your AVR target 
# Optionally define -D_LCD_DEFINITIONS_FILE in the CDEFS section below 
# if you want to use a separate file for display and target specific defines
#----------------------------------------------------------------------------
# usage:
#
# make          = build software
# make clean    = Clean out built project files
# make program  = Download the hex file to the device, using avrdude.
#                 Please customize the avrdude settings below first!
#
# make filename.s = Just compile filename.c into the assembler code only.
# make filename.i = Create a preprocessed source file 
#
# To rebuild project do "make clean" then "make"
#----------------------------------------------------------------------------


# MCU name
MCU = atmega8


# Processor frequency.
#     This will define a symbol, F_CPU, in all source code files equal to the 
#     processor frequency. You can then use this symbol in your source code to 
#     calculate timings. Do NOT tack on a 'UL' at the end, this will be done
#     automatically to create a 32-bit value in your source code.
F_CPU = 8000000


# Target file name (without extension).
TARGET =  test_lcd


# List C source files here. (C dependencies are automatically generated.)
SRC = $(TARGET).c  lcd.c 


# List Assembler source files here.
#     Make them always end in a capital .S.  Files ending in a lowercase .s
#     will not be considered source files but generated files (assembler
#     output from the compiler), and will be deleted upon "make clean"!
#     Even though the DOS/Win* filesystem matches both .s and .S the same,
#     it will preserve the spelling of the filenames, and gcc itself does
#     care about how the name is spelled on its command-line.
#ASRC = 


# List any extra directories to look for include files here.
#     Each directory must be seperated by a space.
#     Use forward slashes for directory separators.
#     For a directory that has spaces, enclose it in quotes.
EXTRAINCDIRS = 


#specify alternate location of sources files
#     (unlike VPATH= which is a search path for all prerequisites, not just source files)
#vpath %.c <directory>
#vpath %.S <directory>


# Optimization level, can be [0, 1, 2, 3, s]. 
#     0 = turn off optimization. s = optimize for size.
#     (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
OPT = s


# Place -D or -U options here
# Uncomment below line if you want to use a separate file lcd_definitions.h
# for display and target specific definitions
#CDEFS = -D_LCD_DEFINITIONS_FILE


# Place -I options here
CINCS =


#---------------- Compiler Options ----------------
#  -gdwarf-2:    generate debugging information
#  -O*:          optimization level
#  -f...:        tuning, see GCC manual and avr-libc documentation
#  -Wall...:     warning level
#  -Wa,...:      tell GCC to pass this to the assembler.
#    -adhlns...: create assembler listing
CFLAGS  = -DF_CPU=$(F_CPU)UL
CFLAGS += $(CDEFS) $(CINCS)
CFLAGS += -I. $(patsubst %,-I%,$(EXTRAINCDIRS))
CFLAGS += -std=gnu99
CFLAGS += -gdwarf-2
CFLAGS += -O$(OPT)
CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
CFLAGS += -Wall -Wstrict-prototypes
CFLAGS += -Wa,-adhlns=$(<:.c=.lst)
CFLAGS += -save-temps


#---------------- Assembler Options ----------------
#  -Wa,...:   tell GCC to pass this to the assembler.
#   -adhlns=$(<:.S=.lst)  create listing
#   -gdwarf-2:            generate debugging information
ASFLAGS = -DF_CPU=$(F_CPU)UL -x assembler-with-cpp -Wa,-gdwarf2

#---------------- Library Options ----------------
# Minimalistic printf version
PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min

# Floating point printf version (requires MATH_LIB = -lm below)
PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt

# If this is left blank, then it will use the Standard printf version.
PRINTF_LIB = 
#PRINTF_LIB = $(PRINTF_LIB_MIN)
#PRINTF_LIB = $(PRINTF_LIB_FLOAT)


# Minimalistic scanf version
SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min

# Floating point + %[ scanf version (requires MATH_LIB = -lm below)
SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt

# If this is left blank, then it will use the Standard scanf version.
SCANF_LIB = 
#SCANF_LIB = $(SCANF_LIB_MIN)
#SCANF_LIB = $(SCANF_LIB_FLOAT)


MATH_LIB = -lm



#---------------- External Memory Options ----------------

# 64 KB of external RAM, starting after internal RAM (ATmega128!),
# used for variables (.data/.bss) and heap (malloc()).
#EXTMEMOPTS = -Wl,-Tdata=0x801100,--defsym=__heap_end=0x80ffff

# 64 KB of external RAM, starting after internal RAM (ATmega128!),
# only used for heap (malloc()).
#EXTMEMOPTS = -Wl,--defsym=__heap_start=0x801100,--defsym=__heap_end=0x80ffff

EXTMEMOPTS =



#---------------- Linker Options ----------------
#  -Wl,...:     tell GCC to pass this to linker.
#    -Map:      create map file
#    --cref:    add cross reference to  map file
LDFLAGS = -Wl,-Map=$(TARGET).map,--cref
LDFLAGS += $(EXTMEMOPTS)
LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)



#---------------- Programming Options (avrdude) ----------------

# Programming hardware:   Type: avrdude -c ? to get a full listing.
AVRDUDE_PROGRAMMER = usbasp

# usb, com1 = serial port, lpt1 = parallel port 
AVRDUDE_PORT = USB

AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
#AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep

# Uncomment the following if you do /not/ wish a verification to be performed after programming the device.
#AVRDUDE_NO_VERIFY = -V

# Disable save mode for fuses
AVRDUDE_NO_SAFEMODE = -u

# Uncomment the following if you want avrdude's erase cycle counter.
# Note that this counter needs to be initialized first using -Yn,
#AVRDUDE_ERASE_COUNTER = -y

# Increase verbosity level.  
#AVRDUDE_VERBOSE = -v -v

# Adjust programming speed of USBasp
#  no -B switch 375khz (default)
#  -B 2000    	500 hz
#  -B 1000 			1khz
#  -B 500 			2khz
#  -B 250 			4khz
#  -B 125 			8 khz
#  -B 62 			  16khz
#  -B 31 				32khz * the cutoff for bit banged isp
#  -B 10 				93.75 khz 
#  -B 5 			  187.5 khz
#  -B 2 				375 khz
#  -B 1 				750 khz
#  -B .5 			  1.5mhz 
AVRDUDE_SPEED = -B .5

AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)
AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY)
AVRDUDE_FLAGS += $(AVRDUDE_NO_SAFEMODE)
AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER)
AVRDUDE_FLAGS += $(AVRDUDE_SPEED)
AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE)



#============================================================================
# Output format. (can be srec, ihex, binary)
FORMAT = ihex

# Define programs and commands.
#SHELL = win-bash
CC = avr-gcc
OBJCOPY = avr-objcopy
OBJDUMP = avr-objdump
SIZE = avr-size
NM = avr-nm
AVRDUDE = avrdude
REMOVE = rm -rf
COPY = cp
WINSHELL = cmd


# Define Messages
MSG_FLASH = Creating load file for Flash:
MSG_EEPROM = Creating load file for EEPROM:
MSG_EXTENDED_LISTING = Creating Extended Listing:
MSG_SYMBOL_TABLE = Creating Symbol Table:
MSG_LINKING = Linking:
MSG_COMPILING = Compiling:
MSG_ASSEMBLING = Assembling:
MSG_CLEANING = Cleaning project:



# Define all object files.
OBJ = $(SRC:.c=.o) $(ASRC:.S=.o)

# Define all listing files.
LST = $(SRC:.c=.lst) $(ASRC:.S=.lst) 


# Compiler flags to generate dependency files.
GENDEPFLAGS = -MD -MP -MF .dep/$(@F).d


# Combine all necessary flags and optional flags.
# Add target processor to flags.
ALL_CFLAGS = -mmcu=$(MCU) $(CFLAGS) $(GENDEPFLAGS)
ALL_ASFLAGS = -mmcu=$(MCU) -I. $(ASFLAGS)


# Default target.
all: gccversion $(TARGET).elf $(TARGET).hex $(TARGET).eep $(TARGET).lss $(TARGET).sym size


# Display compiler version information.
gccversion : 
	@echo $(OBJ1)
	@$(CC) --version


# Create final output files (.hex, .eep) from ELF output file.
%.hex: %.elf
	@echo $(MSG_FLASH) $@
	$(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@

%.eep: %.elf
	@echo $(MSG_EEPROM) $@
	-$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" --change-section-lma .eeprom=0 -O $(FORMAT) $< $@ 

# Create extended listing file from ELF output file.
%.lss: %.elf
	@echo $(MSG_EXTENDED_LISTING) $@
	$(OBJDUMP) -h -S $< > $@

# Create a symbol table from ELF output file.
%.sym: %.elf
	@echo $(MSG_SYMBOL_TABLE) $@
	$(NM) -n $< > $@

# Link: create ELF output file from object files.
.SECONDARY : $(TARGET).elf
.PRECIOUS : $(OBJ)
%.elf: $(OBJ)
	@echo $(MSG_LINKING) $@
	$(CC) -mmcu=$(MCU) $(LDFLAGS) $^ --output $(@F) 

# Compile: create object files from C source files.
%.o : %.c
	@echo $(MSG_COMPILING) $<
	$(CC) -c $(ALL_CFLAGS) $< -o $(@F)

# Compile: create assembler files from C source files.
%.s : %.c
	$(CC) -S $(ALL_CFLAGS) $< -o $(@F)

# Assemble: create object files from assembler source files.
%.o : %.S
	@echo $(MSG_ASSEMBLING) $<
	$(CC) -c $(ALL_ASFLAGS) $< -o $(@F)

# Create preprocessed source for use in sending a bug report.
%.i : %.c
	$(CC) -E -mmcu=$(MCU) -I. $(CFLAGS) $< -o $(@F) 


# Display size of file.
size: ${TARGET}.elf
	@avr-size -C --mcu=${MCU} ${TARGET}.elf


# Program the device.  
program: $(TARGET).hex $(TARGET).eep
	$(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)


# Delete all generated files.
clean:
	@echo $(MSG_CLEANING)
	$(REMOVE) $(TARGET).hex $(TARGET).eep $(TARGET).cof $(TARGET).elf $(TARGET).map $(TARGET).sym $(TARGET).lss $(OBJ) $(LST) $(SRC:.c=.s) $(SRC:.c=.d) $(SRC:.c=.i) .dep/


# Include the dependency files.
#-include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*) 
-include $(shell mkdir .dep 2>NUL) $(wildcard .dep/*)


# Listing of phony targets.
.PHONY : all size gccversion clean program

as for crosspack, I just build the project in Xcode using the makefile and then use command line to flash the hex file onto the atmega8.

 

Thanks Again!

- TheWT

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

TheOnlyWT wrote:
I got rid of the whole infinite loop [...]
Don't do that.  See my edit to my previous post.

 

TheOnlyWT wrote:
And I have a variable resistor hooked up to the contrast and have cycled through it and havent seen text. I'm not really sure what contrast I'm looking for to be honest.
OK, good.  Have you seen filled boxes (where characters would be) at one end of the resistor's range?  If so, then dial it down a bit below that for now.  If not, then I'd be concerned that you don't have the variable contrast resistor hooked up correctly. 

 

BTW, what specific model of LCD is this?  Did you ever find a datasheet for it?  If so, please point us to it.  If not, point us to where you bought this LCD, if applicable.

 

TheOnlyWT wrote:
And here is the makefile I am using:
OK, but that's just Peter's makefile.  Other than the fact that you failed to adjust from his 8 MHz default to match your 4 MHz MCU clock speed, there's no need to further tweak that.  (I thought you had a makefile of your own that needed Peter's library added.  If you do, we can deal with that after you get the LCD working.)

 

Oh, and did you properly tweak Peter's 'lcd.h' file to match your LCD's capabilities?

 

I don't have an LCD wired up at the moment, but if need be, I might find time to hook one up tomorrow, assuming you can't get Peter's test code working with his library.

 

Fix the 8 MHz thing and, if needed, the 'lcd.h' settings and let us know how that works....

 

Bill

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ok, I initialized the LCD and cleared the screen outside of the for(;;) loop, and drew the two lines inside of it, but no text crying

 

Yes, I have seen the filled boxes (only on the top line though) and I dialed back the resistor until just after the boxes disappeared.

 

I fixed the 8 MHz to 4 MHz and changed lcd.h to fit my wiring settings but still not text on the lcd.

 

I bought the lcd from here: http://www.ebay.com/itm/1602-128...

 

I am using Peter's makefile. Here is the code to the makefile I was using before I switched to Peter's:

 

# Name: Makefile
# Author: <insert your name here>
# Copyright: <insert your copyright message here>
# License: <insert your license reference here>

# This is a prototype Makefile. Modify it according to your needs.
# You should at least check the settings for
# DEVICE ....... The AVR device you compile for
# CLOCK ........ Target AVR clock rate in Hertz
# OBJECTS ...... The object files created from your source files. This list is
#                usually the same as the list of source files with suffix ".o".
# PROGRAMMER ... Options to avrdude which define the hardware you use for
#                uploading to the AVR and the interface where this hardware
#                is connected. We recommend that you leave it undefined and
#                add settings like this to your ~/.avrduderc file:
#                   default_programmer = "stk500v2"
#                   default_serial = "avrdoper"
# FUSES ........ Parameters for avrdude to flash the fuses appropriately.

DEVICE     = atmega8
CLOCK      = 4000000
PROGRAMMER = #-c stk500v2 -P avrdoper
OBJECTS    = main.o
FUSES      = -U hfuse:w:0xd9:m -U lfuse:w:0x24:m

# ATMega8 fuse bits used above (fuse bits for other devices are different!):
# Example for 8 MHz internal oscillator
# Fuse high byte:
# 0xd9 = 1 1 0 1   1 0 0 1 <-- BOOTRST (boot reset vector at 0x0000)
#        ^ ^ ^ ^   ^ ^ ^------ BOOTSZ0
#        | | | |   | +-------- BOOTSZ1
#        | | | |   +---------- EESAVE (set to 0 to preserve EEPROM over chip erase)
#        | | | +-------------- CKOPT (clock option, depends on oscillator type)
#        | | +---------------- SPIEN (if set to 1, serial programming is disabled)
#        | +------------------ WDTON (if set to 0, watchdog is always on)
#        +-------------------- RSTDISBL (if set to 0, RESET pin is disabled)
# Fuse low byte:
# 0x24 = 0 0 1 0   0 1 0 0
#        ^ ^ \ /   \--+--/
#        | |  |       +------- CKSEL 3..0 (8M internal RC)
#        | |  +--------------- SUT 1..0 (slowly rising power)
#        | +------------------ BODEN (if 0, brown-out detector is enabled)
#        +-------------------- BODLEVEL (if 0: 4V, if 1: 2.7V)
#
# For computing fuse byte values for other devices and options see
# the fuse bit calculator at http://www.engbedded.com/fusecalc/


# Tune the lines below only if you know what you are doing:

AVRDUDE = avrdude $(PROGRAMMER) -p $(DEVICE)
COMPILE = avr-gcc -Wall -Os -DF_CPU=$(CLOCK) -mmcu=$(DEVICE)

# symbolic targets:
all:	main.hex

.c.o:
	$(COMPILE) -c $< -o $@

.S.o:
	$(COMPILE) -x assembler-with-cpp -c $< -o $@
# "-x assembler-with-cpp" should not be necessary since this is the default
# file type for the .S (with capital S) extension. However, upper case
# characters are not always preserved on Windows. To ensure WinAVR
# compatibility define the file type manually.

.c.s:
	$(COMPILE) -S $< -o $@

flash:	all
	$(AVRDUDE) -U flash:w:main.hex:i

fuse:
	$(AVRDUDE) $(FUSES)

# Xcode uses the Makefile targets "", "clean" and "install"
install: flash fuse

# if you use a bootloader, change the command below appropriately:
load: all
	bootloadHID main.hex

clean:
	rm -f main.hex main.elf $(OBJECTS)

# file targets:
main.elf: $(OBJECTS)
	$(COMPILE) -o main.elf $(OBJECTS)

main.hex: main.elf
	rm -f main.hex
	avr-objcopy -j .text -j .data -O ihex main.elf main.hex
	avr-size --format=avr --mcu=$(DEVICE) main.elf
# If you have an EEPROM section, you must also create a hex file for the
# EEPROM and add it to the "flash" target.

# Targets for code debugging and analysis:
disasm:	main.elf
	avr-objdump -d main.elf

cpp:
	$(COMPILE) -E main.c

The settings on that one may be off, but that one has been working for my MCU LED and button projects. Sorry that this is taking so long to figure out, but I want to see why this is working easily for everyone but me.

 

Thanks!

- TheWT

- TheWT

Last Edited: Sun. Mar 1, 2015 - 07:04 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

TheOnlyWT wrote:
Ok, I initialized the LCD and cleared the screen outside of the for(;;) loop, and drew the two lines inside of it, but no text crying
No need to continuously draw the lines inside the do-forever loop, but, no matter.  As long as you're not falling off the main routine or clearing the LCD continuously with no delay, that's much better!

 

TheOnlyWT wrote:
Yes, I have seen the filled boxes and I dialed back the resistor until just after the boxes disappeared.
Good.

 

TheOnlyWT wrote:
I fixed the 8 MHz to 4 MHz and changed lcd.h to fit my wiring settings but still not text on the lcd.
OK, assuming you were quite careful there, then you should have been seeing something by now.

 

So let's start considering other possibilities....

 

Which pins of the LCD did you hook the 4 data lines to?  All LCDs I've seen use the upper bits (DB4-DB7), not DB0-DB3 as one might expect.

 

Are you positive that the ATMega8A is really running at 4 MHz?  Have you flashed an LCD LED using that setup to prove it?  I hope this doesn't sound condescending, but a lot of people are under the mistaken impression that simply altering the 'F_CPU' setting in a makefile or some source code is all that's needed.  It's not.

 

Did you connect the voltage to both the Vcc and AVcc pins on your ATMega8A?   Did you connect both GND pins of the ATMega8A?  Do you have proper (e.g. 0.1-uF ceramic) capacitors between Vcc/GND and AVcc/GND?

 

Good.  I wish you'd said that a while back. smiley

There's a datasheet for this "WaveShare LCD 1602" LCD at that site, in the zip file.  Download it!  It has a wealth of information.

 

TheOnlyWT wrote:
I am using Peter's makefile.
Good.  Keep doing so for now.

 

TheOnlyWT wrote:
Here is the code to the makefile I was using before I switched to Peter's:
Good to have seen it, but let's deal with that later.

 

TheOnlyWT wrote:
Sorry that this is taking so long to figure out, but I want to see why this is working easily for everyone but me.
No problem... There are a myriad of things that can be wrong, so it may take some time, but I'm reasonably confident we'll get you sorted away eventually.

 

There's what I consider semi-conflicting information in that datasheet, but let's proceed the way we are for a bit longer.

 

Edit #1: Fix names of LCD pins.

 

Edit #2: "LCD" -> "LED"

 

Bill

 

Last Edited: Tue. Mar 3, 2015 - 08:20 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You haven't mentioned the row of blocks** since post #6 so it is not clear if you have gotten past that point.  If you can't correctly initialize the display then no amount of code is going to help you. 

 

There is no sense trying anything fancy until you can get rid of the row of blocks and display a simple message on the first row of your display.  You want to make sure that this simple message is not subsequently overwritten with junk or blanks so it is best to initially stay away from loops and just end the program after sending the information to the display.

 

You have to first establish the fact that your display is wired correctly and that it is functional.  Unfortunately these have to be done simultaneously and the best way to proceed is to use known working code.  Have you looked at any of the example code that I mentioned back in reply #4?  The same examples are referenced in Johan's information that is mentioned in reply #5.

 

Don

 

EDIT: ** I searched for 'blocks' and 'bocks' but you are now calling them 'boxes'.

Last Edited: Sun. Mar 1, 2015 - 04:06 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I just spotted these two comments:

 

Reply #12

OK, good.  Have you seen filled boxes (where characters would be) at one end of the resistor's range?  If so, then dial it down a bit below that for now.  If not, then I'd be concerned that you don't have the variable contrast resistor hooked up correctly. 

 

Reply #13

Yes, I have seen the filled boxes (only on the top line though) and I dialed back the resistor until just after the boxes disappeared.

 

It looks like you still have an initialization problem.  Post #12 is referring to the case where ALL of the character positions show blocks.  When  you are talking about blocks in every character position then this would be the correct way to adjust the contrast.

 

On the other hand reply #13 says that there are blocks on the first line only.  The device is still not initialized properly so you are not ready to proceed.

 

Don

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Well then how do I fix the initialization? I am using Peter's trusted library and his initialization functions, but do you know how to fix it?

- TheWT

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

... but do you know how to fix it?

Just how many times do I have to point you to code that works?  Here it is again:  For more information follow the LCD Initialization link at http://web.alfredstate.edu/weimandn.  There are programming examples there as well.

 

Don

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have tried all of those code examples and none of them have worked.........

- TheWT

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

OK, so if known good code is not working then it must be a hardware problem.

 

Go back and check your wiring. If it still doesn't work then please post a detailed list of the connections. (ie pin xxx on my uC goes to pin yy on my LCD display)

'This forum helps those who help themselves.'

 

pragmatic  adjective dealing with things sensibly and realistically in a way that is based on practical rather than theoretical consideration.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Buy an Arduino UNO or clone.

Connect your LCD with your current wiring.

 

Edit an example sketch for the constructor() in the lcd class to reflect your current wiring.

Verify that your hardware works.     You should find a visible contrast with pin#3 connected to GND.   (or the potentiometer is near 0V)

 

When you know that the hardware works,   simply build your Fleury example for the ATmega328P on the UNO.    i.e. do not change the wiring.

 

If it works on the ATmega328P,   it will work on an ATmega8A.

 

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

TheOnlyWT wrote:
I have tried all of those code examples and none of them have worked.........

WT, you're repeatedly having problems and yet you don't bother to answer a single one of the questions from my last post!

 

How (and, maybe equally importantly, "Why") do you expect someone to help you when you seemingly cannot be bothered to answer a single one of their questions?!?

 

For the record, I strongly agree with every bit of advice you've gotten from Brian Fairchild.

 

I know that Peter Fleury's code works (although there's a potential minor issue with his code that I didn't and won't mention because it won't affect your current setup).  Since my last post, I've also run LCD guru ('floresta1212') Don Weiman's sample code and it too (unsurprisingly) works fine.

 

If you want any further help from me, then kindly take the time to answer the questions that I've taken the time to compose -- past, present, and future.  Then follow Brian's sage advice.

 

Bill

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Given the tone in your most recent post, I do not like be treated like a child. I wish no further help from you Bill.

 

-TheWT

- TheWT

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Try soldering the pins on your LCD module.

 

Don

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

 

Ok, let's take a step back here for a moment everybody.

 

WT, help me out a little bit here with a couple of questions I have from my brief skimming of the thread.

 

1) what is the IDE environment you are using? Atmel Studio, Arduino?

 

2) Can you post a schematic of your connections in the picture in your OP?

 

3) Are you using a Crystal or internal Oscillator of the Mega8?

 

4) I saw AvrDude mentioned in a post, is that what you are using?(important question)

 

 

I use Peter Fleury's LCD library and it works for me every time, so how about we work with that one, and once we have it running then play with some of the other excellent LCD libraries tat have been suggested?

From what I have read so far I would hedge that there is a hardware issue, but rather than jump to conclusions let's start over a little and get the four questions I have resolved, then move forward.

 

Sound good? smiley

 

Jim

If you want a career with a known path - become an undertaker. Dead people don't sue! - Kartman

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

1) what is the IDE environment you are using? Atmel Studio, Arduino?

I am using a Mac and am using Xcode to develop my code and CrossPack to flash it to my device. 

 

Can you post a schematic of your connections in the picture in your OP?

Here is the schematic I have currently:

 

 Are you using a Crystal or internal Oscillator of the Mega8?

I am using the internal oscillator. I believe I have set the fuses correctly to run at 4 MHz, but there may be an issue there: but I'm not sure.

 

 I use Peter Fleury's LCD library and it works for me every time, so how about we work with that one,

I would prefer to use his and that is the current library I am using.

 

 And yes, I am planning on soldering the pins of the LCD soon, but I haven't had time for that yet.

 

EDIT: Just checked all of my connections and ~4.2 volts is being sent into the LCD. I wondering if the issue is that the LCD pins are not soldered? 

EDIT: I just checked the are of the LCD where it should be soldered, and the voltage was ~1.5 volts. So that is most likely the issue. I'll solder it tomorrow and try and see if it works then.

- TheWT

Last Edited: Wed. Mar 4, 2015 - 05:09 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Can you post your code modifications to peters library? I see you are using two ports to control the lcd and peters code is set up to use one port. Also how are you getting 4MHZ out of the internal oscillator?

If you are indeed running the AVR at 4MHZ you have to change a setting in the lcd library to reflect this

Jim

If you want a career with a known path - become an undertaker. Dead people don't sue! - Kartman

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

 And yes, I am planning on soldering the pins of the LCD soon, but I haven't had time for that yet.

Your LCD will not function reliably, if at all, if the connections to it are not soldered.  You are wasting our time.

 

Edit:  Your potentiometer is not wired properly in your drawing.  I doubt it is actually connected that way since your display (and your power supply) still appear to be working.

 

Don

Last Edited: Wed. Mar 4, 2015 - 12:58 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi Don,

 

It could work.

 

If the pot is really wired as per diagram it will work if the wiper is near the contrast end.  Of course the closer the wiper gets to the other end the lower the resistance between the grounded wiper and +5v which will draw more and more current....

 

David

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Please read the following (Cliff too.....)

http://www.avrfreaks.net/forum/d...

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Note that LCD modules are quite slow to awaken at power-up.  Certainly an AVR8 is ready to go after a power-on much sooner than an LCD module.  So if you haven't already, delay at least 100ms after AVR startup before trying to initialize the LCD module.

 

Note that one powered on for a while, you could test that theory by resetting the AVR instead of re-powering and see if that changes anything.

 

Long[ish] wires can cause problems.  Especially a ratty signal on the E line.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
#define LCD_CNTRL_PORT	PORTC

Are all Vcc and Gnd pins connected, and all pairs properly decoupled?  (I'm thinking AVcc...)

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I am not super experienced with electronics

So let's check a few hardware items, mentioned but not spelled out explicitly, above:

 

On the uC ALL Vcc pins must be tied to V+. 

On the uC AVcc must be tied to V+

On the uC ALL Ground pins must be tied to Ground.

 

Across every one of the Vcc/Ground and AVcc/Ground pair of pins you should have a by-pass capacitor, a 0.1uf Cap, placed as close to the body of the uC chip as possible.

 

Then go fix the contrast pot.

One end goes to V+, the other end goes to Ground.

The wiper goes to the Contrast Pin on the LCD.

 

Solder you LCD to a head or wires.  Otherwise you are wasting your time.

 

JC

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I had not noticed that the LCD does not appear to be soldered at all.

I had assumed that it was soldered to some male header strip,   which was plugged into the mini-breadboard.

 

If you have proper contacts with the LCD (and 100nF capacitors on VCC),    a breadboard lash-up should work.

 

I would suggest that the OP uses 4-bit mode and puts everything on one breadboard.

Then chooses consistent colours for her jumper wires.

 

Take a photo that shows all the jumper wires clearly.   e.g. from above.

 

LCD threads go on forever.   It should be a simple task to follow an LCD tutorial and wire up neatly.

Then it would work first time.

 

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I had not noticed that the LCD does not appear to be soldered at all.

This was pointed out and acknowledged (in thread #26) but not corrected since the OP hasn't had the time to do so.  There's not much sense proposing any more 'solutions' until this is taken care of.

 

Don

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Please read the following (Cliff too.....)

http://www.avrfreaks.net/forum/do-not-post-forum

John:

 

Your concern is obviously justified but there is a fundamental problem with the forum (no surprise here) that is a contributing factor.

 

An inexperienced poster may indeed put his question in the wrong place but under the circumstances outlined below this may not be apparent to even an experienced responder.

 

I and at least some others use "Recent Discussions" to determine which forum posts to read and possibly respond to.  Unfortunately, using this technique, there is no way to tell which forum section a post is actually in until you actually open it. 

 

Only after you have opened the thread can you determine the forum section in which it is located.   The information is not very prominent, it's a part of the breadcrumb listing near the top of the page.  To be honest I never have given a thought to looking up there.

 

When I am done reading and answering I do have to go the the "Forums" section because another thing missing from the "Recent Discussions" page is a way to mark all topics read.

 

Don

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ok, before this thread derails any more than it already has, if a debate on the naming of the project forum, and what happens if someone makes a mistake and posts a question there please start a new thread in Site Feedback where it belongs.

 

To the OP - WT,

As noted there is really no need to go further until the following parameters have been taken care of:

 

1) solder pins/lead wires to the display.

2) connect the contrast pot correctly.

3) post all the code you have written so far, and any modifications to Peter Fleury's library.

4) as David mentioned a few over head and side pictures of the connections you have might help, but I am inclined to say you will probably be doing some rewiring.

 

Thank You

Jim

If you want a career with a known path - become an undertaker. Dead people don't sue! - Kartman

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB user

Last Edited: Thu. Mar 5, 2015 - 12:44 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ok, before this thread derails any more than it already has, if a debate on the naming of the project forum, and what happens if someone makes a mistake and posts a question there please start a new thread in Site Feedback where it belongs.

Jim:  This thread has not been derailed, it is merely mired.  Every post is on the topic of how to get the OP's display functioning except those by two moderators and my responses. 

 

Don

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

And let's keep it that way.  Thanks! smiley

 

JIm

If you want a career with a known path - become an undertaker. Dead people don't sue! - Kartman

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Sorry for such a delayed reply. I have been busy with school and school sports. Here is what I have done according to you checklist above: 

1) solder pins/lead wires to the display.

Done.

 

 2) connect the contrast pot correctly.

Done. The variable resistor is adjusting the contrast. There is a picture of full contrast below.

 

 

3) post all the code you have written so far, and any modifications to Peter Fleury's library.

Here is the code I have so far:

 

Main.c :

#include <avr/io.h>
#include <util/delay.h>
#include "lcd.h"

int main(void)
{
    lcd_init(LCD_DISP_ON_CURSOR); /* initialize lcd, display on, cursor on */
    // for more options for
     // lcd_init(), view lcd.h file
     while(1)                      /* run continuously */
    {
        lcd_clrscr();             /* clear screen of lcd */
        lcd_home();               /* bring cursor to 0,0 */
        lcd_puts("IT IS");        /* type something random */
        lcd_gotoxy(0,1);          /* go to 2nd row 1st col */
        lcd_puts("WORKING");  /* type something random */
        _delay_ms(50);            /* wait 50ms */
    }
}






 

lcd.h:

#ifndef LCD_H
#define LCD_H
/*************************************************************************
 Title	:   C include file for the HD44780U LCD library (lcd.c)
 Author:    Peter Fleury <pfleury@gmx.ch>  http://tinyurl.com/peterfleury
 File:	    $Id: lcd.h,v 1.14.2.4 2015/01/20 17:16:07 peter Exp $
 Software:  AVR-GCC 4.x
 Hardware:  any AVR device, memory mapped mode only for AVR with 
            memory mapped interface (AT90S8515/ATmega8515/ATmega128)
***************************************************************************/

/**
 @mainpage
 Collection of libraries for AVR-GCC
 @author Peter Fleury pfleury@gmx.ch http://tinyurl.com/peterfleury
 @copyright (C) 2015 Peter Fleury, GNU General Public License Version 3
 
 @file
 @defgroup pfleury_lcd LCD library <lcd.h>
 @code #include <lcd.h> @endcode
 
 @brief Basic routines for interfacing a HD44780U-based character LCD display

 LCD character displays can be found in many devices, like espresso machines, laser printers. 
 The Hitachi HD44780 controller and its compatible controllers like Samsung KS0066U have become an industry standard for these types of displays. 
 
 This library allows easy interfacing with a HD44780 compatible display and can be
 operated in memory mapped mode (LCD_IO_MODE defined as 0 in the include file lcd.h.) or in 
 4-bit IO port mode (LCD_IO_MODE defined as 1). 8-bit IO port mode is not supported.

 Memory mapped mode is compatible with old Kanda STK200 starter kit, but also supports
 generation of R/W signal through A8 address line.

 @see The chapter <a href=" http://homepage.hispeed.ch/peterfleury/avr-lcd44780.html" target="_blank">Interfacing a HD44780 Based LCD to an AVR</a>
      on my home page, which shows example circuits how to connect an LCD to an AVR controller. 

 @author Peter Fleury pfleury@gmx.ch http://tinyurl.com/peterfleury
 
 @version   2.0
 
 @copyright (C) 2015 Peter Fleury, GNU General Public License Version 3
  
*/

#include <inttypes.h>
#include <avr/pgmspace.h>

#if (__GNUC__ * 100 + __GNUC_MINOR__) < 405
#error "This library requires AVR-GCC 4.5 or later, update to newer AVR-GCC compiler !"
#endif


/**@{*/

/*
 * LCD and target specific definitions below can be defined in a separate include file with name lcd_definitions.h instead modifying this file 
 * by adding -D_LCD_DEFINITIONS_FILE to the CDEFS section in the Makefile
 * All definitions added to the file lcd_definitions.h will override the default definitions from lcd.h
 */
#ifdef _LCD_DEFINITIONS_FILE
//#include "lcd_definitions.h"
#endif


/**
 * @name  Definition for LCD controller type
 * Use 0 for HD44780 controller, change to 1 for displays with KS0073 controller.
 */
#ifndef LCD_CONTROLLER_KS0073 
#define LCD_CONTROLLER_KS0073 0  /**< Use 0 for HD44780 controller, 1 for KS0073 controller */
#endif

/** 
 * @name  Definitions for Display Size 
 * Change these definitions to adapt setting to your display
 *
 * These definitions can be defined in a separate include file \b lcd_definitions.h instead modifying this file by 
 * adding -D_LCD_DEFINITIONS_FILE to the CDEFS section in the Makefile.
 * All definitions added to the file lcd_definitions.h will override the default definitions from lcd.h
 *
 */
#ifndef LCD_LINES
#define LCD_LINES           2     /**< number of visible lines of the display */
#endif
#ifndef LCD_DISP_LENGTH
#define LCD_DISP_LENGTH    16     /**< visibles characters per line of the display */
#endif
#ifndef LCD_LINE_LENGTH
#define LCD_LINE_LENGTH  0x40     /**< internal line length of the display    */
#endif
#ifndef LCD_START_LINE1
#define LCD_START_LINE1  0x00     /**< DDRAM address of first char of line 1 */
#endif
#ifndef LCD_START_LINE2
#define LCD_START_LINE2  0x40     /**< DDRAM address of first char of line 2 */
#endif
#ifndef LCD_START_LINE3
#define LCD_START_LINE3  0x14     /**< DDRAM address of first char of line 3 */
#endif
#ifndef LCD_START_LINE4
#define LCD_START_LINE4  0x54     /**< DDRAM address of first char of line 4 */
#endif
#ifndef LCD_WRAP_LINES
#define LCD_WRAP_LINES      0     /**< 0: no wrap, 1: wrap at end of visibile line */
#endif


/**
 * @name Definitions for 4-bit IO mode
 *
 * The four LCD data lines and the three control lines RS, RW, E can be on the 
 * same port or on different ports. 
 * Change LCD_RS_PORT, LCD_RW_PORT, LCD_E_PORT if you want the control lines on
 * different ports. 
 *
 * Normally the four data lines should be mapped to bit 0..3 on one port, but it
 * is possible to connect these data lines in different order or even on different
 * ports by adapting the LCD_DATAx_PORT and LCD_DATAx_PIN definitions.
 *
 * Adjust these definitions to your target.\n 
 * These definitions can be defined in a separate include file \b lcd_definitions.h instead modifying this file by 
 * adding \b -D_LCD_DEFINITIONS_FILE to the \b CDEFS section in the Makefile.
 * All definitions added to the file lcd_definitions.h will override the default definitions from lcd.h
 *  
 */
#define LCD_IO_MODE      1            /**< 0: memory mapped mode, 1: IO port mode */

#if LCD_IO_MODE

#ifndef LCD_PORT
#define LCD_PORT         PORTD        /**< port for the LCD lines   */
#endif
#ifndef LCD_DATA0_PORT
#define LCD_DATA0_PORT   LCD_PORT     /**< port for 4bit data bit 0 */
#endif
#ifndef LCD_DATA1_PORT
#define LCD_DATA1_PORT   LCD_PORT     /**< port for 4bit data bit 1 */
#endif
#ifndef LCD_DATA2_PORT
#define LCD_DATA2_PORT   LCD_PORT     /**< port for 4bit data bit 2 */
#endif
#ifndef LCD_DATA3_PORT
#define LCD_DATA3_PORT   LCD_PORT     /**< port for 4bit data bit 3 */
#endif
#ifndef LCD_DATA0_PIN
#define LCD_DATA0_PIN    0            /**< pin for 4bit data bit 0  */
#endif
#ifndef LCD_DATA1_PIN
#define LCD_DATA1_PIN    1            /**< pin for 4bit data bit 1  */
#endif
#ifndef LCD_DATA2_PIN
#define LCD_DATA2_PIN    2            /**< pin for 4bit data bit 2  */
#endif
#ifndef LCD_DATA3_PIN
#define LCD_DATA3_PIN    3            /**< pin for 4bit data bit 3  */
#endif
#ifndef LCD_RS_PORT
#define LCD_RS_PORT      LCD_PORT     /**< port for RS line         */
#endif
#ifndef LCD_RS_PIN
#define LCD_RS_PIN       4            /**< pin  for RS line         */
#endif
#ifndef LCD_RW_PORT
#define LCD_RW_PORT      LCD_PORT     /**< port for RW line         */
#endif
#ifndef LCD_RW_PIN
#define LCD_RW_PIN       5            /**< pin  for RW line         */
#endif
#ifndef LCD_E_PORT
#define LCD_E_PORT       LCD_PORT     /**< port for Enable line     */
#endif
#ifndef LCD_E_PIN
#define LCD_E_PIN        6            /**< pin  for Enable line     */
#endif

#elif defined(__AVR_AT90S4414__) || defined(__AVR_AT90S8515__) || defined(__AVR_ATmega64__) || \
      defined(__AVR_ATmega8515__)|| defined(__AVR_ATmega103__) || defined(__AVR_ATmega128__) || \
      defined(__AVR_ATmega161__) || defined(__AVR_ATmega162__)
/*
 * memory mapped mode is only supported when the device has an external data memory interface
 */
#define LCD_IO_DATA      0xC000    /* A15=E=1, A14=RS=1                 */
#define LCD_IO_FUNCTION  0x8000    /* A15=E=1, A14=RS=0                 */
#define LCD_IO_READ      0x0100    /* A8 =R/W=1 (R/W: 1=Read, 0=Write   */

#else
#error "external data memory interface not available for this device, use 4-bit IO port mode"

#endif


/**
 * @name Definitions of delays
 * Used to calculate delay timers.
 * Adapt the F_CPU define in the Makefile to the clock frequency in Hz of your target
 *
 * These delay times can be adjusted, if some displays require different delays.\n 
 * These definitions can be defined in a separate include file \b lcd_definitions.h instead modifying this file by 
 * adding \b -D_LCD_DEFINITIONS_FILE to the \b CDEFS section in the Makefile.
 * All definitions added to the file lcd_definitions.h will override the default definitions from lcd.h
 */
#ifndef LCD_DELAY_BOOTUP
#define LCD_DELAY_BOOTUP   16000      /**< delay in micro seconds after power-on  */
#endif
#ifndef LCD_DELAY_INIT
#define LCD_DELAY_INIT      5000      /**< delay in micro seconds after initialization command sent  */
#endif
#ifndef LCD_DELAY_INIT_REP
#define LCD_DELAY_INIT_REP    64      /**< delay in micro seconds after initialization command repeated */
#endif
#ifndef LCD_DELAY_INIT_4BIT
#define LCD_DELAY_INIT_4BIT   64      /**< delay in micro seconds after setting 4-bit mode */ 
#endif
#ifndef LCD_DELAY_BUSY_FLAG
#define LCD_DELAY_BUSY_FLAG    4      /**< time in micro seconds the address counter is updated after busy flag is cleared */
#endif
#ifndef LCD_DELAY_ENABLE_PULSE
#define LCD_DELAY_ENABLE_PULSE 1      /**< enable signal pulse width in micro seconds */
#endif


/**
 * @name Definitions for LCD command instructions
 * The constants define the various LCD controller instructions which can be passed to the 
 * function lcd_command(), see HD44780 data sheet for a complete description.
 */

/* instruction register bit positions, see HD44780U data sheet */
#define LCD_CLR               0      /* DB0: clear display                  */
#define LCD_HOME              1      /* DB1: return to home position        */
#define LCD_ENTRY_MODE        2      /* DB2: set entry mode                 */
#define LCD_ENTRY_INC         1      /*   DB1: 1=increment, 0=decrement     */
#define LCD_ENTRY_SHIFT       0      /*   DB2: 1=display shift on           */
#define LCD_ON                3      /* DB3: turn lcd/cursor on             */
#define LCD_ON_DISPLAY        2      /*   DB2: turn display on              */
#define LCD_ON_CURSOR         1      /*   DB1: turn cursor on               */
#define LCD_ON_BLINK          0      /*     DB0: blinking cursor ?          */
#define LCD_MOVE              4      /* DB4: move cursor/display            */
#define LCD_MOVE_DISP         3      /*   DB3: move display (0-> cursor) ?  */
#define LCD_MOVE_RIGHT        2      /*   DB2: move right (0-> left) ?      */
#define LCD_FUNCTION          5      /* DB5: function set                   */
#define LCD_FUNCTION_8BIT     4      /*   DB4: set 8BIT mode (0->4BIT mode) */
#define LCD_FUNCTION_2LINES   3      /*   DB3: two lines (0->one line)      */
#define LCD_FUNCTION_10DOTS   2      /*   DB2: 5x10 font (0->5x7 font)      */
#define LCD_CGRAM             6      /* DB6: set CG RAM address             */
#define LCD_DDRAM             7      /* DB7: set DD RAM address             */
#define LCD_BUSY              7      /* DB7: LCD is busy                    */

/* set entry mode: display shift on/off, dec/inc cursor move direction */
#define LCD_ENTRY_DEC            0x04   /* display shift off, dec cursor move dir */
#define LCD_ENTRY_DEC_SHIFT      0x05   /* display shift on,  dec cursor move dir */
#define LCD_ENTRY_INC_           0x06   /* display shift off, inc cursor move dir */
#define LCD_ENTRY_INC_SHIFT      0x07   /* display shift on,  inc cursor move dir */

/* display on/off, cursor on/off, blinking char at cursor position */
#define LCD_DISP_OFF             0x08   /* display off                            */
#define LCD_DISP_ON              0x0C   /* display on, cursor off                 */
#define LCD_DISP_ON_BLINK        0x0D   /* display on, cursor off, blink char     */
#define LCD_DISP_ON_CURSOR       0x0E   /* display on, cursor on                  */
#define LCD_DISP_ON_CURSOR_BLINK 0x0F   /* display on, cursor on, blink char      */

/* move cursor/shift display */
#define LCD_MOVE_CURSOR_LEFT     0x10   /* move cursor left  (decrement)          */
#define LCD_MOVE_CURSOR_RIGHT    0x14   /* move cursor right (increment)          */
#define LCD_MOVE_DISP_LEFT       0x18   /* shift display left                     */
#define LCD_MOVE_DISP_RIGHT      0x1C   /* shift display right                    */

/* function set: set interface data length and number of display lines */
#define LCD_FUNCTION_4BIT_1LINE  0x20   /* 4-bit interface, single line, 5x7 dots */
#define LCD_FUNCTION_4BIT_2LINES 0x28   /* 4-bit interface, dual line,   5x7 dots */
#define LCD_FUNCTION_8BIT_1LINE  0x30   /* 8-bit interface, single line, 5x7 dots */
#define LCD_FUNCTION_8BIT_2LINES 0x38   /* 8-bit interface, dual line,   5x7 dots */


#define LCD_MODE_DEFAULT     ((1<<LCD_ENTRY_MODE) | (1<<LCD_ENTRY_INC) )



/** 
 *  @name Functions
 */


/**
 @brief    Initialize display and select type of cursor
 @param    dispAttr \b LCD_DISP_OFF display off\n
                    \b LCD_DISP_ON display on, cursor off\n
                    \b LCD_DISP_ON_CURSOR display on, cursor on\n
                    \b LCD_DISP_ON_CURSOR_BLINK display on, cursor on flashing             
 @return  none
*/
extern void lcd_init(uint8_t dispAttr);


/**
 @brief    Clear display and set cursor to home position
 @return   none
*/
extern void lcd_clrscr(void);


/**
 @brief    Set cursor to home position
 @return   none
*/
extern void lcd_home(void);


/**
 @brief    Set cursor to specified position
 
 @param    x horizontal position\n (0: left most position)
 @param    y vertical position\n   (0: first line)
 @return   none
*/
extern void lcd_gotoxy(uint8_t x, uint8_t y);


/**
 @brief    Display character at current cursor position
 @param    c character to be displayed                                       
 @return   none
*/
extern void lcd_putc(char c);


/**
 @brief    Display string without auto linefeed
 @param    s string to be displayed                                        
 @return   none
*/
extern void lcd_puts(const char *s);


/**
 @brief    Display string from program memory without auto linefeed
 @param    progmem_s string from program memory be be displayed                                        
 @return   none
 @see      lcd_puts_P
*/
extern void lcd_puts_p(const char *progmem_s);


/**
 @brief    Send LCD controller instruction command
 @param    cmd instruction to send to LCD controller, see HD44780 data sheet
 @return   none
*/
extern void lcd_command(uint8_t cmd);


/**
 @brief    Send data byte to LCD controller 
 
 Similar to lcd_putc(), but without interpreting LF
 @param    data byte to send to LCD controller, see HD44780 data sheet
 @return   none
*/
extern void lcd_data(uint8_t data);


/**
 @brief macros for automatically storing string constant in program memory
*/
#define lcd_puts_P(__s)         lcd_puts_p(PSTR(__s))

/**@}*/

#endif //LCD_H

 

makefile:

# ----------------------------------------------------------------------------
# Makefile for lcd library
# Author: Peter Fleury
# File:   $Id: Makefile.lcd,v 1.5 2015/01/31 19:59:32 peter Exp $
#
# Adjust MCU and F_CPU below to your AVR target 
# Optionally define -D_LCD_DEFINITIONS_FILE in the CDEFS section below 
# if you want to use a separate file for display and target specific defines
#----------------------------------------------------------------------------
# usage:
#
# make          = build software
# make clean    = Clean out built project files
# make program  = Download the hex file to the device, using avrdude.
#                 Please customize the avrdude settings below first!
#
# make filename.s = Just compile filename.c into the assembler code only.
# make filename.i = Create a preprocessed source file 
#
# To rebuild project do "make clean" then "make"
#----------------------------------------------------------------------------


# MCU name
MCU = atmega8


# Processor frequency.
#     This will define a symbol, F_CPU, in all source code files equal to the 
#     processor frequency. You can then use this symbol in your source code to 
#     calculate timings. Do NOT tack on a 'UL' at the end, this will be done
#     automatically to create a 32-bit value in your source code.
F_CPU = 4000000


# Target file name (without extension).
TARGET =  test_lcd


# List C source files here. (C dependencies are automatically generated.)
SRC = $(TARGET).c  lcd.c 


# List Assembler source files here.
#     Make them always end in a capital .S.  Files ending in a lowercase .s
#     will not be considered source files but generated files (assembler
#     output from the compiler), and will be deleted upon "make clean"!
#     Even though the DOS/Win* filesystem matches both .s and .S the same,
#     it will preserve the spelling of the filenames, and gcc itself does
#     care about how the name is spelled on its command-line.
#ASRC = 


# List any extra directories to look for include files here.
#     Each directory must be seperated by a space.
#     Use forward slashes for directory separators.
#     For a directory that has spaces, enclose it in quotes.
EXTRAINCDIRS = 


#specify alternate location of sources files
#     (unlike VPATH= which is a search path for all prerequisites, not just source files)
#vpath %.c <directory>
#vpath %.S <directory>


# Optimization level, can be [0, 1, 2, 3, s]. 
#     0 = turn off optimization. s = optimize for size.
#     (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
OPT = s


# Place -D or -U options here
# Uncomment below line if you want to use a separate file lcd_definitions.h
# for display and target specific definitions
#CDEFS = -D_LCD_DEFINITIONS_FILE


# Place -I options here
CINCS =


#---------------- Compiler Options ----------------
#  -gdwarf-2:    generate debugging information
#  -O*:          optimization level
#  -f...:        tuning, see GCC manual and avr-libc documentation
#  -Wall...:     warning level
#  -Wa,...:      tell GCC to pass this to the assembler.
#    -adhlns...: create assembler listing
CFLAGS  = -DF_CPU=$(F_CPU)UL
CFLAGS += $(CDEFS) $(CINCS)
CFLAGS += -I. $(patsubst %,-I%,$(EXTRAINCDIRS))
CFLAGS += -std=gnu99
CFLAGS += -gdwarf-2
CFLAGS += -O$(OPT)
CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
CFLAGS += -Wall -Wstrict-prototypes
CFLAGS += -Wa,-adhlns=$(<:.c=.lst)
CFLAGS += -save-temps


#---------------- Assembler Options ----------------
#  -Wa,...:   tell GCC to pass this to the assembler.
#   -adhlns=$(<:.S=.lst)  create listing
#   -gdwarf-2:            generate debugging information
ASFLAGS = -DF_CPU=$(F_CPU)UL -x assembler-with-cpp -Wa,-gdwarf2

#---------------- Library Options ----------------
# Minimalistic printf version
PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min

# Floating point printf version (requires MATH_LIB = -lm below)
PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt

# If this is left blank, then it will use the Standard printf version.
PRINTF_LIB = 
#PRINTF_LIB = $(PRINTF_LIB_MIN)
#PRINTF_LIB = $(PRINTF_LIB_FLOAT)


# Minimalistic scanf version
SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min

# Floating point + %[ scanf version (requires MATH_LIB = -lm below)
SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt

# If this is left blank, then it will use the Standard scanf version.
SCANF_LIB = 
#SCANF_LIB = $(SCANF_LIB_MIN)
#SCANF_LIB = $(SCANF_LIB_FLOAT)


MATH_LIB = -lm



#---------------- External Memory Options ----------------

# 64 KB of external RAM, starting after internal RAM (ATmega128!),
# used for variables (.data/.bss) and heap (malloc()).
#EXTMEMOPTS = -Wl,-Tdata=0x801100,--defsym=__heap_end=0x80ffff

# 64 KB of external RAM, starting after internal RAM (ATmega128!),
# only used for heap (malloc()).
#EXTMEMOPTS = -Wl,--defsym=__heap_start=0x801100,--defsym=__heap_end=0x80ffff

EXTMEMOPTS =



#---------------- Linker Options ----------------
#  -Wl,...:     tell GCC to pass this to linker.
#    -Map:      create map file
#    --cref:    add cross reference to  map file
LDFLAGS = -Wl,-Map=$(TARGET).map,--cref
LDFLAGS += $(EXTMEMOPTS)
LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)



#---------------- Programming Options (avrdude) ----------------

# Programming hardware:   Type: avrdude -c ? to get a full listing.
AVRDUDE_PROGRAMMER = usbasp

# usb, com1 = serial port, lpt1 = parallel port 
AVRDUDE_PORT = USB

AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
#AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep

# Uncomment the following if you do /not/ wish a verification to be performed after programming the device.
#AVRDUDE_NO_VERIFY = -V

# Disable save mode for fuses
AVRDUDE_NO_SAFEMODE = -u

# Uncomment the following if you want avrdude's erase cycle counter.
# Note that this counter needs to be initialized first using -Yn,
#AVRDUDE_ERASE_COUNTER = -y

# Increase verbosity level.  
#AVRDUDE_VERBOSE = -v -v

# Adjust programming speed of USBasp
#  no -B switch 375khz (default)
#  -B 2000    	500 hz
#  -B 1000 			1khz
#  -B 500 			2khz
#  -B 250 			4khz
#  -B 125 			8 khz
#  -B 62 			  16khz
#  -B 31 				32khz * the cutoff for bit banged isp
#  -B 10 				93.75 khz 
#  -B 5 			  187.5 khz
#  -B 2 				375 khz
#  -B 1 				750 khz
#  -B .5 			  1.5mhz 
AVRDUDE_SPEED = -B .5

AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)
AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY)
AVRDUDE_FLAGS += $(AVRDUDE_NO_SAFEMODE)
AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER)
AVRDUDE_FLAGS += $(AVRDUDE_SPEED)
AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE)



#============================================================================
# Output format. (can be srec, ihex, binary)
FORMAT = ihex

# Define programs and commands.
#SHELL = win-bash
CC = avr-gcc
OBJCOPY = avr-objcopy
OBJDUMP = avr-objdump
SIZE = avr-size
NM = avr-nm
AVRDUDE = avrdude
REMOVE = rm -rf
COPY = cp
WINSHELL = cmd


# Define Messages
MSG_FLASH = Creating load file for Flash:
MSG_EEPROM = Creating load file for EEPROM:
MSG_EXTENDED_LISTING = Creating Extended Listing:
MSG_SYMBOL_TABLE = Creating Symbol Table:
MSG_LINKING = Linking:
MSG_COMPILING = Compiling:
MSG_ASSEMBLING = Assembling:
MSG_CLEANING = Cleaning project:



# Define all object files.
OBJ = $(SRC:.c=.o) $(ASRC:.S=.o)

# Define all listing files.
LST = $(SRC:.c=.lst) $(ASRC:.S=.lst) 


# Compiler flags to generate dependency files.
GENDEPFLAGS = -MD -MP -MF .dep/$(@F).d


# Combine all necessary flags and optional flags.
# Add target processor to flags.
ALL_CFLAGS = -mmcu=$(MCU) $(CFLAGS) $(GENDEPFLAGS)
ALL_ASFLAGS = -mmcu=$(MCU) -I. $(ASFLAGS)


# Default target.
all: gccversion $(TARGET).elf $(TARGET).hex $(TARGET).eep $(TARGET).lss $(TARGET).sym size


# Display compiler version information.
gccversion : 
	@echo $(OBJ1)
	@$(CC) --version


# Create final output files (.hex, .eep) from ELF output file.
%.hex: %.elf
	@echo $(MSG_FLASH) $@
	$(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@

%.eep: %.elf
	@echo $(MSG_EEPROM) $@
	-$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" --change-section-lma .eeprom=0 -O $(FORMAT) $< $@ 

# Create extended listing file from ELF output file.
%.lss: %.elf
	@echo $(MSG_EXTENDED_LISTING) $@
	$(OBJDUMP) -h -S $< > $@

# Create a symbol table from ELF output file.
%.sym: %.elf
	@echo $(MSG_SYMBOL_TABLE) $@
	$(NM) -n $< > $@

# Link: create ELF output file from object files.
.SECONDARY : $(TARGET).elf
.PRECIOUS : $(OBJ)
%.elf: $(OBJ)
	@echo $(MSG_LINKING) $@
	$(CC) -mmcu=$(MCU) $(LDFLAGS) $^ --output $(@F) 

# Compile: create object files from C source files.
%.o : %.c
	@echo $(MSG_COMPILING) $<
	$(CC) -c $(ALL_CFLAGS) $< -o $(@F)

# Compile: create assembler files from C source files.
%.s : %.c
	$(CC) -S $(ALL_CFLAGS) $< -o $(@F)

# Assemble: create object files from assembler source files.
%.o : %.S
	@echo $(MSG_ASSEMBLING) $<
	$(CC) -c $(ALL_ASFLAGS) $< -o $(@F)

# Create preprocessed source for use in sending a bug report.
%.i : %.c
	$(CC) -E -mmcu=$(MCU) -I. $(CFLAGS) $< -o $(@F) 


# Display size of file.
size: ${TARGET}.elf
	@avr-size -C --mcu=${MCU} ${TARGET}.elf


# Program the device.  
program: $(TARGET).hex $(TARGET).eep
	$(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)


# Delete all generated files.
clean:
	@echo $(MSG_CLEANING)
	$(REMOVE) $(TARGET).hex $(TARGET).eep $(TARGET).cof $(TARGET).elf $(TARGET).map $(TARGET).sym $(TARGET).lss $(OBJ) $(LST) $(SRC:.c=.s) $(SRC:.c=.d) $(SRC:.c=.i) .dep/


# Include the dependency files.
#-include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*) 
-include $(shell mkdir .dep 2>NUL) $(wildcard .dep/*)


# Listing of phony targets.
.PHONY : all size gccversion clean program

The lcd is wired to an Atmega8A.

 

4) as David mentioned a few over head and side pictures of the connections you have might help, but I am inclined to say you will probably be doing some rewiring.

Here are some pictures (Also, the lcd is receiving 5.4 volts to power it):

 

once again, thanks for helping such a n00b like me!!

- TheWT

Last Edited: Wed. Mar 18, 2015 - 05:50 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
     while(1)                      /* run continuously */
    {
        lcd_clrscr();             /* clear screen of lcd */
        lcd_home();               /* bring cursor to 0,0 */
        lcd_puts("IT IS");        /* type something random */
        lcd_gotoxy(0,1);          /* go to 2nd row 1st col */
        lcd_puts("WORKING");  /* type something random */
        _delay_ms(50);            /* wait 50ms */
    }

I've not read the rest of the thread but just to note that the 50ms delay in there is a bit ambitious! You are going to be clearing and then rewriting the display 20 times a second. It's going to look like an explosion in a flicker factory!

 

If you want to show something "happening" on the LCD then how about parting the clrscr() outside the while(1) then just keep going to some x,y and keep printing an uint that you are incrementing from 0..65535 or something. That will show the display being updated but you won't be clearing the entire thing each time round the loop. For something like an incrementing number you *may* get away with doing an update every 50ms but note that these LCD modules tend to use Super-twist Nematic (STN) LCD material and the on/off pixel switching time is something like 200ms (5 updates per second) and if you attempt to turn things on/off quicker than this it will just look like a blurry mess.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

As Cliff says,    you only need to clear the whole screen when you want a 'fresh start'

Otherwise,   you can simply overwrite the message.

 

LCDs can be updated far faster than a human can read.    If you do it too often,   everything looks blurry.

 

Incidentally,    all LCD commands and writes complete in < 50us except for CLEAR and HOME.    And the CLEAR sets the cursor to HOME automatically.

 

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What is the frequency the avr is running at and how is it created? The value of the clock must b defined in the led library- there is a line for it in the .h file IIRC. This is for the E line timing and the delays during the unit phase.

Jim

If you want a career with a known path - become an undertaker. Dead people don't sue! - Kartman

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The mcu is running at 4 MHz and i set it to that using the following command via terminal:

avrdude -c USBasp -p atmega8 -U lfuse:w:0xe3:m -U hfuse:w:0xd9:m

And I did no find a IIRC in the lcd.h file.

 

@clawson:

I moved the lcd_clrscr() outside of the while loop and I still just see boxes and no text as I adjust the contrast.

- TheWT

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'll try to stay out of this as much as possible since there are a bunch of potential helpers present already. Here are some sanity-check-advice:

 

1) Since you have differing contrasts on line 1 and 2 you still have an initialization problem. Look no further ATM.

 

2) While keeping the F_CPU in the makefile at 4 MHz actually lower the CPU clock frequency to something lower or much lower (e.g. 1 MHz, or 100 KHz) if possible. If things suddenly start working then you have a timing problem somewhere.

 

3) Measure all signals. Especially since you use breadboards. Are all GNDs and VCC/VDD at the levels they sghould be? Measure at the LCD pins. If you have a logic probe, make sure you see activity on the control and data pins if you do a "cold start".

"He used to carry his guitar in a gunny sack, or sit beneath the tree by the railroad track. Oh the engineers would see him sitting in the shade, Strumming with the rhythm that the drivers made. People passing by, they would stop and say, "Oh, my, what that little country boy could play!" [Chuck Berry]

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The lcd is receiving 5.4 volts. RS and RW are reading 5.4 volts as well. E isnt reading anything and pin D5 (lcd) connected to pin D1 on the mcu is reading 5.4 volts as well. Every other connecting (excluding backlight and contrast) arent reading anything.

 

Whole new development, Xcode has been using the wrong makefile this whole time (not the one above).... despite the fact I removed the reference to the old one. I replaced the code in the old makefile with the code from the new one and I get a build error now:

make: *** No rule to make target 'test_lcd.o', needed by 'test_lcd.elf'.  Stop.
Command /usr/bin/make failed with exit code 2

I am not good with makefiles, so I have no idea how to fix this.

- TheWT

Last Edited: Wed. Mar 18, 2015 - 04:58 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What it's saying is that test_lcd.o cannot be built (presumably from test_lcd.c) for some reason. Either the file name is wrong or the file is not where it is looking or there are build errors.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Do you know how to fix that? Maybe better, here is the makefile that works:

# Name: Makefile
# Author: <insert your name here>
# Copyright: <insert your copyright message here>
# License: <insert your license reference here>

# This is a prototype Makefile. Modify it according to your needs.
# You should at least check the settings for
# DEVICE ....... The AVR device you compile for
# CLOCK ........ Target AVR clock rate in Hertz
# OBJECTS ...... The object files created from your source files. This list is
#                usually the same as the list of source files with suffix ".o".
# PROGRAMMER ... Options to avrdude which define the hardware you use for
#                uploading to the AVR and the interface where this hardware
#                is connected. We recommend that you leave it undefined and
#                add settings like this to your ~/.avrduderc file:
#                   default_programmer = "stk500v2"
#                   default_serial = "avrdoper"
# FUSES ........ Parameters for avrdude to flash the fuses appropriately.

DEVICE     = atmega8
CLOCK      = 4000000
PROGRAMMER = #-c stk500v2 -P avrdoper
OBJECTS    = main.o
FUSES      = -U hfuse:w:0xd9:m -U lfuse:w:0x24:m

# ATMega8 fuse bits used above (fuse bits for other devices are different!):
# Example for 8 MHz internal oscillator
# Fuse high byte:
# 0xd9 = 1 1 0 1   1 0 0 1 <-- BOOTRST (boot reset vector at 0x0000)
#        ^ ^ ^ ^   ^ ^ ^------ BOOTSZ0
#        | | | |   | +-------- BOOTSZ1
#        | | | |   +---------- EESAVE (set to 0 to preserve EEPROM over chip erase)
#        | | | +-------------- CKOPT (clock option, depends on oscillator type)
#        | | +---------------- SPIEN (if set to 1, serial programming is disabled)
#        | +------------------ WDTON (if set to 0, watchdog is always on)
#        +-------------------- RSTDISBL (if set to 0, RESET pin is disabled)
# Fuse low byte:
# 0x24 = 0 0 1 0   0 1 0 0
#        ^ ^ \ /   \--+--/
#        | |  |       +------- CKSEL 3..0 (8M internal RC)
#        | |  +--------------- SUT 1..0 (slowly rising power)
#        | +------------------ BODEN (if 0, brown-out detector is enabled)
#        +-------------------- BODLEVEL (if 0: 4V, if 1: 2.7V)
#
# For computing fuse byte values for other devices and options see
# the fuse bit calculator at http://www.engbedded.com/fusecalc/


# Tune the lines below only if you know what you are doing:

AVRDUDE = avrdude $(PROGRAMMER) -p $(DEVICE)
COMPILE = avr-gcc -Wall -Os -DF_CPU=$(CLOCK) -mmcu=$(DEVICE)

# symbolic targets:
all:	main.hex

.c.o:
	$(COMPILE) -c $< -o $@

.S.o:
	$(COMPILE) -x assembler-with-cpp -c $< -o $@
# "-x assembler-with-cpp" should not be necessary since this is the default
# file type for the .S (with capital S) extension. However, upper case
# characters are not always preserved on Windows. To ensure WinAVR
# compatibility define the file type manually.

.c.s:
	$(COMPILE) -S $< -o $@

flash:	all
	$(AVRDUDE) -U flash:w:main.hex:i

fuse:
	$(AVRDUDE) $(FUSES)

# Xcode uses the Makefile targets "", "clean" and "install"
install: flash fuse

# if you use a bootloader, change the command below appropriately:
load: all
	bootloadHID main.hex

clean:
	rm -f main.hex main.elf $(OBJECTS)

# file targets:
main.elf: $(OBJECTS)
	$(COMPILE) -o main.elf $(OBJECTS)

main.hex: main.elf
	rm -f main.hex
	avr-objcopy -j .text -j .data -O ihex main.elf main.hex
	avr-size --format=avr --mcu=$(DEVICE) main.elf
# If you have an EEPROM section, you must also create a hex file for the
# EEPROM and add it to the "flash" target.

# Targets for code debugging and analysis:
disasm:	main.elf
	avr-objdump -d main.elf

cpp:
	$(COMPILE) -E main.c

How would I add an include for the lcd.c and lcd.h files?

- TheWT

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Back to Fleury's code.  I looked and the line I was thinking about is in the .h file for the CPU frequency


/** 
 *  @name  Definitions for MCU Clock Frequency
 *  Adapt the MCU clock frequency in Hz to your target. 
 */
#define XTAL 4000000              /**< clock frequency in Hz, used to calculate delay timer */

 

 

JIm

If you want a career with a known path - become an undertaker. Dead people don't sue! - Kartman

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I do not see that line of code in my lcd.h file, should I add it?

 

- TheWT

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Is there something that says you have to use Makefiles? Can you not make use of an IDE of some sort? It will generate the Makefile for you without errors. Failing that look for Mfile and use that.

Pages