Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

problem with 40x4 LCD
Goto page 1, 2  Next
 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR
View previous topic :: View next topic  
Author Message
pierscintilla

Bascom Member



Joined: 08 Aug 2005
Posts: 54
Location: italy

PostPosted: Tue Oct 26, 2021 3:10 pm    Post subject: problem with 40x4 LCD Reply with quote

HI to all.
I have a problem with a 40X4 LCD (maybe only for the simulation).
I am using version 2.0.8.4 of the compiler and a chip ATMEGA328.
After going crazy with a source that I'm writing and, not having the hw at hand, I'm trying to simulate the lcdcustom4bit2e.bas example that uses the lcd4e2.lbx library.
I have followed everything indicated and what I have found so far on the internet but absolutely nothing continues to appear on the LCD.
The doubt is that in this case it is not possible to simulate. Nobody has any news about it or a piece of code that is really complete and working even in simulation?
here my code


Code:

$lib "lcd4e2.lbx"
$regfile = "m328pdef.dat"                                  
$crystal = 16000000                                      
$baud = 9600                                                
$hwstack = 32                                              
$swstack = 10                                              
$framesize = 40  

Dim  ___lcde as bit

Config Lcdpin = Pin , Db4 = Portb.4 , Db5 = Portb.5 , Db6 = Portb.6 , Db7 = Portb.7 , E = Portb.2 , Rs = Portb.0, E2 = portb.3

Config Lcd = 40x4

___lcde = 0
Initlcd
Cls
Upperline
LOCATE 1,1
Lcd "1"
Lowerline
LOCATE 2,1
Lcd "2"
Cursor Off
___lcde = 1
Initlcd
Thirdline
Locate 1 , 2
Lcd "3"
Fourthline
Locate 2 , 2
Lcd "4"
Cursor Off
End

 



Thanks in advance

(BASCOM-AVR version : 2.0.8.4 )
Back to top
View user's profile
Duval JP

Bascom Member



Joined: 22 Jun 2004
Posts: 1161
Location: France

france.gif
PostPosted: Tue Oct 26, 2021 6:00 pm    Post subject: Reply with quote

hi
this code works for all port
Code:

$sim
'__ serial port----------------------------------
Config Com1 = 115200 , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0       '9600  115200
Echo Off
Config Serialin0 = Buffered , Size = 15                     'jaune
Config Serialout0 = Buffered , Size = 15                    'RX from Terminal  vert comme vert     usbserial lignt df robot le TX va a tx
Open "COM1:" For Binary As #1

Enable Interrupts

'---lcd --------------------------------------------------------------------
Led Alias Porta.6
Buzzer Alias Porta.7
Config Lcdmode = Port
Config Lcdpin = Pin , Db4 = Porta.2 , Db5 = Porta.3 , Db6 = Porta.4 , Db7 = Porta.5 , E = Porta.1 , Rs = Porta.0
Config Lcd = 20 * 4
Config Buzzer = Output
Config Led = Output

Dim Ischar As Byte
Dim Rxbyte As Byte
' constant---------------------------------------------------------------
Const Notedo = 2548
Const Durdo = 300
'-----------variables-----------------------------------------------------
Dim Jbyte As Byte
'testled
For Jbyte = 1 To 4
   Set Led
   Waitms 200
   Reset Led
   Waitms 200
Next
Cls
Wait 1
' test lcd
Locate 1 , 1 : Lcd "123456789A123456789A"
Locate 2 , 1 : Lcd "123456789B123456789B"
Locate 3 , 1 : Lcd "123456789C123456789C"
Locate 4 , 1 : Lcd "123456789D123456789D"
 

it is part of a program but I test My led, and my LCD before anything else
JP Wink
it works with arduino too

[img][/img]

_________________
pleasure to learn, to teach, to create
Back to top
View user's profile Visit poster's website
pierscintilla

Bascom Member



Joined: 08 Aug 2005
Posts: 54
Location: italy

PostPosted: Tue Oct 26, 2021 7:33 pm    Post subject: Reply with quote

Yes, this works but only with LCD 20X4. With LCD 40x4 (with 2 EN lines) it displays only the last 3 lines and also in the wrong way exactly as it happens to me when not using the lcd4e2.lbx library which is made to manage the two EN lines. But if I use this library the display doesn't show anything ...
Back to top
View user's profile
Duval JP

Bascom Member



Joined: 22 Jun 2004
Posts: 1161
Location: France

france.gif
PostPosted: Wed Oct 27, 2021 8:15 am    Post subject: Reply with quote

sorry I read to fast . Now I use only Nextion graphic display it takes only 2 pins from µC

but are you sure of your code ?


Code:
Fourthline
Locate 2 , 2

When you "locate 2" you mean line 2, why did you use Fourthline ?

JP Wink

_________________
pleasure to learn, to teach, to create
Back to top
View user's profile Visit poster's website
pierscintilla

Bascom Member



Joined: 08 Aug 2005
Posts: 54
Location: italy

PostPosted: Wed Oct 27, 2021 1:25 pm    Post subject: Reply with quote

Yes. Fourthline Locate 2 , 2 is correct (at least I think so) and so I have seen in other codes not mine. This is because for the third and fourth line the second controller must be activated via the second EN. The LCD then "sees" these two lines as the first and second
Back to top
View user's profile
Duval JP

Bascom Member



Joined: 22 Jun 2004
Posts: 1161
Location: France

france.gif
PostPosted: Wed Oct 27, 2021 2:11 pm    Post subject: Reply with quote

yes it seems to a be a bug
I try
Code:

'---lcd --------------------------------------------------------------------
Led Alias Porta.6
Buzzer Alias Porta.7
Config Lcdmode = Port
Config Lcdpin = Pin , Db4 = Porta.2 , Db5 = Porta.3 , Db6 = Porta.4 , Db7 = Porta.5 , E = Porta.1 , Rs = Porta.0
Config Lcd = 40x4
 

then
Code:
' test lcd
Locate 1 , 1 : Lcd "123456789A123456789A123456789B123456789" 'only 39 char
Locate 2 , 1 : Lcd "123456789B123456789C123456789B123456789"
Locate 3 , 1 : Lcd "123456789C123456789E123456789B123456789"
Locate 4 , 1 : Lcd "123456789D123456789G123456789B123456789"

[img]

Rolling Eyes
JP[/img]

_________________
pleasure to learn, to teach, to create
Back to top
View user's profile Visit poster's website
pierscintilla

Bascom Member



Joined: 08 Aug 2005
Posts: 54
Location: italy

PostPosted: Wed Oct 27, 2021 3:26 pm    Post subject: Reply with quote

Your problem is that you don't check the second enable and don't use the necessary library. You are using the LCD as if it were a normal LCD with a single controller but in this case (over 20 characters) the controllers and enables are 2. But unfortunately when I use the necessary library the LCD remains empty
Back to top
View user's profile
laborratte

Bascom Expert



Joined: 27 Jul 2005
Posts: 299
Location: Berlin

germany.gif
PostPosted: Wed Oct 27, 2021 5:55 pm    Post subject: Reply with quote

a) The library lcd4e2.lbx ist pretty old and was written before the mega328p came up. Inside the lib the port for lcd is hardcoded. You have to edit the lcd4e2.lib file to the correct I/O register for the m328p:
Code:
(...)
[_Init_LCD]
.EQU LCDDDR=$17       ; change to another address for DDRD ($11)
.EQU LCDPORT=$18      ; change to another address for PORTD ($12)
(...)
 
must be change afaik to $04 and $05 for mega328p if you want to use portB.

b) ___LCDE must be byte, not bit

c) a secound lcdinit doesn't make sense - it inits both lcd controler

d) I doubt that simulator can simulate this lib.
Back to top
View user's profile
pierscintilla

Bascom Member



Joined: 08 Aug 2005
Posts: 54
Location: italy

PostPosted: Wed Oct 27, 2021 7:31 pm    Post subject: Reply with quote

Many thanks for the reply. As for the first point, it is possible to overwrite the two addresses at my code level by inserting .EQU LCDDDR = $ 04 and .EQU LCDPORT = $ 05? I had tried 11 and 12 found on the net without success but I do not understand if it is possible to enter these addresses programmatically without modifying the library (I only have the lbx) and the perplexity is aggravated by the doubt that the emulator can manage this library ....
Back to top
View user's profile
pierscintilla

Bascom Member



Joined: 08 Aug 2005
Posts: 54
Location: italy

PostPosted: Wed Oct 27, 2021 7:37 pm    Post subject: Reply with quote

I have tested the indicated variations but still without success. The doubt about the simulator is getting stronger
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5920
Location: Holland

blank.gif
PostPosted: Wed Oct 27, 2021 8:32 pm    Post subject: Reply with quote

the LCD simulation is made for the specified LCD's. It will not simulate other LCD properly. Many LCD have a different memory lay out. And the sim only knows the memory map of the supported LCD. Not for a custom lib with 2 LCD.
_________________
Mark
Back to top
View user's profile Visit poster's website
laborratte

Bascom Expert



Joined: 27 Jul 2005
Posts: 299
Location: Berlin

germany.gif
PostPosted: Wed Oct 27, 2021 8:47 pm    Post subject: Reply with quote

Quote:
As for the first point, it is possible to overwrite the two addresses at my code level by inserting .EQU LCDDDR = $ 04 and .EQU LCDPORT = $ 05?

No, it has to be changed in lib.

From Help: "Note that LBX is a compiled LIB file. In order to change the routines you need the commercial edition with the source code(lib files). After a change you should compile the library with the library manager."
Back to top
View user's profile
sq2eer

Bascom Member



Joined: 16 Aug 2011
Posts: 7
Location: Pelplin

poland.gif
PostPosted: Wed Oct 27, 2021 9:02 pm    Post subject: Reply with quote

Hello, on the Polish bascom forum, there is a code for a 40x4 lcd, maybe this code will be good.

https://bart-projects-forum.cba.pl/viewtopic.php?f=13&t=243

Regards, Jacek.
Back to top
View user's profile
pierscintilla

Bascom Member



Joined: 08 Aug 2005
Posts: 54
Location: italy

PostPosted: Thu Oct 28, 2021 9:21 am    Post subject: Reply with quote

Ok Mark. Your answer resolves any doubts
Thank you
Back to top
View user's profile
pierscintilla

Bascom Member



Joined: 08 Aug 2005
Posts: 54
Location: italy

PostPosted: Thu Oct 28, 2021 9:27 am    Post subject: Reply with quote

The fact that a 40x4 LCD config is provided and, since practically all 40-character LCDs have two enablements, I think it would be useful to say which LCDs are considered by the simulator with a warning message in the help..
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR All times are GMT + 1 Hour
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum