CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

How to drive two 20x4 lcds ?
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
temtronic



Joined: 01 Jul 2010
Posts: 9636
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue Jul 22, 2014 10:01 am     Reply with quote

probably a Proteus error that no one here can fix( or wants to).

other problems is the midprogram declaration of variables It sometimes works,usually not though.I think that ' Standard C programming' is that ALL variables be declared before main().

you should add a delay_ms(500) before the LCD module are initialzed. In the real world if you don't, you stand an 85% chance the LCDs will NOT run as expected.

as pointed out there are other errors but until you burn a real PIC and run in the real world.....you'll never see what's really going to happen.

hth
jay
pg1995



Joined: 05 Apr 2014
Posts: 31

View user's profile Send private message

PostPosted: Tue Jul 22, 2014 10:13 am     Reply with quote

Thank you, John.

ezflyr wrote:
Your code had a lot of problems and 'oddities', so it's a bit hard to know where to start


Sorry for the oddities. I just made up the code to test my learning and wasn't very careful with the code.

ezflyr wrote:
1. The problem that prompted your post is due to the fact that you are missing a 'new line' (\n), so that the second message overwrites the first message. You've got it for the 1st display, but not the 2nd.....


Let's focus on this. It doesn't look like I'm missing a new line character. The following sections from the code are for LCD2. You can see that a new line character(s) is used in that blue section which is causing an erratic display. Also, if you compare these sections with that of LCD1, you can see LCD1 sections are structured similarly. So, could you please give it another look? Thanks.

if (a1 > 400) output_high(pin_c5);
select_lcd=1;
printf(lcd_putc,"\fvoltage over 1.95");
printf(lcd_putc, "\nV>%g", 1.95);
delay_ms(2000);


if (a3 < 250) output_high(pin_c7);
select_lcd=1;
printf(lcd_putc,"\nvoltage less 1");
printf(lcd_putc, "\nV<%g", 1.0);
delay_ms(2000);



And, yes, I'm not using braces with "if" blocks because as I said above, I just made up the code to test my learning.

ezflyr wrote:
You really should try some really hardware. Honestly, it is a lot of fun!


Agreed. I will start assembling my project in next couple of days. Sure, I will share a video with you once it's working. Thank you.
ezflyr



Joined: 25 Oct 2010
Posts: 1019
Location: Tewksbury, MA

View user's profile Send private message

PostPosted: Tue Jul 22, 2014 11:23 am     Reply with quote

Hi,

Quote:
Sorry for the oddities. I just made up the code to test my learning and wasn't very careful with the code.


In my opinion this is a dangerous philosophy. In programming, details are *always* important, so don't get in the habit of ever thinking they don't!!!!

I went back and looked, and although there is one less '\n' being sent to the 2nd display, it's not clear if this is the issue. In words, please tell us what the unexpected behavior is? Is it just the overwritten text?

Edit: You are using '\f' and '\n' differently between the two displays. Do it the same way for both by using the method that works as a template. this is a case where 'the details' do matter.....

John
pg1995



Joined: 05 Apr 2014
Posts: 31

View user's profile Send private message

PostPosted: Tue Jul 22, 2014 11:48 am     Reply with quote

Thank you, jay, John.

It won't work. I even changed the code to make the sections for LCD2 similar to that LCD1 which works fine. So, I would conclude that it's really a Proteus error as pointed by jay above.

Code:

int16 a0, a1, a2, a3;


void main()
{

   setup_adc_ports(ALL_ANALOG);
   setup_adc(adc_clock_div_32); 
   
   select_lcd=0;
   lcd_init(); //initialise the first lcd
   printf(lcd_putc, "\f");
   delay_ms(500);
   select_lcd=1;
   lcd_init(); //initialise the second lcd
   printf(lcd_putc, "\f");
   delay_ms(500);
   
   delay_ms(20);
   
   set_adc_channel(0);
   delay_ms(20);
   a0 = read_adc();
   
   delay_ms(1000);
   
   set_adc_channel(1);
   delay_ms(20);
   a1 = read_adc();
   
   delay_ms(1000);
   
   set_adc_channel(2);
   delay_ms(20);
   a2 = read_adc();
   
   delay_ms(1000);
   
   set_adc_channel(3);
   delay_ms(20);
   a3 = read_adc();
   
   if (a0 > 300) output_high(pin_c4);
   select_lcd=0;
   printf(lcd_putc,"\fvoltage over 1\n");
   printf(lcd_putc, "V>%g", 1.0);
   delay_ms(2000);
   
   if (a1 > 400) output_high(pin_c5);
   select_lcd=1;
   printf(lcd_putc,"\fvoltage over 1.95\n");
   printf(lcd_putc, "V>%g", 1.95);
   delay_ms(2000);
   
   if (a2 > 600) output_high(pin_c6);
   select_lcd=0;
   printf(lcd_putc,"\nvoltage over 2.93");
   printf(lcd_putc, "\nV>%g", 2.93);
   delay_ms(2000);
   
   if (a3 < 250) output_high(pin_c7);
   select_lcd=1;
   printf(lcd_putc,"\nvoltage less 1");
   printf(lcd_putc, "\nV<%g", 1.0);
   delay_ms(2000);
       
}



Quote:
you should add a delay_ms(500) before the LCD module are initialzed. In the real world if you don't, you stand an 85% chance the LCDs will NOT run as expected.


Did I make a mistake? I have based that LCD initialization part of the code on the following part from PCM programmer's post here.

Code:

void main()
{
int8 i;
int8 b1, b2, b3, b4;

// The lcd_init() function should always be called once,
// near the start of your program.
lcd_init();

// Clear the LCD.
printf(lcd_putc, "\f");
delay_ms(500);


Thank you.
Ttelmah



Joined: 11 Mar 2010
Posts: 20064

View user's profile Send private message

PostPosted: Wed Jul 23, 2014 1:05 am     Reply with quote

The 'later' delay here, is just to allow a pause after the display is woken up.

The point about the 'earlier' pause before lcd_init, is to do with wake up timings of the chips.

Historically, the original Hitachi controller that this 'family' of chips are clones/copies of, needs about 10mSec to wake up before they can accept commands. The flex_lcd driver allows this internally in lcd_init. However there are two problems that have commonly been found. The first is that some of the clones need a _lot_ longer. Some specify over 200mSec in their data. So straight away an extra delay is needed before calling lcd_init. There is also a second problem, that in some cases the specified voltage where the display considers the supply to be 'on', may be much higher than the voltage where the PIC actually starts. A lot of modern PIC's will start operating down at voltages like 2v!. Quite a few of the LCD's don't even start initialising till the supply voltage is over perhaps 4v. Now if the supply is a type where it ramps up slowly, this then means the LCD actually 'starts initialising' several mSec after the PIC starts, meaning yet more delay is needed. This is also made worse, because 'historically' when flex_lcd was first written, the PIC's being used, had crystal oscillators, and used PUT. So the PIC wouldn't start running till typically perhaps 70mSec after the power rail went 'good'. Later PIC's using their internal oscillators, can instead start up, in a few uSec

So to give reliable wake up, it is safer, when using clone chips, and modern PIC's, to add an extra delay before calling lcd_init. Half a second, is not even noticeable, and can make the difference between the code being 'erratic' on some displays, and working perfectly.
pg1995



Joined: 05 Apr 2014
Posts: 31

View user's profile Send private message

PostPosted: Wed Jul 23, 2014 8:46 pm     Reply with quote

Thanks a lot for the detailed reply, Ttelmah.

So, the following is preferred way of doing it.

void main()
{
...
delay_ms(500);
lcd_init();
printf(lcd_putc, "\f");
delay_ms(500);
...
}
temtronic



Joined: 01 Jul 2010
Posts: 9636
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Thu Jul 24, 2014 5:10 am     Reply with quote

Yes, the delay_ms(500); in BOLD is to allow the LCD module time to 'wakeup and get organized' before the PIC sends any commands to it.

You do not need the delay_ms(500); AFTER any printf to the LCD module though, unless it's to allow you time to see what's on the LCD module.

hth
jay
pg1995



Joined: 05 Apr 2014
Posts: 31

View user's profile Send private message

PostPosted: Thu Jul 24, 2014 5:50 am     Reply with quote

Thank you.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 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


Powered by phpBB © 2001, 2005 phpBB Group