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 with multiple ports for character LCD

Status
Not open for further replies.

Winch

Member
Hello,
I work with an arduino leonardo PCB.
And use it together with a DFrobot LCD shield. (https://wiki.dfrobot.com/LCD_KeyPad_Shield_For_Arduino_SKU__DFR0009)

Now with this solution they have used multiple ports for the data flow!
To be precise:
D4 = portD.4
D5 = portC. 6
D6 = portD.7
D7 = portE. 6
The D4 etc. comes from the shield DFrobot PCB which has the standard pinout of the arduino.
But these D4, D5, D6, D7 are ultimately connected to multiple ports of the ATmega32U4!

Normally you do the following to Define the LCD:

Code:
Define LCD_BITS = 4
Define LCD_DREG = PORTD
Define LCD_DBIT = 4
Define LCD_RSREG = PORTB
Define LCD_RSBIT = 4
Define LCD_EREG = PORTB
Define LCD_EBIT = 5
Define LCD_RWREG = PORTB
Define LCD_RWBIT = 0

You use a port in this case, for example, the D port in the example above.
But now you have multiple LCD_DREG define how to fix this? Never done it before.
 
I take it you are not using the Arduino IDE... Are you using oshon basic?? If so you just write your own driver..

Arduino LCD shields never use a DREG variable..



lcdprint( character)
pin1 = character bit 1
pin2 = character bit 2
etc...

then Lcdinit()
write this
write that
etc...
 
Yes, for this I use the OshonSoft AVR Basic.
I just use the arduino Leonardo for the hardware together with the ICSP connector and the Oshonsoft Compiler.

But I think I'm going to find my solution in the fact that I'm going to place the display on a breadboard with a new pinning to the arduino.
This is getting too complicated for me.

Thanks for the effort anyway!
 
This is what I mean..

I did this for a pic.... Just change to suit your AVR
Code:
Define CONFIG = 0x3f71
Define CLOCK_FREQUENCY = 4
Dim addr As Word 'variable for storing EEPROM byte address
Dim data As Byte 'variable for storing EEPROM byte data
Dim bl As Byte
Dim rs As Byte
'data
Symbol d0 = PORTB.0
Symbol d1 = PORTB.1
Symbol d2 = PORTC.0
Symbol d3 = PORTC.1
'control
Symbol en = PORTB.2
Symbol cd = PORTB.3
TRISB = 0
TRISC = 0
Dim lcdoutput As String
Call lcdbegin()
main:  'endless loop
    data = 45
    Call cmdwrite(0x80)
    lcdoutput = "Testing = " + #data
    Call printstr(lcdoutput)
    Call cmdwrite(0xc0)
    data = 128
    lcdoutput = "Set = " + #data
    Call printstr(lcdoutput)

Goto main
End  'end program       
                        
Proc printstr(str As String)
Dim x As Byte
Dim ch As Byte
Dim idx As Byte
   Idx = Len(str) - 1
   For x = 0 To idx
         ch = Asc(str)
         Call datawrite(ch)
         str = LRotateStr(str)
   Next x
End Proc    
                                   
Proc lcdbegin()
   WaitMs 20
   Call cmdwrite(0x33)
   WaitMs 5
   Call cmdwrite(0x32)
   WaitMs 5
   Call cmdwrite(0x2c)
   WaitMs 1
   Call cmdwrite(0xc)
   WaitMs 1
   Call cmdwrite(0x6)
   WaitMs 1
   Call cmdwrite(0x1)
End Proc                                       
Proc datawrite(data As Byte)
   cd = 1
   d0 = data.4
   d1 = data.5
   d2 = data.6
   d3 = data.7
   en = 1
   WaitUs 100
   en = 0
   WaitMs 1
   d0 = data.0
   d1 = data.1
   d2 = data.2
   d3 = data.3
   en = 1
   WaitUs 100
   en = 0
   WaitMs 1
End Proc   
                                     
Proc cmdwrite(cmd As Byte)
   cd = 0
   d0 = cmd.4
   d1 = cmd.5
   d2 = cmd.6
   d3 = cmd.7
   en = 1
   WaitUs 100
   en = 0
   WaitMs 1
   d0 = cmd.0
   d1 = cmd.1
   d2 = cmd.2
   d3 = cmd.3
   en = 1
   WaitUs 100
   en = 0
   WaitMs 1

End Proc
 
Oké.
Thanks.
I have to admit when I have solved it, it is much easier to use it with the arduino Leonardo!
I'll study your code. Hoping I understand and can decipher it!
You will probably receive further questions in the coming days. :)
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top