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

16f877a and lcd won't work

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








16f877a and lcd won't work
PostPosted: Sat Feb 10, 2007 7:59 am     Reply with quote

Hi

I am trying to get my 2x8 lcd to show a sign of life, but without success. I can't get more than the first line black. The lcd is hd44780 compatible, on the same hardware (same board) another program written in picbasic does work with the display. The file with the lcd routines looks as follows:

Code:

#define LCD_DB4   PIN_B4
#define LCD_DB5   PIN_B5
#define LCD_DB6   PIN_B6
#define LCD_DB7   PIN_B7
#define LCD_E     PIN_B2
#define LCD_RS    PIN_B1

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

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
 };

void lcd_send_nibble(int8 nibble) {
    // Note:  !! converts an integer expression
    // to a boolean (1 or 0).
    output_bit(LCD_DB4, !!(nibble & 1));
    output_bit(LCD_DB5, !!(nibble & 2));
    output_bit(LCD_DB6, !!(nibble & 4));   
    output_bit(LCD_DB7, !!(nibble & 8));   
    delay_cycles(1);
    output_high(LCD_E);
    delay_us(2);
    output_low(LCD_E);
}

void lcd_send_byte(int8 address, int8 n) {
   output_low(LCD_RS);
   delay_us(60);
   if(address)
      output_high(LCD_RS);
   else
      output_low(LCD_RS);
   delay_cycles(1);
   output_low(LCD_E);
   lcd_send_nibble(n >> 4);
   lcd_send_nibble(n & 0xf);
}

void lcd_init(void) {
   int8 i;
   output_low(LCD_RS);
   output_low(LCD_E);
   delay_ms(15);
   for(i=0 ;i < 3; i++) {
       lcd_send_nibble(0x03);
       delay_ms(5);
   }
   lcd_send_nibble(0x02);
   for(i=0; i < sizeof(LCD_INIT_STRING); i++) {
       lcd_send_byte(0, LCD_INIT_STRING[i]);
       delay_ms(5);
   }
}

void lcd_gotoxy(int8 x, int8 y) {
   int8 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;
     }
}


and then I have exactly the following code:

Code:

void main() {
   set_tris_b(0b00001001);
   set_tris_c(0b11010001);
   set_tris_d(0b01110000);
   lcd_init();
   lcd_gotoxy(1,1);
   lcd_putc("Hello World");
   ...


I do not post all the code because it's way too much. Can somebody find any error in this code, or should it basically work this way? What else could I look for? I have done a lot of research and also tried other versions of lcd drivers, also from this forum, but none worked.

Regards
Martin
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Feb 10, 2007 11:01 am     Reply with quote

1. I notice you're setting the TRIS. That LCD driver is intended to work
in standard i/o mode, not fast i/o mode. If you want to use Fast i/o mode,
then look at the following large thread. It's about using the CCS lcd.c
driver to run an 8x2 LCD. (Not the Flex driver, which you're trying to use).
http://www.ccsinfo.com/forum/viewtopic.php?t=22713

2. Do you have the contrast voltage set properly on the LCD ?
It should typically be somewhere in the range of 0 to .5 volts.
You have to set it with two resistors, or with a trimpot connected
between +5 and ground, with the center tap going to the LCD
contrast pin.

3. What's the manufacturer and part number of the LCD ?
Guest








PostPosted: Sun Feb 11, 2007 2:19 pm     Reply with quote

Thanks for your answer, pcm programmer.

1. I was not aware at all that the tris bits must or should not be set in standard i/o mode. I did not set #use fast_io and had no intention of using fast i/o. Therefore I removed the set_tris calls. Was, however, not the only reason for the non-working display obviously. I still looked through that thread, but didn't find much which I think is helpful in my case.

2. The contrast voltage (set with a 25k pot) should be ok, as contrast was ok when running the mentioned picbasic program, and I have not changed it since. Furthermore, I remember that the black rectangles I see in the first row of the lcd were not visible with the contrast not set correctly.

3. It's a DIPS082 sold by Electronic Assembly, the one with backlight. The data sheet can be found here:

www.lcd-module.de/deu/pdf/doma/dips082e.pdf

When I experimented with this (selfmade) experimental board first time, using picbasic then, I first used a powertip lcd where I didn't even get the rectangles in the first line, no way I could get it to work at all. Then I found the dips082 which is even better for my purpose as size matters a lot so I changed over and it worked first time. There were reasons I went away from proton picbasic, but the lcd driving worked. I just reloaded the old program and it still works, no hardware broken in the meantime.

I have r/w tied to ground for a 6-wire interface. This did work with picbasic. Does CCS have any dificulty with this?

I have written another lcd_init(), exactly as specified in the KS0066 data sheet, as follows:

Code:

void lcd_init() {
   delay_ms(30);
   lcd_send_byte(0,0x20);
   lcd_send_byte(0,0x20);
   lcd_send_byte(0,0xC0);
   delay_us(50);
   lcd_send_byte(0,0x00);
   lcd_send_byte(0,0xC0);
   delay_us(50);
   lcd_send_byte(0,0x00);
   lcd_send_byte(0,0x10);
   delay_ms(3);
   lcd_send_byte(0,0x00);
   lcd_send_byte(0,0x60);
}


Didn't help either.

I wonder what the heck is going wrong here. Do you have further ideas?

Regards
Martin
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Feb 11, 2007 5:25 pm     Reply with quote

I made a small test program, using the Flex LCD driver, and tested it
with three brands of 8x2 LCDs. It worked with all of them.

Here are the 8x2 LCDs:
1. CrystalFontz CFAH0802A-NYA-JP
2. Hantronix HDM08216H-3-S00S
3. Fema CM0823-SYR1 (Note: obsolete -- replaced by CM0826)

Here's the test program:
Code:

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

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

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

while(1);
}



Quote:

I have r/w tied to ground for a 6-wire interface. This did work with picbasic. Does CCS have any dificulty with this?

It's not a CCS issue, it's the Flex LCD driver. It has to be configured
to work with a 6-pin interface. This is done by commenting out the
following line in the Flex_LCD.c file:
Code:
// #define USE_RW_PIN   1

If that line is commented out, the Flex driver will be configured to work
with a 6-pin interface. I tested it this way, and it worked.

I suggest that you use the Flex LCD driver from the CCS code library.
Don't edit it, except to change the pin numbers to fit your board, and to
comment out the "#define USE_RW_PIN 1" statement.
Guest








PostPosted: Mon Feb 12, 2007 3:57 am     Reply with quote

Hi PCM Programmer

Yes this does work! I just changed the device to the "a" type and the pin settings in the flex lcd driver, and voila!

So I tried to figure out why it doesn't work in the main program. Finally I have a display now, but don't really know why. I commented out the following fuses

#FUSES NOPROTECT
#FUSES NODEBUG
#FUSES NOCPD
#FUSES NOWRT

and

#device ICD=TRUE

and changed

#FUSES NOBROWNOUT to #FUSES BROWNOUT

These had all been set by the project wizard.

Now I will further debug the code to make sure there's not only some text displayed but the one there should be...

Thanks a lot for this help for the moment, chances are good that I'll come back with further questions.

Regards
Martin
kender



Joined: 09 Aug 2004
Posts: 768
Location: Silicon Valley

View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger

PostPosted: Fri Mar 30, 2007 9:26 am     Reply with quote

PCM programmer wrote:

2. Do you have the contrast voltage set properly on the LCD ?
It should typically be somewhere in the range of 0 to .5 volts.
You have to set it with two resistors, or with a trimpot connected
between +5 and ground, with the center tap going to the LCD
contrast pin.


What happens to the LCD, when V_contrast = Vcc = +5V?

(I'm struggling with the same symptoms as the original poster.)

EDIT: Solved the problem http://www.ccsinfo.com/forum/viewtopic.php?t=30353 at the end of the thread.
Trent___
Guest







Powertip PC200-ARS-ASO-A
PostPosted: Wed Jun 20, 2007 8:17 am     Reply with quote

I am having the same trouble as the other posters.

Have anyone got the LCD mentioned in the subject to this post to work ?

I am using the FLEX_LCD driver, 4 bit mode and the display is correctly contrast.

The PIC is 18F2680

Is there any fine detail that I might have missed that anyone can offer ?
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