View previous topic :: View next topic |
Author |
Message |
pijang Guest
|
PIC to LCD |
Posted: Fri Mar 02, 2007 2:01 am |
|
|
Hi everybody
Actually i want to ask something about my project
im using PIC16F877A and LCD display 16x2.
Im using ccs compiler to program and galep 32 to burn the program into PIC.
The problem is there is nothing appear at my LCD.
Can somebody check this coding for me..
Is there anything to add?
i modified a little bit from lcd.c to lcd2.c because im using port B
The given coding in the CCS is using PORT D as its output.
#include <16f877a.h>
#device adc=10;
#use delay (clock = 4000000)
#fuses xt, noprotect, nowdt, nolvp
#byte PORTA = 5
#byte PORTB = 6
#define use_portb_lcd TRUE
#include <lcd2.c>
main()
{
int valuein, valueout;
set_tris_b(0); //set port b as output
setup_port_a(ALL_ANALOG); //port a all analog input
setup_adc(ADC_CLOCK_INTERNAL);
set_adc_channel(1); //using port AN1
valuein = read_adc(1); //read from port AN1
valueout = valuein*2.8;
lcd_init(); //LCD initializing
do
{
lcd_putc("\fThe value is\n");
lcd_putc(48+valueout);
delay_ms(1000);
}
while(1);
}
Hopefully, somebody can reply
Thank u in advance.. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
pijang Guest
|
|
Posted: Fri Mar 02, 2007 2:26 am |
|
|
Actually im a little bit confius about flex_lcd.c??? :
I have to add this code or what am i supposed to do?
Can u just tell me which one is wrong from my coding. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Mar 02, 2007 2:46 am |
|
|
Quote: | Can u just tell me which one is wrong from my coding. |
You said that nothing is appearing on your LCD. Does that mean that
the text shown in bold below does not appear on the LCD ?
Quote: | lcd_putc("\fThe value is\n"); |
You also said that you modifed the lcd.c driver file. Where did the
lcd.c driver come from ? Is it the CCS driver from this directory:
Quote: | c:\Program Files\Picc\Drivers\lcd.c |
What changes did you make to lcd.c ? What pins are you using ? |
|
|
pijang Guest
|
|
Posted: Sun Mar 04, 2007 9:24 am |
|
|
Yup. The word the value is didn't appear at my LCD.
And what i read, the LCD will show one row of black squares.
But this also didnt happen. Is it my connection for VLC didnt correct?
I connect to resistor and then to ground..
I modify the lcd.c from the ccs directory. im using port B as my output.. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Mar 04, 2007 1:38 pm |
|
|
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
|
|
Posted: Sun Mar 04, 2007 7:54 pm |
|
|
Ok thanx.. I will try to use your flex lcd program first..
i Hope it will work..
Thanks a lot.. |
|
|
pijang Guest
|
|
Posted: Thu Mar 08, 2007 1:38 am |
|
|
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
|
|
Posted: Thu Mar 08, 2007 1:49 am |
|
|
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
|
|
Posted: Thu Mar 08, 2007 8:18 am |
|
|
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
|
|
Posted: Thu Mar 08, 2007 10:19 am |
|
|
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
|
|
Posted: Sat Mar 10, 2007 5:49 pm |
|
|
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
|
|
Posted: Sat Mar 10, 2007 11:29 pm |
|
|
Quote: | lcd_putc(result); <-- This one didnt appear.. |
Post a test program that I can compile. Show all variable declarations. |
|
|
pijang Guest
|
|
Posted: Sun Mar 11, 2007 2:33 am |
|
|
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);
}
}
|
|
|
Guest
|
|
Posted: Sun Mar 11, 2007 2:35 am |
|
|
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);
}
} |
|
|
|