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

PIC to LCD
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Mar 04, 2007 1:38 pm     Reply with quote

If the contrast is connected to ground, then it's good enough so that
you should see something.

It's possible that you have other problems with the LCD connections.

This page has an LCD to PIC schematic. Scroll down about 1/3
of the way on the page to see it. Notice that the upper four bits
on the LCD data bus are used. The schematic labels these as D4-D7.
http://www.mikroe.com/en/books/picbook/7_09chapter.htm

Here's another schematic that shows the LCD pins that must be used.
Again, notice that the upper 4 bits on the LCD data bus are used.
(Not the lower 4 bits).
http://www.electronic-engineering.ch/microchip/datasheets/lcd/lcd_connectivity.pdf


Here's a link to the Flex LCD driver in the CCS Code Library forum:
http://www.ccsinfo.com/forum/viewtopic.php?t=24661
The reason I posted that driver is because it's easy to use. One time,
someone complained that the CCS driver is too hard to configure
if you use different pins than the ones shown in the LCD.c file. The
person said that in PicBasic-Pro, you can just specify a list of the pins
that you want to use at the top of the file. He asked why can't CCS
provide a driver like this ? So from that, I got the idea to make a
a driver that could do this. I called it the Flexible LCD driver and posted
it in the Code library. I suggest that you use it. It's just easier.

-------
Edit: Fixed a typo.


Last edited by PCM programmer on Sun Mar 04, 2007 8:06 pm; edited 1 time in total
pijang
Guest







PostPosted: Sun Mar 04, 2007 7:54 pm     Reply with quote

Ok thanx.. I will try to use your flex lcd program first..
i Hope it will work..

Thanks a lot.. Laughing
pijang
Guest







PostPosted: Thu Mar 08, 2007 1:38 am     Reply with quote

I am quite confused about this program from flex_lcd.c

// If you only want a 6-pin interface to your LCD, then
// connect the R/W pin on the LCD to ground, and comment
// out the following line.

#define USE_LCD_RW 1 <-- Can i delete this coding from your program because im using 7-pin interface with my LCD.

// If the R/W signal is not used, then
// the busy bit can't be polled. One of
// the init commands takes longer than
// the hard-coded delay of 60 us, so in
// that case, lets just do a 5 ms delay
// after all four of them.

#ifndef USE_LCD_RW
delay_ms(5);
#endif

Can i delete this row too?
or i should put this coding although i will never use it?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Mar 08, 2007 1:49 am     Reply with quote

Quote:

#define USE_LCD_RW 1 <-- Can i delete this coding from your program because im using 7-pin interface with my LCD.

That line must be there for the 7-pin interface. Don't delete it.


Quote:

#ifndef USE_LCD_RW
delay_ms(5);
#endif

Can i delete this row too?
or i should put this coding although i will never use it?

It's conditional code. It will not be compiled for the 7-pin interface.
You don't need to delete it.

Just leave the driver unchanged. Don't edit the routines.
The #ifdef statements will configure the driver code and allow
the correct code to be compiled.

The main purpose of #ifdef statements is to allow you to easily change
the configuration of a program by just changing a #define statement
at the top of the program. It saves you from having to edit the
program. When you edit a program, you can make errors.
If a program can be configured with a #define statement, it's best
to follow that method.
pijang
Guest







PostPosted: Thu Mar 08, 2007 8:18 am     Reply with quote

ooo.. Now i understand
Because i think i must adjust it suite with my application
So i only change from port D to port B if i want to use port B as my output?

Ok. Thanx
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Mar 08, 2007 10:19 am     Reply with quote

That's right. The driver as posted, is already setup for a 7-pin interface.
You only need to change the list of pins (at the top of the file) to use your
pins on port B.
pijang
Guest







PostPosted: Sat Mar 10, 2007 5:49 pm     Reply with quote

My LCD is working and show the value.
But the problem is why this coding below does not appear?
I know i should use ascii number if i dont use the symbol "...."
But i quite confius why also it doesnt show anything

valuein = read_adc(1); //read from port AN1

valueout = valuein*0.035;
result = 48+valueout; <-- 48 is in ascii, which is 0

lcd_putc("\fThe value is\n"); <-- This one appear at my screen

lcd_putc(result); <-- This one didnt appear..

I already try to change all the word result in ascii, but also it doesnt show anything

Can u help me..
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Mar 10, 2007 11:29 pm     Reply with quote

Quote:
lcd_putc(result); <-- This one didnt appear..

Post a test program that I can compile. Show all variable declarations.
pijang
Guest







PostPosted: Sun Mar 11, 2007 2:33 am     Reply with quote

Below is my programming..

#include <16f877a.h>
#device adc=10;
#include <stdlib.h>
#include <math.h>
#use delay (clock = 4000000)
#fuses HS, noprotect, nowdt, nolvp
#byte PORTA = 5
#byte PORTB = 6
#define use_portb_lcd TRUE
#include <flex_lcd.c>

void main()
{
double valuein, valueout, result;


set_tris_b(0); //set port b as output
setup_port_a(ALL_ANALOG); //port a analog input
setup_adc(ADC_CLOCK_INTERNAL);

portb=0x00;
delay_ms(3000);
portb=0;

lcd_init();

do

{

set_adc_channel(1);
delay_us(20);
valuein = read_adc(1); //read from port AN1
valueout = valuein*0.035;
result=48+valueout;


lcd_putc("\f The value is\n");
lcd_putc( 48+valueout );

delay_ms(2000);

while(1);

}

}


Wink
Guest








PostPosted: Sun Mar 11, 2007 2:35 am     Reply with quote

Sorry, iforget to put the worh at include

#include <16f877a.h>
#device adc=10;
#include <stdlib.h>
#include <math.h>
#use delay (clock = 4000000)
#fuses HS, noprotect, nowdt, nolvp
#byte PORTA = 5
#byte PORTB = 6
#define use_portb_lcd TRUE
#include <flex_lcd.c>

void main()
{
double valuein, valueout, result;


set_tris_b(0); //set port b as output
setup_port_a(ALL_ANALOG); //port a analog input
setup_adc(ADC_CLOCK_INTERNAL);

portb=0x00;
delay_ms(3000);
portb=0;

lcd_init();

do

{

set_adc_channel(1);
delay_us(20);
valuein = read_adc(1); //read from port AN1
valueout = valuein*0.035;
result=48+valueout;


lcd_putc("\f The value is\n");
lcd_putc( 48+valueout );

delay_ms(2000);

while(1);

}

}
Guest








PostPosted: Sun Mar 11, 2007 2:38 am     Reply with quote

Sir, actually at the include coding have stdlib.h, math.h and flex_lcd.c
I dont know why it does not appear when i posted at this forum

#include <16f877a.h>
#device adc=10;
#include
#include
#use delay (clock = 4000000)
#fuses HS, noprotect, nowdt, nolvp
#byte PORTA = 5
#byte PORTB = 6
#define use_portb_lcd TRUE
#include

void main()
{
double valuein, valueout, result;


set_tris_b(0); //set port b as output
setup_port_a(ALL_ANALOG); //port a analog input
setup_adc(ADC_CLOCK_INTERNAL);

portb=0x00;
delay_ms(3000);
portb=0;

lcd_init();

do

{

set_adc_channel(1);
delay_us(20);
valuein = read_adc(1); //read from port AN1
valueout = valuein*0.035;
result=48+valueout;


lcd_putc("\f The value is\n");
lcd_putc( 48+valueout );

delay_ms(2000);

while(1);

}

}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Mar 11, 2007 1:12 pm     Reply with quote

The #include files are missing because when you posted your code,
you didn't disable HTML. There's a tickbox below the posting window
to do this. It looks like this:
Quote:
x Disable HTML in this post

I have tried to get the forum Admin to disable HTML by default for
the whole forum, but it hasn't happened.


Regarding your program, lcd_putc() can't accept a 'double' as a
parameter. It's expecting an 8-bit unsigned integer. You have
to convert the result of the expression into an integer by 'casting' it.
Example:
Code:
putc((int8)(48+valueout));
pijang
Guest







PostPosted: Sun Mar 11, 2007 9:19 pm     Reply with quote

what do u mean by casting?
Is it i have to change the double function to int8 at the top coding?

I have read some notes telling that we must limit the input value.
For example if my input is until 4 or 5 decimal places, i have to cut it down to 2 or 3 depends on my PIC. Is it right?
Then can i know how to limit the input value until 1 or 2 decimal places
For example let say 2.3569 become 2.35..

Then i have to set the program become like this
lcd_putc(48+D1&"."&48+D2&48+D3);

D1=first digit which is 2
D2=second digit after "." which is 3
D3=third digit which is 5

How do i want to set this coding if this assumption is correct?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Mar 11, 2007 10:21 pm     Reply with quote

http://www.ccsinfo.com/forum/viewtopic.php?t=29157&highlight=printf+lcdputc
pijang
Guest







PostPosted: Mon Mar 12, 2007 2:07 am     Reply with quote

oo. Now i understand...
So i must use printf command for my analog input..
So how about the rest of my question..

can i limit the value from my input until 2 decimal places?
and what i should declare at the top of this coding?

Is it just using the double function and change lcd_putc to prinf
or i have to use int8 instead of double function?

for example
int8 valuein, valueout, result;
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 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


Powered by phpBB © 2001, 2005 phpBB Group