Having difficulty running LCD code

General discussion on mikroBasic PRO for PIC.
Post Reply
Author
Message
Maged A. Mohamed
Posts: 27
Joined: 26 Dec 2014 11:01
Location: Cairo
Contact:

Having difficulty running LCD code

#1 Post by Maged A. Mohamed » 27 Jun 2015 11:24

Hi,
I have a project using LCD 4x20, I did some advanced projects with C51 code and no problems before with LCD 1X16,2X16 and 4X16 .
This one should be done with PIC16F877A for availability problem at destination area.
I tried the examples with Great Cow compiler and Prithvi for LCD light meter and both worked fine,
The MiKroElektronica example gave me at compile error message with 2 lines
" ANSEL = 0 ' Configure AN pins as digital I/O
ANSELH = 0"
Saying ANSEL was not declared, commenting both lines, the code generated does not work

I reconfigured the breadboard to my schematic and that configuration worked fine with previous light meter, then I used the steps I used with C51 , but no result, I made a simple loop to write "M" then flash led then "3" then flash led and loop, the only result I get is the program runs till initialization of LCD and it shows 2 lines and the cursor at Line 1 Char 1 and even the LED does not flash.
On oscilloscope the oscillator is running, but all the port pins are not changing.
Attached please find the test project I used
Attachments
LCD tst.zip
(24.31 KiB) Downloaded 111 times

Dany
Posts: 3854
Joined: 18 Jun 2008 11:43
Location: Nieuwpoort, Belgium
Contact:

Re: Having difficulty running LCD code

#2 Post by Dany » 27 Jun 2015 12:48

Hi,

ANSEL or ANSELH do not exist in the P16F877A.
You should use register ADCON1 in stead and fill it with value 6 to set all inputs to digital. See the pic's datasheet page 128.
Kind regards, Dany.
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)

Maged A. Mohamed
Posts: 27
Joined: 26 Dec 2014 11:01
Location: Cairo
Contact:

Re: Having difficulty running LCD code

#3 Post by Maged A. Mohamed » 29 Jun 2015 12:07

Hi,
Thanks very much for this information, sorry I overlooked it because I mixed 16f877 with 887

Here I did what you suggested, still the LCD configures to 2 lines and the cursor stops at 1st character, the LED does not flash.

I reconfigured the circuit to use portc instead (attached) the only difference it the LED turns on and stays on
Attachments
LCD tst-m.zip
(47.01 KiB) Downloaded 112 times

Maged A. Mohamed
Posts: 27
Joined: 26 Dec 2014 11:01
Location: Cairo
Contact:

Re: Having difficulty running LCD code

#4 Post by Maged A. Mohamed » 04 Jul 2015 11:41

if I exceed the stack limit, will the program issue an alarm?

Dany
Posts: 3854
Joined: 18 Jun 2008 11:43
Location: Nieuwpoort, Belgium
Contact:

Re: Having difficulty running LCD code

#5 Post by Dany » 04 Jul 2015 19:11

Code: Select all

dim i, ...  as byte   ' Loop variable and sensor faults  

sub Procedure WaitMS(dim Time_mSec as word)
   for i = 1 to Time_mSec
         Wait1ms
   next i
end sub

while true
             TstLED = 1
             WaitMS (500)
Variable I is a byte, it can only handle values 0..255, so the latter statement "WaitMS (500)" will not work well...
p.s. If you had defined "I" locally in the WaitMS procedure the problem could have been spotted more easily... (and the code would have been more robust also)
Kind regards, Dany.
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)

Maged A. Mohamed
Posts: 27
Joined: 26 Dec 2014 11:01
Location: Cairo
Contact:

Re: Having difficulty running LCD code

#6 Post by Maged A. Mohamed » 09 Jul 2015 12:44

1st I am sorry for late reply as I was busy doing something else.
2nd Thanks very much that was it, it solved my problem.

Thanks again

Post Reply

Return to “mikroBasic PRO for PIC General”