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.

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



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'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.
 
Are you using the serial monitor as Danadak mentioned?? If so, show the code you used!
 
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
 
I hope you changed this line
DDRD = 0x0f 'Output PD0 to PD3..

As that is setting PD4~PD7 as out not the lower nibble..
DDRD = 0xF0 'Output PD0 to PD3.. sets the lower half to outputs
 
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.



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..
 
I have read through the data on Vlad's site... There is a DATA variable 0 for low and 4 for high

Define LCD_DBIT = 4

Can you try
Define LCD_DBIT = 0
 
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!

 
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.

 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…