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

Having trouble getting 8x2 LCD working with 16F689

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



Joined: 09 Aug 2004
Posts: 97

View user's profile Send private message

Having trouble getting 8x2 LCD working with 16F689
PostPosted: Wed Apr 11, 2012 4:24 pm     Reply with quote

Hi All,

I recently upgraded an existing design from a 16F648A to a 16F689 because I needed a couple of additional I/O, and I wanted to take advantage of the higher speed internal oscillator available in the 16F689. Unfortunately, I can't get an 8x2 LCD to work with the new design. The top row is all solid squares like the LCD is not being properly initialized. I am using the Flex_LCD.c driver for this effort.

I've worked with character LCD's for many years, so of course I checked the power connections, and the Vee (contrast) voltage, and everything looks good. All the signal lines from the LCD to the PIC have been rung out, and an LED connected to each signal line at the LCD socket can be flashed. I even went so far as to connect a 16F648A to the new board using wire wrap wires, and the display works on the new board with the old PIC, just not with the 16F689 device. In short, my hardware seems to be OK.

The LCD is the only thing that is not working on the new design. I can flash diagnostic LED's at predictable rates/durations, and my serial Comms are working just fine, so I know that the 16f689 is basically working correctly.

I can run the following test program on the old design:

Code:

//-----< Include Files, setup fuses >-----
#include <16f648a.h>

#fuses INTRC_IO, NOWDT, NOPROTECT, NOLVP, NOBROWNOUT

// Tell compiler clock speed is 4.00 MHZ
#use delay(clock=4000000)

#include <flex_lcd.c>

//========================================
void main()
{
lcd_init();

lcd_putc("Hello  1\n");
lcd_putc("World  2");

while(1);
}


With the following Flex_LCD pin connections:

Code:

#define LCD_DB4   PIN_A0
#define LCD_DB5   PIN_A1
#define LCD_DB6   PIN_A2
#define LCD_DB7   PIN_A3

#define LCD_E     PIN_B3
#define LCD_RS    PIN_A4

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


And everything works fine.

I cannot run the following test program on the new design:

Code:

//-----< Include Files, setup fuses >-----
#include <16f689.h>
#fuses INTRC, NOWDT, NOPROTECT, NOBROWNOUT, PUT

// Tell compiler clock speed is 8.00 MHZ
#use delay(clock=8000000)

#include <flex_lcd_689.c>

//========================================
void main()
{
lcd_init();

lcd_putc("Hello  1\n");
lcd_putc("World  2");

while(1);
}


With the following Flex_LCD pin connections:

Code:

#define LCD_DB4   PIN_C0
#define LCD_DB5   PIN_C1
#define LCD_DB6   PIN_C2
#define LCD_DB7   PIN_C3

#define LCD_E     PIN_B4
#define LCD_RS    PIN_A2

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


And the code does not work at all.

I looked at the .lst file for each compilation with Beyond Compare, and they are very similar, except I think for the pin defines. There does seem to be a large block of code at the beginning of Main() for the new design that is not present in the old design, but it's not clear (to me) what it's doing?

I'm using a relatively old version of the PCM compiler, v4.050, and I'm wondering if something isn't being handled properly in this version for the 16f689 device? I'm very hesitant to blame the compiler, but the hardware seems to be OK.

If someone could take a look at the two .lst files and offer an opinion whether the compiler is generating the "correct" code, I'd be grateful. Any other suggestions are also welcome!

Thanks,

John
_________________
John Morley
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Apr 11, 2012 5:24 pm     Reply with quote

Try adding the lines shown in bold below, in the exact positions shown:
Quote:

#byte ANSEL = getenv("SFR:ANSEL")
//==========================
void main()
{

ANSEL = 0x00;

lcd_init();
John Morley



Joined: 09 Aug 2004
Posts: 97

View user's profile Send private message

PostPosted: Thu Apr 12, 2012 6:30 am     Reply with quote

Hi PCM,

I suspect that you are on to something here, but unfortunately my version of the compiler wasn't happy with that fix. The two added lines of code, added in the locations you indicated, resulted in the following errors:

Code:


*** Error 12 "LCD_Test_689.c" Line 14(1,2): Undefined identifier
*** Error 12 "LCD_Test_689.c" Line 17(7,12): Undefined identifier   ANSEL



I guess this means that my compiler is "unaware" of the ANSEL register location for this part, so the getenv() function wont work to find it? I think that means I should be able to hard code the address of this register from the datasheet, right? I'll take a look and see if I can figure that out!

John
_________________
John Morley
John Morley



Joined: 09 Aug 2004
Posts: 97

View user's profile Send private message

PostPosted: Thu Apr 12, 2012 6:41 am     Reply with quote

Hi PCM,

OK, that was it! Your original hunch was correct!

This code solved my LCD problem:

Code:

#byte ANSEL    = 0x11e

//========================================
void main()
{

ANSEL = 0x00;


BTW, I had a similar thought about this issue, and tried adding this line of code to my original project, but it had no effect. It looks like v4.050 doesn't handle the ANSEL register correctly!

Code:

   Setup_ADC_Ports( NO_ANALOGS);


Thanks a million, and now I'm off to update my compiler!

John
_________________
John Morley
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