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

Flexible LCD driver
Goto page Previous  1, 2, 3, 4, 5, 6, 7  Next
 
Post new topic   Reply to topic    CCS Forum Index -> Code Library
View previous topic :: View next topic  
Author Message
BrunoCF



Joined: 14 Aug 2007
Posts: 2
Location: SP - Brasil

View user's profile Send private message MSN Messenger

Thanks
PostPosted: Tue Aug 14, 2007 5:00 am     Reply with quote

Thank you for the code. Worked just fine for me.
nmeyer



Joined: 09 Jul 2004
Posts: 70

View user's profile Send private message

PostPosted: Fri Aug 17, 2007 8:38 am     Reply with quote

I have purchased the PICDEM 2 PLus board and i am using the Flex_lcd driver for the lcd. However, i am finding that if i try to write more than 7 characters on a line, it locks up the PIC.
#include <18F4520.h>
#device adc=8
#include <stdio.h>
#include <math.h>



#FUSES NOWDT //No Watch Dog Timer
#FUSES WDT128 //Watch Dog Timer uses 1:128 Postscale
#FUSES HS //High speed Osc (> 4mhz)
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOBROWNOUT //No brownout reset
#FUSES BORV25 //Brownout reset at 2.5V
#FUSES NOPUT //No Power Up Timer
#FUSES NOCPD //No EE protection
#FUSES STVREN //Stack full/underflow will cause reset
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOWRT //Program memory not write protected
#FUSES NOWRTD //Data EEPROM not write protected
#FUSES IESO //Internal External Switch Over mode enabled
#FUSES FCMEN //Fail-safe clock monitor enabled
#FUSES PBADEN //PORTB pins are configured as analog input channels on RESET
#FUSES NOWRTC //configuration not registers write protected
#FUSES NOWRTB //Boot block not write protected
#FUSES NOEBTR //Memory not protected from table reads
#FUSES NOEBTRB //Boot block not protected from table reads
#FUSES NOCPB //No Boot Block code protection
#FUSES LPT1OSC //Timer1 configured for low-power operation
#FUSES MCLR //Master Clear pin enabled
#FUSES XINST //Extended set extension and Indexed Addressing mode enabled



#use delay(clock=4000000,RESTART_WDT)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)

#include <Flex_LCD>

void main()
{

setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_adc(ADC_OFF|ADC_TAD_MUL_0);
setup_psp(PSP_DISABLED);
setup_spi(SPI_SS_DISABLED);
setup_wdt(WDT_OFF);
setup_timer_0(RTCC_INTERNAL);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
while (true)
{
output_low(PIN_B0);
output_low(PIN_B1);
output_low(PIN_B2);
output_low(PIN_B3);
output_low(PIN_C2);
delay_ms(1000);
output_high(PIN_B0);
output_high(PIN_B1);
output_high(PIN_B2);
output_high(PIN_B3);
//output_high(PIN_C2);
delay_ms(1000);
printf("Hello\n\r");
output_high(PIN_D7);
lcd_init();
printf(lcd_putc,"\fRawson\n");
printf(lcd_putc,"Accurat");
}
}
Does anyone have any idea what i am doing wrong?
PCM programmer



Joined: 06 Sep 2003
Posts: 20318

View user's profile Send private message

PostPosted: Fri Aug 17, 2007 9:07 am     Reply with quote

Quote:
#FUSES XINST //Extended set extension

This fuse setting will cause the program to run erratically.
Change it to NOXINST. Do this in all your programs for PICs that
have that fuse.
nmeyer



Joined: 09 Jul 2004
Posts: 70

View user's profile Send private message

PostPosted: Fri Aug 17, 2007 12:12 pm     Reply with quote

Thanks for the input. Do you have any ideas on why i can only do 7 characters?
PCM programmer



Joined: 06 Sep 2003
Posts: 20318

View user's profile Send private message

PostPosted: Fri Aug 17, 2007 12:40 pm     Reply with quote

1. The 'XINST' fuse could be the cause of it doing only seven characters.
Make sure you change it to 'NOXINST' in all your programs.
It's essential.

2. Post the list of #define statements that show the connections
between the LCD and the PIC. These #define statements are at
the start of the Flex_lcd.c driver, and must match the connections
on your PIC board.

3. Your test program is too complicated. Try a very simple program.
Example:
Code:

#include <18F4520.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 4000000)

#include "flex_lcd.c"
   
//==========================
void main()
{
lcd_init();

lcd_putc("\fHello World\n");
lcd_putc("Line Number 2");
 

while(1);
}
nmeyer



Joined: 09 Jul 2004
Posts: 70

View user's profile Send private message

PostPosted: Fri Aug 17, 2007 3:17 pm     Reply with quote

I changed the setting to NOXINST and it still performed the same. Here are my defines from the flex_lcd file.

// These pins are for the Microchip PicDem2-Plus board,
// which is what I used to test the driver. Change these
// pins to fit your own board.

#define LCD_DB4 PIN_D0
#define LCD_DB5 PIN_D1
#define LCD_DB6 PIN_D2
#define LCD_DB7 PIN_D3

#define LCD_E PIN_D6
#define LCD_RS PIN_D4
#define LCD_RW PIN_D5

// 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

//========================================

#define lcd_type 2 // 0=5x7, 1=5x10, 2=2 lines
#define lcd_line_two 0x40 // LCD RAM address for the 2nd line
PCM programmer



Joined: 06 Sep 2003
Posts: 20318

View user's profile Send private message

PostPosted: Fri Aug 17, 2007 3:52 pm     Reply with quote

Based on those pin numbers, you are apparently using the new "Rohs
update" version of the PicDem2-Plus board.

That version of the board can be identified by a surface-mount pad
pattern at the bottom of the proto-typing area on the board. The older
version of the board doesn't have that surface-mount area on it.

If you have the new Rohs version of the board you need to use the
test program shown below. Notice how it adds a #define statement
for the LCD power pin, and it adds two new lines at the start of main().
Those lines are essential for the new Rohs version of the PicDem2-Plus.

Here are the pin assignments that you must set at the top of the Flex
driver. Also, for the "Rohs" PicDem2-Plus board, you must comment
out the "#define USE_LCD_RW 1" line, as shown below.
Code:

// These are the pin assignments used for the "Rohs"
// PicDem2-Plus:
#define LCD_DB4   PIN_D0
#define LCD_DB5   PIN_D1
#define LCD_DB6   PIN_D2
#define LCD_DB7   PIN_D3

#define LCD_E     PIN_D6
#define LCD_RS    PIN_D4
#define LCD_RW    PIN_D5

// The following line must be commented out for
// the "Rohs" board.

// #define USE_LCD_RW   1   
     


Test program for "Rohs" version of PicDem2-Plus board:
Code:

#include <18F4520.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 4000000)

#define LCD_POWER  PIN_D7

#include "Flex_LCD.c"

//============================
void main()
{
output_high(LCD_POWER);  // Turn on power to LCD
output_low(LCD_RW);      // Set R/W pin on LCD to a low level

lcd_init();              // Initialize the LCD

lcd_putc("\fHello World\n");
lcd_putc("Line Number 2");

while(1);
}
nmeyer



Joined: 09 Jul 2004
Posts: 70

View user's profile Send private message

PostPosted: Tue Aug 21, 2007 11:20 am     Reply with quote

These changes seem to be working well.
Thanks
d



Joined: 04 Sep 2007
Posts: 3

View user's profile Send private message

PostPosted: Thu Sep 06, 2007 8:32 am     Reply with quote

thanks for the code
works perfect, first time!

d.
syahrul.s



Joined: 09 Nov 2007
Posts: 6

View user's profile Send private message

PostPosted: Fri Nov 09, 2007 2:14 am     Reply with quote

can the flex_lcd.c be used with LCD-016M002B by Vishay??
PCM programmer



Joined: 06 Sep 2003
Posts: 20318

View user's profile Send private message

PostPosted: Fri Nov 09, 2007 11:21 am     Reply with quote

The Vishay LCD has a KS0066 controller, which is compatible with
the HD44780. So it should work OK with the Flex driver.
Praad



Joined: 15 May 2008
Posts: 5

View user's profile Send private message

PostPosted: Thu May 15, 2008 10:42 am     Reply with quote

[ sorry for my bad english I'm .fr ;p ]

Hi,

Great work PCMProgrammer.

I've just tested lcd_flex on my PIC16F876 with a 2x16 LCD : gdm1602a
I changed pins etc. With Proteus ISIS all is ok, however when I test the program on the real pic & lcd it doesn't works. It print black squares (is it the good word ?).

Why ? :s

http://elmicro.com/files/lcd/gdm1602a_datasheet.pdf


thx
PCM programmer



Joined: 06 Sep 2003
Posts: 20318

View user's profile Send private message

PostPosted: Thu May 15, 2008 12:25 pm     Reply with quote

The LCD displays black squares when:

1. The LCD is not initialized.
or
2. The contrast voltage is not correct.


So, to fix this:
1. Make sure you call the lcd_init() function at the start of main().
Also make sure the connections to the LCD are correct.
The data pins on the LCD must be DB4-DB7 (do not use DB0-DB3).

2. Set the contrast voltage to 0.5 volts. Use a voltage divider or
a trimpot to get this voltage. The contrast pin is called "Vo" in the
LCD data sheet. It's on pin 3 of the LCD.
Praad



Joined: 15 May 2008
Posts: 5

View user's profile Send private message

PostPosted: Thu May 15, 2008 12:49 pm     Reply with quote

I use DB4-DB7 data pins on the LCD.
For the contrast voltage I use a poteniometer (RVLCD) :



But with all these things the LCD displays black squares Confused

I tried this morning (at school) to make it works but without success.


Thx
PCM programmer



Joined: 06 Sep 2003
Posts: 20318

View user's profile Send private message

PostPosted: Thu May 15, 2008 12:57 pm     Reply with quote

In your schematic, you have the R/W pin connected to ground.
With that connection, you must "comment out" the following line
in the Flex LCD driver. Do this by adding comment symbols in
front of the line. Example:
Quote:
// #define USE_LCD_RW 1


Then re-compile and test it.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> Code Library All times are GMT - 6 Hours
Goto page Previous  1, 2, 3, 4, 5, 6, 7  Next
Page 4 of 7

 
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