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 support@ccsinfo.com

LCD Problem

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Trefor
Guest







LCD Problem
PostPosted: Wed Apr 02, 2003 11:31 am     Reply with quote

Hi All,
I have put together a program that works except for the LCD drive. You may recognise it from www.vermontficks.org. The problem that I am having is that the second line on the LCD refuses to work!!! The display is a powertip 2x16 alphanumeric TN and their data sheets says that a missing second line is due to either incorrect initialisation or wrongly set as a single line dispaly. However the program looks good as far as I can tell!! The code is below and any help will be much apreciated!!
Thanks
trefor

#include <16c74.h>
#include <math.h>
#define echo pin_c2
#define init pin_b6
#define binh pin_b7
#define lcd_d0 pin_b0
#define lcd_d1 pin_b1
#define lcd_d2 pin_b2
#define lcd_d3 pin_b3
#define lcd_en pin_b4
#define lcd_rs pin_b5
#define first_line 0x00
#define second_line 0x40
#define clear_disp 0x01


#separate void lcd_init (void);
#separate void lcd_setposition (unsigned int cX);
#separate void lcd_putchar (unsigned int cX);
#separate void lcd_putcmd (unsigned int cX);
#separate void lcd_pulseenable (void);
#separate void lcd_setdata (unsigned int cX);

#use delay (clock=20000000)
long value;
float time,time1,distance,angle,anglerad,calc1,hyp1,hyp2,tipdist;
const long k1=2,k2=66;
const float counttime=0.0000016,sos=13628,const1=2.95,const2=0.01745,const3=12,offset=1;

#separate lcd_init (void)
{
lcd_setdata (0x00);
delay_ms(200);
output_low (lcd_rs);
lcd_setdata (0x03);
lcd_pulseenable();
lcd_pulseenable();
lcd_pulseenable();
lcd_setdata (0x02);
lcd_pulseenable();
lcd_putcmd (0x2C);
lcd_putcmd (0x0C);
lcd_putcmd (0x01);
lcd_putcmd (0x06);
}

#separate void lcd_setdata (unsigned int cX)
{
output_bit (lcd_d0,cX&0x01);
output_bit (lcd_d1,cX&0x02);
output_bit (lcd_d2,cX&0x04);
output_bit (lcd_d3,cX&0x08);
}

#separate void lcd_pulseenable (void)
{
output_high (lcd_en);
delay_us(10);
output_low (lcd_en);
delay_ms(5);
}

#separate void lcd_putcmd (unsigned int cX)
{
lcd_setdata ( swap ( cX ) );
lcd_pulseenable();
lcd_setdata ( swap ( cX ) );
lcd_pulseenable();
}

#separate void lcd_setposition (unsigned int cX)
{
lcd_setdata (swap(cX|0x08));
lcd_pulseenable();
lcd_setdata (swap(cX));
lcd_pulseenable();
}

#separate void lcd_putchar (unsigned int cX)
{
output_high (lcd_rs);
lcd_setdata (swap(cX));
lcd_pulseenable();
lcd_setdata (swap(cX));
lcd_pulseenable();
output_low (lcd_rs);
}

main (void)
{
while (true)
{
set_tris_a (0xff);
set_tris_b (0x00);
setup_ccp1(ccp_capture_re);
setup_adc_ports(ra0_ra1_ra3_analog);
setup_adc(adc_clock_internal);
set_adc_channel(0);
enable_interrupts(int_ccp1);
enable_interrupts(global);
output_low (init);
output_low(binh);
delay_ms(200);
setup_timer_1(t1_internal);
output_high(init);
delay_us(900);
output_high(binh);
delay_ms(100);
output_low(init);
delay_ms(100);
time=ccp_1*counttime;
time1=time/k1;
distance=(time1*sos)+offset;
value=read_adc();
angle=(value-k2)/const1;
anglerad=angle*const2;
calc1=cos(anglerad);
hyp1=distance/calc1;
hyp2=hyp1-const3;
tipdist=hyp2*calc1;
lcd_init();
lcd_putcmd (clear_disp);
lcd_setposition(first_line);
printf (lcd_putchar,"tipdist=\%2.1f",tipdist);
lcd_setposition(second_line);
printf (lcd_putchar,"angle=\%2.1f",angle);
(true);
}
}
___________________________
This message was ported from CCS's old forum
Original Post ID: 13318
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

Re: LCD Problem
PostPosted: Wed Apr 02, 2003 12:44 pm     Reply with quote

:=Hi All,
:= I have put together a program that works except for the LCD drive. You may recognise it from www.vermontficks.org. The problem that I am having is that the second line on the LCD refuses to work!!! The display is a powertip 2x16 alphanumeric
------------------------------------------------------

They appear to have at least 14 different models of a 16x2 LCD.
Which one are you using ?
<a href="http://www.powertipusa.com/lcdc.htm" TARGET="_blank">http://www.powertipusa.com/lcdc.htm</a>
___________________________
This message was ported from CCS's old forum
Original Post ID: 13321
Trefor
Guest







Re: LCD Problem
PostPosted: Wed Apr 02, 2003 12:56 pm     Reply with quote

Thanks for the quick reply!
The model number of the display is PC 1602-D
Hope this helps
trefor

:=:=Hi All,
:=:= I have put together a program that works except for the LCD drive. You may recognise it from www.vermontficks.org. The problem that I am having is that the second line on the LCD refuses to work!!! The display is a powertip 2x16 alphanumeric
:=------------------------------------------------------
:=
:=They appear to have at least 14 different models of a 16x2 LCD.
:=Which one are you using ?
:= <a href="http://www.powertipusa.com/lcdc.htm" TARGET="_blank"> <a href="http://www.powertipusa.com/lcdc.htm" TARGET="_blank">http://www.powertipusa.com/lcdc.htm</a></a>
___________________________
This message was ported from CCS's old forum
Original Post ID: 13322
Rollo
Guest







Re: LCD Problem
PostPosted: Wed Apr 02, 2003 1:09 pm     Reply with quote

Hi!

I'm not at all sure if this is relevant to your case or not, but here goes...

I got an 1 x 16 LCD last week. Got it home and tried it out. It only showed data on the first 8 characters, and nothing to the right of that. I thought maybe the unit was defective. Researched it and wrote eMails and found out that my unit was considering the right half to be the "second line".

Long story short, I was able to get it to work, but only if I added a location type of command before my "second line". In my case, I'm using the lcd.c code from CCS.

lcd_gotoxy(1,1);
printf(lcd_putc, "Line#1\n");

lcd_gotoxy(1,0);
printf(lcd_putc, "Line#2\n");

There is a second way in which I was able to get it to work using one command line, but I found I had to be careful of the number of characters I sent. It goes like this...

lcd_gotoxy(1,1);
printf(lcd_putc, "Line#1 \nLine#2 ");

In my case, each side of that \n above has eight characters, which add up to 16, for my 1 x 16 LCD.

I don't see how my code bears any resemblance to yours. Looks to me like you're maybe not using lcd.c as I am. But just in case that positionning or the \n issue is helpful, I thought I should post a reply.

I hope this might be useful, somehow. If I'm misunderstanding the problem, then my apologies, as I'm only 2 weeks into PICs and CCS.

G'luck!
Rol






:=Hi All,
:= I have put together a program that works except for the LCD drive. You may recognise it from www.vermontficks.org. The problem that I am having is that the second line on the LCD refuses to work!!! The display is a powertip 2x16 alphanumeric TN and their data sheets says that a missing second line is due to either incorrect initialisation or wrongly set as a single line dispaly. However the program looks good as far as I can tell!! The code is below and any help will be much apreciated!!
:=Thanks
:= trefor
:=
:=#include <16c74.h>
:=#include <math.h>
:=#define echo pin_c2
:=#define init pin_b6
:=#define binh pin_b7
:=#define lcd_d0 pin_b0
:=#define lcd_d1 pin_b1
:=#define lcd_d2 pin_b2
:=#define lcd_d3 pin_b3
:=#define lcd_en pin_b4
:=#define lcd_rs pin_b5
:=#define first_line 0x00
:=#define second_line 0x40
:=#define clear_disp 0x01
:=
:=
:=#separate void lcd_init (void);
:=#separate void lcd_setposition (unsigned int cX);
:=#separate void lcd_putchar (unsigned int cX);
:=#separate void lcd_putcmd (unsigned int cX);
:=#separate void lcd_pulseenable (void);
:=#separate void lcd_setdata (unsigned int cX);
:=
:=#use delay (clock=20000000)
:=long value;
:=float time,time1,distance,angle,anglerad,calc1,hyp1,hyp2,tipdist;
:=const long k1=2,k2=66;
:=const float counttime=0.0000016,sos=13628,const1=2.95,const2=0.01745,const3=12,offset=1;
:=
:=#separate lcd_init (void)
:= {
:= lcd_setdata (0x00);
:= delay_ms(200);
:= output_low (lcd_rs);
:= lcd_setdata (0x03);
:= lcd_pulseenable();
:= lcd_pulseenable();
:= lcd_pulseenable();
:= lcd_setdata (0x02);
:= lcd_pulseenable();
:= lcd_putcmd (0x2C);
:= lcd_putcmd (0x0C);
:= lcd_putcmd (0x01);
:= lcd_putcmd (0x06);
:= }
:=
:=#separate void lcd_setdata (unsigned int cX)
:= {
:= output_bit (lcd_d0,cX&0x01);
:= output_bit (lcd_d1,cX&0x02);
:= output_bit (lcd_d2,cX&0x04);
:= output_bit (lcd_d3,cX&0x08);
:= }
:=
:=#separate void lcd_pulseenable (void)
:= {
:= output_high (lcd_en);
:= delay_us(10);
:= output_low (lcd_en);
:= delay_ms(5);
:= }
:=
:=#separate void lcd_putcmd (unsigned int cX)
:= {
:= lcd_setdata ( swap ( cX ) );
:= lcd_pulseenable();
:= lcd_setdata ( swap ( cX ) );
:= lcd_pulseenable();
:= }
:=
:=#separate void lcd_setposition (unsigned int cX)
:= {
:= lcd_setdata (swap(cX|0x08));
:= lcd_pulseenable();
:= lcd_setdata (swap(cX));
:= lcd_pulseenable();
:= }
:=
:=#separate void lcd_putchar (unsigned int cX)
:= {
:= output_high (lcd_rs);
:= lcd_setdata (swap(cX));
:= lcd_pulseenable();
:= lcd_setdata (swap(cX));
:= lcd_pulseenable();
:= output_low (lcd_rs);
:= }
:=
:=main (void)
:= {
:= while (true)
:= {
:= set_tris_a (0xff);
:= set_tris_b (0x00);
:= setup_ccp1(ccp_capture_re);
:= setup_adc_ports(ra0_ra1_ra3_analog);
:= setup_adc(adc_clock_internal);
:= set_adc_channel(0);
:= enable_interrupts(int_ccp1);
:= enable_interrupts(global);
:= output_low (init);
:= output_low(binh);
:= delay_ms(200);
:= setup_timer_1(t1_internal);
:= output_high(init);
:= delay_us(900);
:= output_high(binh);
:= delay_ms(100);
:= output_low(init);
:= delay_ms(100);
:= time=ccp_1*counttime;
:= time1=time/k1;
:= distance=(time1*sos)+offset;
:= value=read_adc();
:= angle=(value-k2)/const1;
:= anglerad=angle*const2;
:= calc1=cos(anglerad);
:= hyp1=distance/calc1;
:= hyp2=hyp1-const3;
:= tipdist=hyp2*calc1;
:= lcd_init();
:= lcd_putcmd (clear_disp);
:= lcd_setposition(first_line);
:= printf (lcd_putchar,"tipdist=\%2.1f",tipdist);
:= lcd_setposition(second_line);
:= printf (lcd_putchar,"angle=\%2.1f",angle);
:= (true);
:= }
:= }
___________________________
This message was ported from CCS's old forum
Original Post ID: 13323
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

Re: LCD Problem
PostPosted: Wed Apr 02, 2003 2:27 pm     Reply with quote

:=Thanks for the quick reply!
:= The model number of the display is PC 1602-D
--------------------------------------------------------

Given the model number, I was able to get the data sheet.
I had to get it by doing a web search because this company,
PowerTip, regards their LCD data sheets as "secret".
That does not give me a high opinion of the company.

But anyway, here's the solution:

The problem is in your lcd_setposition() routine. You have
changed a line of Mr. Fick's code, and that's why it doesn't
work. You have this:

lcd_setdata (swap(cX|0x08));

and it needs to be this:

lcd_setdata( swap ( cX ) | 0x08);

This line outputs the high nybble of data. The data sheet
shows that the high nybble must have the top bit set = 1.
So first you should do the swap on cX, to get the high nybble
into bit positions 0-3. Then, you OR it with 0x08, to set the
D3 bit. Then you output it.

Your code could have worked, if you did this:

lcd_setdata (swap(cX | 0x80));

This sets the top bit of the high nybble, and then swaps the
high nybble into bit positions 0-3, and outputs it.
___________________________
This message was ported from CCS's old forum
Original Post ID: 13326
Trefor
Guest







Re: LCD Problem
PostPosted: Sat Apr 05, 2003 3:35 pm     Reply with quote

Thank you very much for this information!! I will modify the code and try it when Im back in college next week. Appologies for not replying untill now, I have been away working at the Aintree races.
I should learn from this, 'dont alter code that I do not understand!!'.
trefor




:=:=Thanks for the quick reply!
:=:= The model number of the display is PC 1602-D
:=--------------------------------------------------------
:=
:=Given the model number, I was able to get the data sheet.
:=I had to get it by doing a web search because this company,
:=PowerTip, regards their LCD data sheets as "secret".
:=That does not give me a high opinion of the company.
:=
:=But anyway, here's the solution:
:=
:=The problem is in your lcd_setposition() routine. You have
:=changed a line of Mr. Fick's code, and that's why it doesn't
:=work. You have this:
:=
:=lcd_setdata (swap(cX|0x08));
:=
:=and it needs to be this:
:=
:=lcd_setdata( swap ( cX ) | 0x08);
:=
:=This line outputs the high nybble of data. The data sheet
:=shows that the high nybble must have the top bit set = 1.
:=So first you should do the swap on cX, to get the high nybble
:=into bit positions 0-3. Then, you OR it with 0x08, to set the
:=D3 bit. Then you output it.
:=
:=Your code could have worked, if you did this:
:=
:=lcd_setdata (swap(cX | 0x80));
:=
:=This sets the top bit of the high nybble, and then swaps the
:=high nybble into bit positions 0-3, and outputs it.
___________________________
This message was ported from CCS's old forum
Original Post ID: 13445
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
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


Powered by phpBB © 2001, 2005 phpBB Group