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

LCD Library troubles

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



Joined: 12 Apr 2011
Posts: 4

View user's profile Send private message

LCD Library troubles
PostPosted: Tue Apr 12, 2011 11:11 am     Reply with quote

Hello,

I am trying to get a 8x2 LCD screen working with the LCD library provided by LCD.c and run into some troubles, I don't know if the issue is in hardware or in software but the hardware is fairly basic therefore I'm assuming its software.

So the LCD module I use is a cheap (£5) Fordata Electronic FDCC0802C-FLYYBW-51LK bought from Farnell and I try to use it in a 4bit mode.

The code I use is:

Code:

#include <18F25K80.h>
#fuses INTRC_IO,NOWDT,NOPROTECT,NOPUT
#use delay(clock=8MHZ)

#define LCD_ENABLE_PIN  PIN_C0
#define LCD_RS_PIN      PIN_C2
#define LCD_RW_PIN      PIN_C1

#define LCD_DATA4       PIN_A0
#define LCD_DATA5       PIN_A1
#define LCD_DATA6       PIN_A2
#define LCD_DATA7       PIN_A3

#include <LCD.c>

void mcu_init()
{
   setup_oscillator(OSC_8MHZ);
   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_OFF);
   setup_comparator(NC_NC_NC_NC);

   #use fast_io(A)
   set_tris_a(0);
   output_a(0);
}

void main()
{
   mcu_init();   

   output_high(PIN_A6);

   lcd_init();

   delay_ms(5);
   lcd_putc('s');

   while (1)
      ;
}


The DB4-DB7 of the LCD screen are assigned to RA0-RA3 the control lines on RC0-RC2. RA6 is assigned to a LED just to signal that the micro is up and running.

One of the weird thing is it looks like the R/W pin is driven high by the screen which as far as I understand it not should be the case. I tried to ground it (the RW pin) but still does not work.

Any Help would be much appreciated.

Regards,

Simon
temtronic



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

View user's profile Send private message

PostPosted: Tue Apr 12, 2011 11:45 am     Reply with quote

You could try the 8 bit mode first to see if it functions OK. There may be a setup problem(timing, command ,?) with your display that is not compatible with the 4 bit mode driver.

I run the flexLCD driver , write only mode, on several LCDs fine...
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Apr 12, 2011 11:46 am     Reply with quote

Make sure you understand the pin numbering method on the LCD.
Viewed from the LCD side of the Fordata board, the top row is
2, 4, 6, 8, 10, 12, 14, 16
and the bottom row is
1, 3, 5, 7, 9, 11, 13, 15.

Also, you have #use fast_io in your code. I don't see that in any CCS
examples that use their lcd.c driver file. I also don't see it in the driver
file. I wouldn't invoke fast_io mode unless you know it can be used.

LCD data sheet:
http://www.farnell.com/datasheets/653672.pdf
---------
Temtronic,
The CCS lcd.c file doesn't support 8-bit mode. It supports "all pins on
one port mode", as an additional mode, but it's still 4-bit data.
Adraen



Joined: 12 Apr 2011
Posts: 4

View user's profile Send private message

PostPosted: Tue Apr 12, 2011 12:34 pm     Reply with quote

Hi again,

Cheers for the answers,

Well I read the datasheet quite carefully already and the 4 bit mode is suppose to be supported by the screen might try the 8bit mode anyway if I run out of ideas.

About the Pins yes I noticed that the pinning is like you said which is a bit weird ... I will try the fast_io and maybe flexLCD and let you know the result.

cheers guys.
Ttelmah



Joined: 11 Mar 2010
Posts: 19520

View user's profile Send private message

PostPosted: Tue Apr 12, 2011 2:36 pm     Reply with quote

No.
The point is to _not_ use fast_io. The standard drivers require standard_io mode. You have a fast_io line in your code.

Best Wishes
Adraen



Joined: 12 Apr 2011
Posts: 4

View user's profile Send private message

PostPosted: Tue Apr 12, 2011 3:59 pm     Reply with quote

So,

I reread the flexible LCD post and like Ttelmah and PCM said fast_io should not be used so I disabled it.

So the problem is still the same it does not work unfortunately and the init stay stuck in "while(bit_test(lcd_read_byte(),7)) ;" I tried to ground the R/W and does not work either (I commented the LCD_RW to use delays instead).

To be sure I used a different LCD screen same model also new.

I rewired everything like this:



And the current code is
Code:

#include <18F25K80.h>
#fuses INTRC_IO,NOWDT,NOPROTECT,NOPUT
#use delay(clock=8MHZ)

#define LCD_DB4      PIN_A0
#define LCD_DB5      PIN_A1
#define LCD_DB6      PIN_A2
#define LCD_DB7      PIN_A3
#define LCD_E      PIN_C0
#define LCD_RS      PIN_C2
#define LCD_RW      PIN_A1
#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

#define BUZZER      PIN_A7
#define LED         PIN_A6

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

#ifdef USE_LCD_RW
int8 lcd_read_nibble(void)
{
   int8 retval;
   // Create bit variables so that we can easily set
   // individual bits in the retval variable.
   #bit retval_0 = retval.0
   #bit retval_1 = retval.1
   #bit retval_2 = retval.2
   #bit retval_3 = retval.3
   
   retval = 0;
      
   output_high(LCD_E);
   delay_cycles(1);
   
   retval_0 = input(LCD_DB4);
   retval_1 = input(LCD_DB5);
   retval_2 = input(LCD_DB6);
   retval_3 = input(LCD_DB7);
    
   output_low(LCD_E);
      
   return(retval);   
}   
#endif

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

#ifdef USE_LCD_RW
int8 lcd_read_byte(void)
{
   int8 low;
   int8 high;
   
   output_high(LCD_RW);
   delay_cycles(1);
   
   high = lcd_read_nibble();
   
   low = lcd_read_nibble();
   
   return( (high<<4) | low);
}
#endif

void lcd_send_byte(int8 address, int8 n)
{
   output_low(LCD_RS);
   
   #ifdef USE_LCD_RW
   while(bit_test(lcd_read_byte(),7)) ;
   #else
   delay_us(60); 
   #endif
   
   if(address)
      output_high(LCD_RS);
   else
      output_low(LCD_RS);
        
    delay_cycles(1);
   
   #ifdef USE_LCD_RW
   output_low(LCD_RW);
   delay_cycles(1);
   #endif
   
   output_low(LCD_E);
   
   lcd_send_nibble(n >> 4);
   lcd_send_nibble(n & 0xf);
}

void lcd_init(void)
{
   int8 i;

   output_low(LCD_RS);

   #ifdef USE_LCD_RW
   output_low(LCD_RW);
   #endif

   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]);
      
       // If the R/W signal is not used, then
       // the busy bit can't be polled.  One of
       // the init commands takes longer than
       // the hard-coded delay of 60 us, so in
       // that case, lets just do a 5 ms delay
       // after all four of them.
       #ifndef USE_LCD_RW
       delay_ms(5);
       #endif
   }
}

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

/*
#INT_TIMER0
void timer0_isr()
{
   output_toggle(BUZZER);
}
*/

// Frequency of interrupt (clock/(4*divisor)) / (256-reload)
void mcu_init()
{
   setup_oscillator(OSC_8MHZ);
   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_OFF);
   setup_comparator(NC_NC_NC_NC);

/*
   // Setup the TIMER0 Interrupt
   set_timer0(0);
   setup_timer_0(RTCC_INTERNAL | RTCC_8_BIT | RTCC_DIV_4);
   enable_interrupts(INT_TIMER0);
   enable_interrupts(GLOBAL);
*/

   //#use fast_io(A)
   set_tris_a(0);
   set_tris_c(0);
   //output_a(0);
}

void main()
{
   mcu_init();   

   //output_high(LED);

   lcd_init();
   delay_ms(5);
   lcd_putc('s');

   while (1)
   {
/*
      enable_interrupts(INT_TIMER0);
      delay_ms(1000);
      disable_interrupts(INT_TIMER0);
      delay_ms(1000);
*/
   }
}


Thank you again for the time you spent on this.

Simon.
temtronic



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

View user's profile Send private message

PostPosted: Tue Apr 12, 2011 5:36 pm     Reply with quote

re: 8 bit mode test vs. 4 bit mode.

Didn't mean to say use the CCS drivers for 8 bit mode. All I do is wire up the 8 data lines to a port, then send the data byte 55x, ( 'U'), then 'pulse ' the E line as required in the LCD data sheet. I have a simple 'hello world 8bit' program. It's small bit easy to check any LCD,setup contrast pin, write only mode,etc. It should take less than 15 minutes to wireup and test any character LCD using a simple preprogrammed PIC like mine.

Some LCDs, while '4 bit mode' capable may require different setup times than what's in the LCD driver. Nothing worse than wasting hours trying to debug the LCD only find the driver needs to be 'tweaked', contrast pin set wrong, etc.

Sounds like this LCD module has an 'odd' pinout and unless wires are colour coded, cross wiring could cause no end of wasted time.
Maybe a weird contrast requirement ??

misDEFINING PICpins is fun as well......

NEVER use fast_io() unless you're an expert, even then it'll get you one day!!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Apr 12, 2011 7:34 pm     Reply with quote

Quote:

So the problem is still the same it does not work unfortunately and the
init stay stuck in "while(bit_test(lcd_read_byte(),7)) ;" I tried to ground
the R/W and does not work either (I commented the LCD_RW to use
delays instead).

What's your compiler version? Your version may be buggy with the
18F25K80. The version is given at the top of the .LST file, which will
be in your project directory after a successful compilation.
This CCS page shows what a version number looks like:
http://www.ccsinfo.com/devices.php?page=versioninfo
Adraen



Joined: 12 Apr 2011
Posts: 4

View user's profile Send private message

PostPosted: Sat Apr 16, 2011 8:54 am     Reply with quote

Hello,

So, it is working the screen now display text, the issue was that my potentiometer value for Vo was wrong therefore I reread the datasheet carefully this time.

I don't know if it is like this for every LCD screen but mines have the first line filled with block so you can see something is here when the voltage is correct.

However I have another issue that I really don't understand is that if I connect the data lines to PORTA it doesn't work but if i connect them to PORTC it works fine :/.

Anyway thanks for your help

Edit: looks like its more the control lines on PORTC than data on PORTA that causes the problem
temtronic



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

View user's profile Send private message

PostPosted: Sat Apr 16, 2011 9:42 am     Reply with quote

You have to disable any onchip peripherals to use pins as general purpose digital I/O pins.
Look carefully on the datasheet for you PIC and see what the 'default' use is for the pins you want to use.
Some PICs have defaults of ADC, SPI,etc. that you must disable.
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