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

Help with PIC16f877a and LCD Lmb162A....Urgent!
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
raz



Joined: 22 Feb 2012
Posts: 22

View user's profile Send private message

Help with PIC16f877a and LCD Lmb162A....Urgent!
PostPosted: Wed Feb 22, 2012 11:23 am     Reply with quote

Hi
I have problem with the LCD lmb162a and pic16f877a using PICC compiler and driver lcd.c. The Lcd isn't displaying anything not even then cursor just displaying the dark squares and I changed the 5k pot for the contrast and still got nothing !
I'm confused Is the Lcd.c driver compatible with the lcd I'm using or what.
Ttelmah



Joined: 11 Mar 2010
Posts: 19504

View user's profile Send private message

PostPosted: Wed Feb 22, 2012 12:51 pm     Reply with quote

Key is that the pin definitions in lcd.h, need to be changed to match your hardware. lcd,h, is generic (not quite as much as flex_lcd from the code library). It can drive almost any standard text lcd, from almost any PIC, but to allow this, you have to tell it what pins connect where.....

Best Wishes
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Feb 22, 2012 12:57 pm     Reply with quote

Did you build the circuit by yourself, or did you buy a board ?

If built it yourself, post the schematic on a free image hosting service
such as http://www.imageshack.us

If you bought the board, then post a link to the website for it.
raz



Joined: 22 Feb 2012
Posts: 22

View user's profile Send private message

PostPosted: Wed Feb 22, 2012 1:51 pm     Reply with quote

This is the lcd.c file
Code:

// As defined in the following structure the pin connection is as follows:
//     D0  enable
//     D1  rs
//     D2  rw
//     D4  D4
//     D5  D5
//     D6  D6
//     D7  D7
//
//   LCD pins D0-D3 are not used and PIC D3 is not used.[/b]

// Un-comment the following define to use port B
// #define use_portb_lcd TRUE


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;


#if defined use_portb_lcd
   //#locate lcd = getenv("sfr:PORTB")    // This puts the entire structure over the port
   #ifdef __pch__
    #locate lcd = 0xf81
   #else
    #locate lcd = 6
   #endif
   #define set_tris_lcd(x) set_tris_b(x)
#else
   //#locate lcd = getenv("sfr:PORTD")    // This puts the entire structure over the port
   #ifdef __pch__
    #locate lcd = 0xf83
   #else
    #locate lcd = 8
   #endif
   #define set_tris_lcd(x) set_tris_d(x)
#endif


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


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 lcd_read_byte() {
      BYTE low,high;
      set_tris_lcd(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_lcd(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_lcd(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;

   if(y!=1)
     address=lcd_line_two;
   else
     address=0;
   address+=x-1;
   lcd_send_byte(0,0x80|address);
}

void lcd_putc( char c) {
   switch (c) {
     case '\f'   : lcd_send_byte(0,1);
                   delay_ms(2);
                                           break;
     case '\n'   : lcd_gotoxy(1,2);        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);
    while ( bit_test(lcd_read_byte(),7) ); // wait until busy flag is low
    lcd.rs=1;
    value = lcd_read_byte();
    lcd.rs=0;
    return(value);
}


Shall I uncomment this line //#locate lcd = getenv("sfr:PORTD") // This puts the entire structure over the port ??????
raz



Joined: 22 Feb 2012
Posts: 22

View user's profile Send private message

PostPosted: Wed Feb 22, 2012 1:53 pm     Reply with quote

As i am using port D and i connected the lcd pins to port D as mentioned in the lcd.c file
I designed and connected the circuit myself on the bread board
temtronic



Joined: 01 Jul 2010
Posts: 9225
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Wed Feb 22, 2012 2:01 pm     Reply with quote

You should post your program,along with compiler version.
raz



Joined: 22 Feb 2012
Posts: 22

View user's profile Send private message

PostPosted: Wed Feb 22, 2012 2:13 pm     Reply with quote

Code:

#include <16F877A.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#include <lcd.c>

void main(void)
{

   set_tris_a(0);
   set_tris_b(0);
   set_tris_c(0);
   set_tris_d(0);
   set_tris_e(0);
   
   output_a(0);
   output_c(0);
   output_b(0);
   output_d(0);
   output_e(0);
   
   output_high(pin_b1);
   delay_ms(75);
   
   lcd_init();
   lcd_gotoxy(1,1);
   lcd_putc("\fReady......");
}

PCWH Compiler version 4.038
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Feb 22, 2012 2:13 pm     Reply with quote

Just use the flex lcd driver in the CCS Code Library forum. It's easier
to configure.
http://www.ccsinfo.com/forum/viewtopic.php?t=24661
raz



Joined: 22 Feb 2012
Posts: 22

View user's profile Send private message

PostPosted: Wed Feb 22, 2012 2:21 pm     Reply with quote

Thanks alot i will check it out
temtronic



Joined: 01 Jul 2010
Posts: 9225
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Wed Feb 22, 2012 6:33 pm     Reply with quote

Odds are you've got a wiring issue or perhaps a timing problem with your LCD module (not all LCDs are the same !), though I've used the Flex driver as PCM suggested for the past few years, Never had a problem with it.
Ttelmah



Joined: 11 Mar 2010
Posts: 19504

View user's profile Send private message

PostPosted: Thu Feb 23, 2012 2:51 am     Reply with quote

I've driven that exact display with the flex driver, with no problems.
It is one of the 'closer' copies of the original Hitachi chip, and has few issues.
Wiring.....
Also, has the original poster actually verified the processor is running at all (simple flash LED program, rather than trying to drive an LCD), and at the right speed (important for the LCD).

Best Wishes
Ttelmah



Joined: 11 Mar 2010
Posts: 19504

View user's profile Send private message

PostPosted: Thu Feb 23, 2012 5:58 am     Reply with quote

Have you read the comments at the top of any of the drivers?.....

lcd_init _must_ be called before you try talking to the display.
raz



Joined: 22 Feb 2012
Posts: 22

View user's profile Send private message

PostPosted: Thu Feb 23, 2012 2:00 pm     Reply with quote

I compiled the flex_lcd.c file but i got the following error Confused
***Error 128 "flex_lcd.c" line 28(1.42): A #DEVICE required before this line
int8 const LCD_INIT_STRING[4] =
raz



Joined: 22 Feb 2012
Posts: 22

View user's profile Send private message

PostPosted: Thu Feb 23, 2012 2:00 pm     Reply with quote

int8 const LCD_INIT_STRING[4] =
{
0x20 | (lcd_type << 2), // Func set: 4-bit, 2 lines, 5x8 dots
0xc, // Display on
1, // Clear display
6 // Increment cursor
};
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Feb 23, 2012 2:39 pm     Reply with quote

Is this your first CCS program ever ?

Look at the Flex lcd post in the link I gave you. You have two files.

1. You have the Flex lcd driver file. Save it as "flex_lcd.c" and put it in
your project directory. You can call the directory "lcd_test".
Edit the pin list at the top of the flex_lcd.c file so it matches the
connections on your board.

2. You also have the test program file. It's in the same post as the
flex_lcd.c file. It has the #include, #fuses, #use delay(), main(), etc.
You can save it as "lcd_test.c" or whatever you want to call it.
This file should be saved in the same directory as the Flex driver.

Now use the Project Wizard in MPLAB or the CCS IDE and make a project.
"Add" the lcd_test.c file to the project. DO NOT add "flex_lcd.c" to the
project. It's included in the project by the #include "flex_lcd.c" line in
the lcd_test.c file. You should NOT "add" it to the project file list.
The project file list (in the left pane in MPLAB) should only have
"lcd_test.c" in it.

Now compile the project. It should compile OK. Hopefully.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
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