problem about HD44780 LCD controller

Go To Last Post
13 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello! i wanna ask how to control LCD.

using mega128

 

here problem occurred.

From the lab board i was practicing, here RS, RW, E pin was connected to PORTC.

 

but to control BLCD motor, i had to design motor drive. 

so making PCB I changed RS, RW, E pin from PORTC to PORTF. 

 

and i changed main header file code of course.

 

#define LCD_RS_0    PORTF.5 = 0
#define LCD_RS_1    PORTF.5 = 1
#define LCD_RW_0    PORTF.6 = 0
#define LCD_RW_1    PORTF.6 = 1
#define LCD_E_0        PORTF.7 = 0
#define LCD_E_1        PORTF.7 = 1

 

and [the first argument of the '.' operator must be of 'struct' or 'union' type] comes up.

 i found out that PORTF is not used this way.

 

and again

 

#define LCD_RS_0    PORTF &= ~0x20
#define LCD_RS_1    PORTF |= 0x20
#define LCD_RW_0    PORTF &= ~0x40
#define LCD_RW_1    PORTF |= 0x40
#define LCD_E_0        PORTF &= ~0x80
#define LCD_E_1        PORTF |= 0x80

 

no error signal. 

 

but still HD44780 LCD doen't work.

 

there is two file, it looks related to LCD control 

lcd.h and lcd_control.c

 

no matter how i look at this code, 

it seems that i can control it with the pins redefined in main header file. 

 

 

Whats is it unhappy with?

Thank you for reading.. 

Hi! AVR

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

PF4-PF7 are JTAG pins on a mega128.

 

Disable JTAG in software.   Better than disable JTAGEN fuse in hardware.

Or better still,  move the LCD control pins to a different PORT.

 

David.

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

qufekf135 wrote:

there is two file, it looks related to LCD control 

lcd.h and lcd_control.c

You might want to say where you are seeing this. Which C compiler, which LCD library?

 

If the file originally had:

 

#define LCD_RS_0    PORTF.5 = 0

 

it suggests it was written for CodeVision (AFAIK the only AVr C compiler to support .n syntax).

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

david.prentice wrote:
Disable JTAG in software

If god gave you JTAG (or any other form of on-chip debug) in a chip, why on earth would you disable it?!

 

surprise

 

david.prentice wrote:
better still,  move the LCD control pins to a different PORT

Surely, the only sensible answer?

 

smiley

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:
#define LCD_RS_0    PORTF.5 = 0

 

it suggests it was written for CodeVision (AFAIK the only AVr C compiler to support .n syntax).

specifically, ".n syntax for accessing port bits"

 

EDIT: See clawson's correction/clarification in #6, below.

 

qufekf135 wrote:
and [the first argument of the '.' operator must be of 'struct' or 'union' type] comes up

So you're not using that one compiler which does support that notation for accessing port bits!

 

Which gives you 2 choices:

  1. Switch to the compiler which does support that;
  2. Re-write the code into standard 'C'.

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
Last Edited: Wed. Oct 9, 2019 - 09:27 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

awneil wrote:
specifically, ".n syntax for accessing port bits"
Err no, .n is not valid in C in whatever context you apply it. Anything beyond a dot is supposed to be a valid symbol name and symbols can't start with a digit. AFAIK Codevision would allow ADCSRA.7 = 1 to set ADSC etc. and that is not "port bits".

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

Ah, yes - I see what you mean.

 

I've added a note to my previous post.

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thank you David

 

It's first time i've heard about JTAG 

I'm gonna search how to JTAG disable in software. 

 

Hi! AVR

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

clawson wrote:

qufekf135 wrote:

there is two file, it looks related to LCD control 

lcd.h and lcd_control.c

You might want to say where you are seeing this. Which C compiler, which LCD library?

 

If the file originally had:

 

#define LCD_RS_0    PORTF.5 = 0

 

it suggests it was written for CodeVision (AFAIK the only AVr C compiler to support .n syntax).

 

Thank you for your comment. 

 

yeah i'm using CodeVision. 

 

Before i worked for my project which is BLDC motor control, 

 

.n syntax works.  when the pin(RS RW E) was connected to PORTC.

 

but i just wonder 

as soon as i changed that pin from PORTC to PORTF 

there is error. yeah i know .n syntax makes noise. 

 

so  I  Re-write the code into standard 'C'.

 

#define LCD_RS_0    PORTF &= ~0x20
#define LCD_RS_1    PORTF |= 0x20
#define LCD_RW_0    PORTF &= ~0x40
#define LCD_RW_1    PORTF |= 0x40
#define LCD_E_0        PORTF &= ~0x80
#define LCD_E_1        PORTF |= 0x80

 

this code works. bcause it's just to put 0 and 1. 

 

this is not a problem with how to put 0s and 1s on a pin well.

I think.

is there any hidden magic in PORTF??

 

plz help me  


 

this is code file

Attachment(s): 

Hi! AVR

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

Have you done the things David suggested to disable JTAG? This is far more likely to be about JTAG on PORTF than anything to do with your C syntax. Whether you use traditional |= or & =~ syntax or the .n extension in Codevision they all just generate the same SBI or CBI opcodes.

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

qufekf135 wrote:
is there any hidden magic in PORTF??

Did you not read post #2, then?

 

But see also #4.

 

.n syntax works

So why did you post that it didn't? you said that it gave you an error message!

 

 

there is error

Go on - what error, exactly?!

 

We can't help you to resolve the "error" when we don't know what it is!

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Seriously.   Codevision gives you LCD libraries.    You can configure them in the IDE.

 

It is always wise to use proven libraries  that come with your Compiler.

 

If you have any problems,  you can ask here or on the Codevision Yahoo Forum.

 

Concentrate on your project logic.   Do not waste time and effort on the LCD.

 

When the project is "working",   you can replace the LCD code with your own "design".    There is nothing wrong with writing your own low level LCD code if that is what you enjoy.

 

Regarding mega128.    Study datasheet for

1.   M103C fuse

2.   JTAGEN fuse

3.   JTD register bit

4.   ICSP pins do not use SPI pins

 

Otherwise,   mega128 just works like any other AVR.

 

David.

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

Alright 

Thank you all!

 

I 'm kind of jumping the gun now so..

 

I'll do one by one what you guys told me. 

Thank you!

Hi! AVR