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

Crystalfontz 20x4 LCD with PIC18F452

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



Joined: 15 Mar 2004
Posts: 6

View user's profile Send private message

Crystalfontz 20x4 LCD with PIC18F452
PostPosted: Tue Mar 16, 2004 12:07 am     Reply with quote

I'm trying to interface a 20x4 LCD display I have with my PIC18F452. I've read the forum here, and checked examples and whatnot, and I can't get it to work. The display uses the standard hitachi controller.

The display datasheet is here:
http://www.crystalfontz.com/products/2004a-color/CFAH2004AGGBJP.pdf

and my code is as follows:
Code:

#if defined(__PCB__)
#include <16c56.h>
#fuses HS,NOWDT,NOPROTECT
#use delay(clock=20000000)

#elif defined(__PCM__)
#include <16F877.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)

#elif defined(__PCH__)
#include <18F452.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=10000000)
#endif

#include <lcd420.c>

void main()
{

   lcd_init();

   lcd_putc("\fReady...\n");

   while (TRUE);
}


I have the display wired up correctly as far as I can tell and the backlight turned on. I have a pot connected to the contrast, so i can see for sure that its not that. I can't for the life of me figure out whats going wrong. When I turn it on, it just doesn't do anything.

Anyone offer any help? see anything I missed?

Thanks,
-Flecko
treitmey



Joined: 23 Jan 2004
Posts: 1094
Location: Appleton,WI USA

View user's profile Send private message Visit poster's website

PostPosted: Tue Mar 16, 2004 12:32 pm     Reply with quote

Are you using circuit documentation that came with the LCD??
I have seen some circuits that use pull-up resisters,..perhaps you need some. I'm not sure.
Mark Weir



Joined: 11 Sep 2003
Posts: 51
Location: New Zealand

View user's profile Send private message

LCD and 452
PostPosted: Tue Mar 16, 2004 12:40 pm     Reply with quote

Hi,
Can you post your include file, It maybe one of the designated output pins is incorrect

Cheers
Mark
Flecko



Joined: 15 Mar 2004
Posts: 6

View user's profile Send private message

PostPosted: Tue Mar 16, 2004 2:57 pm     Reply with quote

Sure...the lcd420.c is a driver that came with the compiler, I assumed it was standard. I've tried using the lcd.c driver on port B as well. Neither seems to work.

Code:

////////////////////////////////////////////////////////////////////////////
////                             LCD420.C                               ////
////            Driver for common 4x20 LCD modules                      ////
////                                                                    ////
////  lcd_init()   Must be called before any other function.            ////
////                                                                    ////
////  lcd_putc(c)  Will display c on the next position of the LCD.      ////
////                     The following have special meaning:            ////
////                      \f  Clear display                             ////
////                      \n  Go to start of second line                ////
////                      \b  Move back one position                    ////
////                                                                    ////
////  lcd_gotoxy(x,y) Set write position on LCD (upper left is 1,1)     ////
////                                                                    ////
////  lcd_getc(x,y)   Returns character at position x,y on LCD          ////
////                                                                    ////
////////////////////////////////////////////////////////////////////////////
////        (C) Copyright 1996,1997 Custom Computer Services            ////
//// This source code may only be used by licensed users of the CCS C   ////
//// compiler.  This source code may only be distributed to other       ////
//// licensed users of the CCS C compiler.  No other use, reproduction  ////
//// or distribution is permitted without written permission.           ////
//// Derivative programs created using this software in object code     ////
//// form are not restricted in any way.                                ////
////////////////////////////////////////////////////////////////////////////

// As defined in the following structure the pin connection is as follows:
//     B0  enable
//     B1  rs
//     B2  rw
//     B4  D4
//     B5  D5
//     B6  D6
//     B7  D7
//
//   LCD pins D0-D3 are not used and PIC B3 is not used.

struct lcd_pin_map {                 // This structure is overlayed
           BOOLEAN enable;           // on to an I/O port to gain
           BOOLEAN rs;               // access to the LCD pins.
           BOOLEAN rw;               // The bits are allocated from
           BOOLEAN unused;           // low order up.  ENABLE will
           int     data : 4;         // be pin B0.
        } lcd;

#byte lcd = 6                        // This puts the entire structure
                                     // on to port B (at address 6)

#define lcd_type 2           // 0=5x7, 1=5x10, 2=2 lines


BYTE const LCD_INIT_STRING[4] = {0x20 | (lcd_type << 2), 0xc, 1, 6};
                             // These bytes need to be sent to the LCD
                             // to start it up.


                             // The following are used for setting
                             // the I/O port direction register.

struct lcd_pin_map const LCD_WRITE = {0,0,0,0,0}; // For write mode all pins are out
struct lcd_pin_map const LCD_READ = {0,0,0,0,15}; // For read mode data pins are in


BYTE lcdline;

BYTE lcd_read_byte() {
      BYTE low,high;

      set_tris_b(LCD_READ);
      lcd.rw = 1;
      delay_cycles(1);
      lcd.enable = 1;
      delay_cycles(1);
      high = lcd.data;
      lcd.enable = 0;
      delay_cycles(1);
      lcd.enable = 1;
      delay_us(1);
      low = lcd.data;
      lcd.enable = 0;
      set_tris_b(LCD_WRITE);
      return( (high<<4) | low);
}


void lcd_send_nibble( BYTE n ) {
      lcd.data = n;
      delay_cycles(1);
      lcd.enable = 1;
      delay_us(2);
      lcd.enable = 0;
}


void lcd_send_byte( BYTE address, BYTE n ) {

      lcd.rs = 0;
      while ( bit_test(lcd_read_byte(),7) ) ;
      lcd.rs = address;
      delay_cycles(1);
      lcd.rw = 0;
      delay_cycles(1);
      lcd.enable = 0;
      lcd_send_nibble(n >> 4);
      lcd_send_nibble(n & 0xf);
}


void lcd_init() {
    BYTE i;

    set_tris_b(LCD_WRITE);
    lcd.rs = 0;
    lcd.rw = 0;
    lcd.enable = 0;
    delay_ms(15);
    for(i=1;i<=3;++i) {
       lcd_send_nibble(3);
       delay_ms(5);
    }
    lcd_send_nibble(2);
    for(i=0;i<=3;++i)
       lcd_send_byte(0, LCD_INIT_STRING[i]);
}


void lcd_gotoxy( BYTE x, BYTE y) {
   BYTE address;

   switch(y) {
     case 1 : address=0x80;break;
     case 2 : address=0xc0;break;
     case 3 : address=0x94;break;
     case 4 : address=0xd4;break;
   }
   address+=x-1;
   lcd_send_byte(0,address);
}

void lcd_putc( char c) {
   switch (c) {
     case '\f'   : lcd_send_byte(0,1);
                   lcdline=1;
                   delay_ms(2);
                                           break;
     case '\n'   : lcd_gotoxy(1,++lcdline);        break;
     case '\b'   : lcd_send_byte(0,0x10);  break;
     default     : lcd_send_byte(1,c);     break;
   }
}

char lcd_getc( BYTE x, BYTE y) {
   char value;

    lcd_gotoxy(x,y);
    lcd.rs=1;
    value = lcd_read_byte();
    lcd.rs=0;
    return(value);
}



I'm gonna try, sometime tonight, writing an interface by hand to see if it works. My next resort, is to wire 4 more data lines up to my LCD and then see if I can get it working with another LCD project of mine that I know works, it just uses the 8 bit interface, which I wanted to avoid for this project.

If anyone has further suggetions, I'm all ears.
Thanks again,
-Flecko
Mark Weir



Joined: 11 Sep 2003
Posts: 51
Location: New Zealand

View user's profile Send private message

LCD and 452
PostPosted: Tue Mar 16, 2004 3:20 pm     Reply with quote

Hi Again,
I am not sure of your experience so if I am stating the obvious please forgive me.

I have used this driver very sucessfully with all kinds of modules. There are a few things to double check.

1. Make sure that the Enable, RS and RW pins are connected to to correct pins on both the PIC and the display.

2. I use a 10K pot with one end connected to the+5, the other to gnd and the wiper to pin 3 for contrast. this pot must be setup when you run the programme first time. It usually sits round towards the gnd end for best contrast.

3. Some module need a small delay in your main programme to initialise properly, you could try say 20mS delay after the lcd init.

4. You could try looking at the pins connected to the display with a scope or even an LED to see if there is any activity on them.

Hope this helps

Cheers
Mark
Flecko



Joined: 15 Mar 2004
Posts: 6

View user's profile Send private message

PostPosted: Tue Mar 16, 2004 5:05 pm     Reply with quote

I think my power supply I'm using isn't sufficient. Its only 190ma, and I have quite a bit of other circuitry connected.

My 500ma supply should arrive tomorrow, I'll post my findings.

Thanks for all the help and suggetsions,
-Flecko
newguy
Guest







port b address
PostPosted: Tue Mar 16, 2004 7:58 pm     Reply with quote

Your problem is with the address of port b as given in the lcd.c file. The "#byte lcd = 6" line is the culprit. In the 16 series, port b's memory location is at address 0x6. In the 18 series, it's different. I'm sorry, but I don't have the data sheet for the 18F family in front of me, but I think (if memory serves) that the address for port b is 0xf81. Double check the data sheet for your particular pic, you'll find the info there.

Hope this helps.

-- Mark
Flecko



Joined: 15 Mar 2004
Posts: 6

View user's profile Send private message

PostPosted: Tue Mar 16, 2004 11:53 pm     Reply with quote

Sad to say, but even if that address was a problem, I'm the stupid one. I left my good power supply at home, and used one I had laying around here at school. It turns out, its output is AC, not DC.

I had the power to my system coming through a 7805 voltage regulator. So how much damage do you think the AC supply did to my circuit? I had a 30 dollar backlit 20x4 LCD hooked up. I will be royally jacked if I ruined it. My DC supply should be arriving here at school in the mail tomorrow, so hopefully I can test it and see what I ruined.

Anyone else ever done this? ruined anything? know what will be ruined?
Thanks everyone,
-Flecko
Flecko



Joined: 15 Mar 2004
Posts: 6

View user's profile Send private message

PostPosted: Wed Mar 17, 2004 2:37 pm     Reply with quote

Well, the pic was unharmed. Not sure about my LCD yet, but at least the circuit works again, despite my stupidity.

I thnk from now on I'll have some safety diodes in place.
Thanks everyone,
-Flecko
Flecko



Joined: 15 Mar 2004
Posts: 6

View user's profile Send private message

PostPosted: Wed Mar 17, 2004 2:43 pm     Reply with quote

It works!!!

Thanks everyone. And you were right newguy. The lcd420.c driver doesn't work with the 18F line of pics. I used the lcd.c driver(which has the port b address at 0xf81) and it works fine.

Thanks everyone, you've all been great Very Happy

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