View previous topic :: View next topic |
Author |
Message |
GhostofK
Joined: 04 Jun 2006 Posts: 6
|
Help with using flexlcd.c with a PIC16F690 |
Posted: Mon Jun 05, 2006 1:22 pm |
|
|
Hi, I'm trying to get a LCD to work with my PIC16F690. The LCD has one of those Hitachi LCD chips on it and is a 14 pin device. I'm using the flexible lcd driver that's posted in the code library section of the forums. Unfortunately, it's not working for me, so I was wondering if someone could give me some help.
The only changes I made to the flexlcd.c part of the code was to change the pin defines to match up with how I connected the LCD to my PIC. The changes are below.
Quote: |
#define LCD_DB4 PIN_C3
#define LCD_DB5 PIN_C6
#define LCD_DB6 PIN_C7
#define LCD_DB7 PIN_B7
#define LCD_E PIN_B6
#define LCD_RS PIN_B5
// 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 LCD_RW PIN_A2
//#define USE_LCD_RW 1
|
The code that I'm using to test out the program is below:
Quote: |
#include <16F690.h>
#fuses HS, NOWDT, PUT
#use delay(clock=4000000)
#include <flexlcd.c>
void main_init(void);
void main(void){
main_init();
lcd_putc("\fReady...\n");
while(1);
}
void main_init(void){
//setup ADC, PWM and LCD here
setup_adc(ADC_CLOCK_DIV_8);
setup_adc_ports(sAN0);
setup_adc_ports(sAN1);
setup_adc_ports(sAN2);
setup_adc_ports(sAN4);
setup_ccp1(CCP_PWM);
setup_timer_2(T2_DIV_BY_1, 24, 1);
set_pwm1_duty(12);
lcd_init();
}
|
All I get on the LCD screen are these black boxes that are default when the LCD is simply powered.
Any help would be great, thanks! |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Jun 05, 2006 1:43 pm |
|
|
1. Do you have the R/W pin on the LCD connected to ground ?
You have the driver configured for that mode, so you need to
have it connected to GND.
2. Do you have a 10K trimpot connected to the contrast pin on
your LCD ? You should set the trimpot so it outputs 0.4 volt
onto the LCD's contrast pin. This voltage should allow you
to see something on the LCD if the driver is working. |
|
|
GhostofK
Joined: 04 Jun 2006 Posts: 6
|
|
Posted: Mon Jun 05, 2006 2:21 pm |
|
|
1. I do have R/W to ground.
2. I installed a 10k pot between the VEE pin and ground now but no change. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Jun 05, 2006 2:39 pm |
|
|
Quote: | #define LCD_DB4 PIN_C3
#define LCD_DB5 PIN_C6
#define LCD_DB6 PIN_C7
#define LCD_DB7 PIN_B7 |
1. Do you have the four PIC pins connected to DB4-DB7 on LCD ?
Could you have accidently used pins DB0-DB3 on the LCD ?
When the LCD is used in 4-bit bus mode, pins DB4-DB7 must be used.
Verify that you have it connected this to DB4-DB7.
2. What is your compiler version ? This number is given at the top of
the .LST file, which is in your project folder. It will be a number
similar to 3.191, 3.236, 3.249, etc.
3. Check all connections, to make sure they are correct.
4. Use a simplified version of your program, which only tests
the LCD problem:
Code: | #include <16F690.h>
#fuses HS, NOWDT, PUT
#use delay(clock=4000000)
#include <flex_lcd.c> // Has modified pin list.
void main(void)
{
setup_adc(NO_ANALOGS);
setup_comparator(NC_NC_NC_NC);
lcd_init();
lcd_putc("\fReady...\n");
while(1);
} |
|
|
|
GhostofK
Joined: 04 Jun 2006 Posts: 6
|
|
Posted: Mon Jun 05, 2006 3:20 pm |
|
|
Ok! I tried the simplified version and it works! But I don't know why? Could the analog setup be getting in the way? What was the point of the line "setup_comparator(NC_NC_NC_NC);"? Please let me know! (And how would I adapt it so that I can still use the ADC and the PWM?) |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Jun 05, 2006 3:25 pm |
|
|
Post your compiler version. |
|
|
GhostofK
Joined: 04 Jun 2006 Posts: 6
|
|
Posted: Mon Jun 05, 2006 3:30 pm |
|
|
Compiler version is 3.243 |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Jun 05, 2006 4:17 pm |
|
|
The CCS startup code doesn't shut off the comparators properly, but
the setup_comparator(NC_NC_NC_NC) function does.
In other words, the startup code has a bug, but the function works OK.
So as a work-around for the bug, always shut off the comparators
with the function call. |
|
|
GhostofK
Joined: 04 Jun 2006 Posts: 6
|
|
Posted: Mon Jun 05, 2006 4:28 pm |
|
|
It works great! Thanks so much! |
|
|
|