Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Work on atmega32u4 with LCD connected to the PD0-PD3 ports

Status
Not open for further replies.

Winch

Member
Hello I have a question!
I have a 4x20 LCD connected to the DP0-PD3 port of an ATmega32u4 processor. The problem is that it won't work?
I suspect it has to do with the UART output of this port. But not sure.
I've already set up this design as a PCB. So I want to get it working on these PD0-PD3 outputs.
As a test, I imitated the same setup on an Arduino Leonardo and got the same picture.
When I connect it to eg PB4-PB7 port it works fine. So it's not the code. It must be the hardware.
Does it ultimately have to do with the fuses setup? Or should something else be done?
This is the image I get on the screen.

IMG20210630180202.jpg
 
I think you are trying to use active pins, eg. UART pins used when
woking with Arduino IDE ....?

1625085028454.png


Regards, Dana.
 
I believe that the active pins are the MISO, MOSI and SCK pins that you use as a programming connector, not the UART pin, they are just free.
In my opinion you should be able to use the PDO up to and including the PD3 pins for a display, right?
Or am I missing something?
 
I believe that the active pins are the MISO, MOSI and SCK pins that you use as a programming connector, not the UART pin, they are just free.
In my opinion you should be able to use the PDO up to and including the PD3 pins for a display, right?
Or am I missing something?

I've not used a Leonardo, but Uno's and Nano's use a bootloader, which uses a serial port to upload the code, the Leonardo uses a USB port. However, as far as I'm aware, those connections don't mess anything up, as they aren't connected to any of the Arduino I/O pins.

The programming connector isn't used, other than for installing the bootloader, if ever required.
 
From the docs -

The Arduino Leonardo board uses Serial1 to communicate via TTL (5V) serial on pins 0 (RX) and 1 (TX). Serial is reserved for USB CDC communication.

>


Regards, Dana.
 
I use the ICSP connector (MISO, MOSI and SCK) to program the atmega32u4. And use the ATMEL-ICE for that.
But these are used by PB1, PB2 and PB3 of the processor so has nothing to do with my problem.
My problem is with PD0 to PD3

Code:
'device ATmega32u4

Define CLOCK_FREQUENCY = 16

Define LCD_LINES = 4
Define LCD_CHARS = 20
Define LCD_BITS = 4
Define LCD_DREG = PORTD
Define LCD_DBIT = 4
Define LCD_RSREG = PORTC
Define LCD_RSBIT = 6
Define LCD_EREG = PORTC
Define LCD_EBIT = 7
Define LCD_RWREG = 0
Define LCD_RWBIT = 0

DDRC = 0xff  'Output
DDRD = 0x0f  'Output PD0 to PD3

Lcdinit 0
WaitMs 100

main:

Lcdcmdout LcdLine1Home
Lcdout " Test! "
WaitMs 100

Goto main
End
 
DDRD = B11111110; // sets Arduino pins 1 to 7 as outputs, pin 0 as input
DDRD = DDRD | B11111100; // this is safer as it sets pins 2 to 7 as outputs
// without changing the value of pins 0 & 1, which are RX & TX



Regards, Dana.
 
To Ian,
Admitted that 0x0f was not set correctly this must indeed be 0xf0.
But it makes no difference!

And to Danadak, I also tried this but no effect.
When I use this as code (DDRD = %11111111) I get this image.
So all four lines of the display. See the photo.

Four-lines.jpg


I keep getting the feeling that it is the output clock of leg PD0?
Does it have something to do with the basic fuse settings?

Code:
'device ATmega32u4

Define CLOCK_FREQUENCY = 16

Define LCD_LINES = 4
Define LCD_CHARS = 20
Define LCD_BITS = 4
Define LCD_DREG = PORTD
Define LCD_DBIT = 4
Define LCD_RSREG = PORTC
Define LCD_RSBIT = 6
Define LCD_EREG = PORTC
Define LCD_EBIT = 7
Define LCD_RWREG = 0
Define LCD_RWBIT = 0

DDRC = 0xff  'Output
DDRD = %11111111
'DDRD = %0xf0  'Output PD0 to PD3

Lcdinit 0
WaitMs 100

main:

Lcdcmdout LcdLine1Home
Lcdout " Test! "
WaitMs 100

Goto main
End
 
What is the controller chip on the LCD ? Is it Hitachi 44780 compatible ?


Regards, Dana.
 
Have you had a chance to look with logic analyzer data and commands fed to display ?


Regards, Dana.
 
I know this is a bit late in the day but I seem to remember Vadimir had a bug when using the low nibble for data...

If this be the case you will need to write one... It's a while ago, but It was on a pic so bear with me..
 
Well Ian Rogers you are my hero today!
The problem is solved. I can't believe my eyes!
But the big question is how could I have known this? Where did you get that information from?
I would like to know. (And I'm using the latest updates!)
Please send me a link to that page of his website.

Thanks Ian!

IMG20210702120756.jpg
 
I have been using Oshonsoft a long time... I also needed to use the lower nibble of a port but it didn't work.

I scanned the assembled file to see that it didn't compile correctly.. I did send a bug report to Vladimir, so when I saw the "DBIT" variable, I read the documentation.

website said:
Interfacing character LCDs

Basic compiler also features the support for LCD modules based on HD44780 or compatible controller chip. Prior to using LCD related statements, user should set up LCD interface using DEFINE directives. Here is the list of available parameters:
LCD_BITS - defines the number of data interface lines (allowed values are 4 and 8; default is 4)
LCD_DREG - defines the port where data lines are connected to (default is PORTB)
LCD_DBIT - defines the position of data lines for 4-bit interface (0 or 4; default is 4), ignored for 8-bit interface <----
LCD_RSREG - defines the port where RS line is connected to (default is PORTB)
LCD_RSBIT - defines the pin where RS line is connected to (default is 3)
LCD_EREG - defines the port where E line is connected to (default is PORTB)
LCD_EBIT - defines the pin where E line is connected to (default is 2)
LCD_RWREG - defines the port where R/W line is connected to (set to 0 if not used; 0 is default)
LCD_RWBIT - defines the pin where R/W line is connected to (set to 0 if not used; 0 is default)
LCD_COMMANDUS - defines the delay after LCDCMDOUT statement (default value is 5000)
LCD_DATAUS - defines the delay after LCDOUT statement (default value is 100)
LCD_INITMS - defines the delay for LCDINIT statement (default value is 100)
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top