Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Running LCD Display 4 Bit Mode Libraries ? Init ?

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    www.mcselec.com Forum Index -> BASCOM-AVR Archive
View previous topic :: View next topic  
Author Message
autoguider

Bascom Member



Joined: 24 Sep 2007
Posts: 82
Location: Aachen

germany.gif
PostPosted: Thu Oct 31, 2013 12:37 am    Post subject: Running LCD Display 4 Bit Mode Libraries ? Init ? Reply with quote

Dear All,
I am asking for your advice to get the LCD Display operating.

The PowertipPC 1602 F Display is not operating on a ATMeaga 168 P in 4 Biut Mode.
I am using the 2.0.7.6 version of the Bascom compiler.

In the program the processor is indicated by following files/ Libraries:

$lib "mcs.lbx"
$regfile = "m168def.dat"

..
later on the LCD display is introduced to the compiler by:

Config Lcd = 16x2
Config LCDBUS = 4
Config Lcdpin = Pin , Db4 = Portd.6 , Db5 = Portd.4 , Db6 = Portd.7 , Db7 = Portb.0 , E = Portd.3 , Rs = Portd.2

The unused data pins of the display are connected to ground. R/W is set to write.

Do I need a different library ?
Is the declaration o.k. ?
Is some special init procedure requires or is this done within the declaration ?

This is the first time that I control the display in 4 bit mode.
Perhaps I cannot see the forest because of the trees.

Please be so kind to give me some advice

best regards
Christian

(BASCOM-AVR version : 2.0.7.6 , Latest : 2.0.7.6 )
Back to top
View user's profile
i.dobson

Bascom Expert



Joined: 05 Jan 2006
Posts: 1571
Location: Basel, Switzerland

switzerland.gif
PostPosted: Thu Oct 31, 2013 6:11 am    Post subject: Reply with quote

Hi,

I usually use something like this :-

Config Lcdpin = Pin , Db4 = Portc.5 , Db5 = Portc.4 , Db6 = Portc.3 , Db7 = Portc.2 , E = Portc.6 , Rs = Portc.7
Config Lcd = 20x4
initlcd

note I don't use the Config LCDBUS = 4 command. and I just leave the unused Pins Floating (not connected).

Are you sure that you have the LCD control voltage Setup correctly/try adjusting the LCD Display voltage Abit.

Regards
Ian Dobson

_________________
Walking on water and writing software to specification is easy if they're frozen.
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 6198
Location: Holland

blank.gif
PostPosted: Thu Oct 31, 2013 4:44 pm    Post subject: Reply with quote

you have connected WR to ground?
always check all pins to see if they function with a simple test code:

config portb.0=output

do
toggle portB.0 'toggle pin and measure with DVM to see if the pin toggles
waitms 1000
loop

checking contrast is a good idea too.

_________________
Mark
Back to top
View user's profile Visit poster's website
autoguider

Bascom Member



Joined: 24 Sep 2007
Posts: 82
Location: Aachen

germany.gif
PostPosted: Thu Oct 31, 2013 8:50 pm    Post subject: Reply with quote

Dear Ian, Dear Albert.
many thanks for your advice.
I will do some testing now.

While reading your advice a further question arises:
Do I habe to config e.g. PORTB.0 = Output before I do the config Lcdpin =Pin ,...., DB7 = PORTB.0 ?

Pin5 ( R/W) of the display is connected to ground. This means that only write access to the display is possible.

I also checked on the contrast voltage. It is low enough.
There are dark rectangles at the location of the letters in one line of the 2 line display only.

I you have some further ideas please let me know.

Now I will do some testing.

best regards

Christian
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 6198
Location: Holland

blank.gif
PostPosted: Thu Oct 31, 2013 9:00 pm    Post subject: Reply with quote

the config lcdpin will set the data direction of the pin.
Just test these pins : Db4 = Portd.6 , Db5 = Portd.4 , Db6 = Portd.7 , Db7 = Portb.0 , E = Portd.3 , Rs = Portd.2
Maybe they are wired different. or some other hardware is connected to them as well?
And make sure you indeed connect to DB4-DB7 of the LCD.
If you see black blocks the contrast is ok.

_________________
Mark
Back to top
View user's profile Visit poster's website
petros047

Bascom Member



Joined: 14 Mar 2012
Posts: 84

greece.gif
PostPosted: Sun Nov 03, 2013 2:03 pm    Post subject: Reply with quote

I use this lib and always work but you have to connect the w/r pin to mc in order to work.
this lib read the w/r pin as flag to calculate the necessary delay who lcd need for various commands.

$lib "lcd4busy_anypin.lbx"
'lcd config
Config Lcdpin = Pin , Db4 = Portc.2 , Db5 = Portc.1 , Db6 = Portc.0 , Db7 = Portd.7 , E = Portc.3 , Rs = Portc.5 , Wr = Portc.4
Config Lcd = 16 * 2
Initlcd
Display On
Cursor Off
Back to top
View user's profile
autoguider

Bascom Member



Joined: 24 Sep 2007
Posts: 82
Location: Aachen

germany.gif
PostPosted: Sun Nov 17, 2013 8:42 pm    Post subject: Reply with quote

Dear All,
many thanks for your advice.

In the meantime I got the LCD working in 4 bit mode.
I found some behaviour of the display which is strange to me.

If there is a wait command after data is written to the LCD using the lcd command then the display does not show any data until it comes to the next access to the display.
The display is not darkened it just shows nothing.

When putting a wait command after e.g. locate then the display remains as it should.

So it means that there must not be a wait command after a lcd command.

Is this normal ?

best regards

Christian





For clarification here is the code:
Config Lcd = 16*2

Config Lcdpin = Pin , Db4 = Portd.6 , Db5 = Portd.4 , Db6 = Portd.7 , Db7 = Portb.0 , E = Portd.3 , Rs = Portd.2
initlcd

Dim i as integer
dim Line_1 as string*16
dim Line_2 as string*16
dim dummystring as string*3
i=0
line_1 = "thisisline#"
cls
lcd line_1
line_2 ="QWERTzYXASDY"
wait 1
lowerline
lcd line_2


waitms 1000
Cursor Off Noblink

' Now there is the endless counting loop

loops:
dummystring =str(i)
dummystring = " " + dummystring

locate 1, 12 'position to line 1 Pos 12
waitms 50 'give time for executing command
lcd dummystring 'write short string to line 1

waitms 1000 '<-- no information visible on LCD display but data is still in the memory

locate 2,12 'position to line 2 Pos 12 Information is displayed
waitms 50 'give time for executing command
lcd dummystring ' write short string to defined position

locate 1, 12 '<---- if removed then no information visible on LCD
waitms 1000 '<------ this works if locate command is prior


i=i+1
'wait 1
if i=100 then i=0

goto loops
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 6198
Location: Holland

blank.gif
PostPosted: Mon Nov 18, 2013 10:39 am    Post subject: Reply with quote

your code does not show if you use the default lib or some other lib?
and do you have WR connected to ground or a pin ?
what i do miss : $crystal = somevalue

that is important for timing.

_________________
Mark
Back to top
View user's profile Visit poster's website
autoguider

Bascom Member



Joined: 24 Sep 2007
Posts: 82
Location: Aachen

germany.gif
PostPosted: Thu Nov 21, 2013 8:24 pm    Post subject: Reply with quote

Dear Albert,

sorry about the lack of information.
Here it comes:
It is the default lib
wr is connected to ground
There is a 6 MHz crystal in operation. No division of the external clock.

best regards
Christian
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 6198
Location: Holland

blank.gif
PostPosted: Thu Nov 21, 2013 11:25 pm    Post subject: Reply with quote

please post the complete code that contains $regfile , $crystal, $hwstack and $swstack. Otherwise i need to guess it.

you wrote earlier that you got the lcd working after initial problems. what was the source of the problem? what would it not work in the first place?

instead of ;

loops:
.. code here
goto loops

you can better write :

do
..code here
loop

right after the LCD command the lcd should display the information. a locate only positions the cursor.
is no other hardware connected to the pins? especial the pins connected to the E-line and RS-line?

_________________
Mark
Back to top
View user's profile Visit poster's website
autoguider

Bascom Member



Joined: 24 Sep 2007
Posts: 82
Location: Aachen

germany.gif
PostPosted: Fri Nov 22, 2013 2:58 pm    Post subject: Reply with quote

Dear Alberet,
here is the source text:


'$PROG &HFF,&HF7,&HDF,&HFF' generated. Take care that the chip supports all fuse bytes.


$lib "mcs.lbx"
$regfile = "m168def.dat" ' specify the used micro
$crystal = 6000000 ' used crystal frequency
$baud = 19200 ' use baud rate
$hwstack = 90 ' default use 32 for the hardware stack
$swstack = 60 ' default use 10 for the SW stack
$framesize = 40

Config Lcd = 16*2
Config LCDBUS = 4
Config Lcdpin = Pin , Db4 = Portd.6 , Db5 = Portd.4 , Db6 = Portd.7 , Db7 = Portb.0 , E = Portd.3 , Rs = Portd.2
initlcd

Dim i as integer
dim Line_1 as string*16
dim Line_2 as string*16
dim dummystring as string*3

i=0
line_1 = "thisisline#"
cls
lcd line_1

line_2 ="QWERTZYXASDY"

wait 1
lowerline
lcd line_2


waitms 1000
Cursor Off Noblink


do




dummystring =str(i)
dummystring = " " + dummystring

locate 1, 12 'position to line 1 Pos 12
waitms 50 'give time for executing command
lcd dummystring 'write short string to line 1

'waitms 1000 '<-- no information visible

locate 2,12 'position to line 2 Pos 12
waitms 50 'give time for executing command
lcd dummystring ' write short string to defined position

locate 1, 12 '<---- if removed then no information visible on LCD
waitms 1000 '<------ this works if locate command is prior


i=i+1
'wait 1
if i=100 then i=0

loop

The wait commands following the lcd commands ( e.g. lines 30. 35, 51) cause the display to show nothing.
If e.g. the command locate occurs after a lcd command but before a wait command ( see lines 49 .. 53) everything runs well.

best regards

Christian
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 6198
Location: Holland

blank.gif
PostPosted: Fri Nov 22, 2013 10:32 pm    Post subject: Reply with quote

i changed your code a bit. first of all, the delays are not necessary.
only 1 delay should be placed so the lcd has time to show the info. (at the end of the loop). Otherwise the result would be erased by the next value.

here is your code:

Code:
$regfile = "m168def.dat"                                    ' specify the used micro
$crystal = 6000000                                          ' used crystal frequency
$baud = 19200                                               ' use baud rate
$hwstack = 90                                               ' default use 32 for the hardware stack
$swstack = 60                                               ' default use 10 for the SW stack
$framesize = 40

Config Lcd = 16*2
Config Lcdpin = Pin , Db4 = Portd.6 , Db5 = Portd.4 , Db6 = Portd.7 , Db7 = Portb.0 , E = Portd.3 , Rs = Portd.2
initlcd

Dim i as integer
dim Line_1 as string*16
dim Line_2 as string*16
dim dummystring as string*3

i=0
line_1 = "thisisline#"
cls
lcd line_1

line_2 ="QWERTZYXASDY"

'wait 1
lowerline
lcd line_2


'waitms 1000
Cursor Off Noblink


do
    dummystring = str(i)
    dummystring = " " + dummystring

    locate 1, 12      'position to line 1 Pos 12
'    waitms 50       'give time for executing command
    lcd dummystring   'write short string to line 1

    'waitms 1000 '&lt;-- no information visible

   locate 2,12       'position to line 2 Pos 12
'   waitms 50       'give time for executing command
   lcd dummystring ' write short string to defined position

'   locate 1, 12 '&lt;---- if removed then no information visible on LCD
   waitms 1000 '&lt;------ this works if locate command is prior
'  ^^  you need a delay to be able to read the text !!!

    i=i+1
    'wait 1
    if i=100 then i=0
loop


i removed the last waitms 1000 because i simulated the code. in a real processor you need to include it.
The code works as expected. i can only assume there is a problem with the hardware. there can be several reasons. I assume you run on 5V ? And that the LCD is a 5V too?
Do you have a link to the PDF of the LCD ?
Did you tried a different LCD ?
Did you wired on a breadboard or is this a ready made board? Do you have the circuit?

And last : if you update the LCD in a loop, you continuously are updating the lcd with command and or data.
Some displays might not show the data while they are updated.
So even while you do not use a CLS command, you might need a delay so the lcd is readable. I suspect that different lcd's will handle this different.
Instead of using a delay you could use an interval to update the LCD.

_________________
Mark
Back to top
View user's profile Visit poster's website
autoguider

Bascom Member



Joined: 24 Sep 2007
Posts: 82
Location: Aachen

germany.gif
PostPosted: Sat Nov 23, 2013 12:31 am    Post subject: Reply with quote

Dear Albert,
many thaks for your efforts and recommendations.
Here is a link to the datasheet of the display: http://www.datasheetarchive.com/PC1602-F-datasheet.html

So far I have not tried an other display but I will do.

The installation is on a soldered board. like this one http://www.reichelt.de/directlink/Lochrasterplatine/index.html?&ACTION=2&GROUPID=3372&&SHOW=1&SID=10TivsyX8AAAIAABt1Y1g2f6efa2336525b970a9f72f7e2a56484&SEARCH=LOCHRASTERPLATINE

The internal connections are done with enameled copper wire.
Before I do a printed circuit board I want to do the test with this prototype.
Enameled copper wire is similar to a multi Layer PCB Wink

thanks again
Christian
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 6198
Location: Holland

blank.gif
PostPosted: Sat Nov 23, 2013 1:09 pm    Post subject: Reply with quote

it seems like a standard display.
it is very wise to test before you make a pcb.
best to keep the wires short as possible.
and make sure you have a good stable power and decoupling caps at vcc.
very important is that the $crystal=6000000 matches the actual oscillator speed.
that is simple to test :

config portb.1 =output 'use a free pin
do
toggle portb.1 'on and off must be ca. 1 sec.
waitms 1000
loop

_________________
Mark
Back to top
View user's profile Visit poster's website
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    www.mcselec.com Forum Index -> BASCOM-AVR Archive All times are GMT + 1 Hour
Page 1 of 1

 
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