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

PIC18F452

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



Joined: 11 Aug 2004
Posts: 3

View user's profile Send private message

PIC18F452
PostPosted: Wed Aug 11, 2004 2:32 pm     Reply with quote

I have researched this topic to no avail.

As you will probably discover I do not have much experiance with embedded programming and any help is much appreciated

I am having trouble initializing an LCD it is a
CrystalFontz - cfah1202a-yyb-jp it uses the Hitachi HD44780u Controller.

I am programming a pic18f452 and using the 4-bit 2-Wire LCD Interface found here http://www.rentron.com/Myke1.htm
PIN_C0 for Data and PIN_C1 for the clock

I beleive I am having trouble with the timing and a general understanding of "what" to send "when"

I have and read the datasheets for the pic18f452, Hitachi Controller, the LCD display and even the Motorola D-flip flop chip

DISCLAIMER: I did not write this

CCS Compiler Ver 3.42
Target voltage = 5V
Target oscillator speed = CPU_CLK 19660800

Code:

#define LCD_DATA PIN_C0
#define LCD_CLK  PIN_C1

#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.
/*
** LCD_Write_Nybble: Write the lower 4 bits of Argument Nybble to the LCD (via a 164 shift register 2 wire interface)
*/

static void LCD_Write_Nybble(BYTE Nybble, BYTE RS)
{
  unsigned char i;

  output_low(LCD_DATA);          //  Clear the '164

  for (i = 0; i < 6; i++)        //  Repeat for six bits
  {
    output_high(LCD_CLK);
    output_low(LCD_CLK);         //  Write the "0"s into the '164
  }

  output_high(LCD_DATA);         //  Output the "AND" Value
  output_high(LCD_CLK);
  output_low(LCD_CLK);

  output_bit(LCD_DATA,RS);       //  Output the RS Bit Value
  output_high(LCD_CLK);
  output_low(LCD_CLK);

  for (i = 0; i < 4; i++)        // Output the Nybble
  {
    if ((Nybble & 0x08) != 0)
      output_high(LCD_DATA);     // Output the High Order Bit
    else
      output_low(LCD_DATA);

    output_high(LCD_CLK);
    output_low(LCD_CLK);         // Strobe the LCD_CLK
    Nybble = Nybble << 1;        // Shift up Nybble for Next Byte
  }

  output_high(LCD_DATA);
  output_low(LCD_DATA);          // Toggle the "E" bit of the LCD via gating circuitry

} // End LCDNybble

void lcd_send_byte( BYTE address, BYTE n ) {

      LCD_Write_Nybble(n >> 4, address);
      delay_cycles(64);
      LCD_Write_Nybble(n & 0xf, address);
      delay_cycles(64);
}

void lcd_init() {

    BYTE i;

    delay_ms(500);               // 15

    for(i=1;i<=3;++i) {
         LCD_Write_Nybble(0x03, 0);
       delay_ms(20);             // 5
    }

      LCD_Write_Nybble(0x02, 0);

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


void lcdPutString(char *msg)
{
    int i;
    for(i=0; msg[i] != '\0'; i++)
    {
        lcd_putc(msg[i]);
    }
}


The main calls the lcd_init() nothing changes and the black row on top remains.

My

Cheers,

Tool
rnielsen



Joined: 23 Sep 2003
Posts: 852
Location: Utah

View user's profile Send private message

PostPosted: Wed Aug 11, 2004 4:24 pm     Reply with quote

I just looked at the spec sheet for the HD44780u controller and it looks like it uses a standard 4 or 8 bit interface, plus the RS, WR and E lines. Trying to talk to it via a 2 line clocked signal will not work. I suggest looking at the spec sheet a bit closer to make sure you have the right kind of bug that you think you have.

Ronald
Ttelmah
Guest







PostPosted: Thu Aug 12, 2004 2:28 am     Reply with quote

rnielsen wrote:
I just looked at the spec sheet for the HD44780u controller and it looks like it uses a standard 4 or 8 bit interface, plus the RS, WR and E lines. Trying to talk to it via a 2 line clocked signal will not work. I suggest looking at the spec sheet a bit closer to make sure you have the right kind of bug that you think you have.

Ronald

He is not trying to talk directly to the interface with a two wire bus. If you look at the article he gives the link for, it uses a 18F84, to control a normal parallel LCD, and translates from a 2wire bus, which he is trying to drive.
The problem though is that there are so many places where this could fail, and without some test equipment, little advice we can give.
The way to proceed, will depend on what equipment is available, but ideally, he needs to be looking at whether the clock and data signals are being generated, and getting to the unit. Personally, I'd probably suspect that the translator unit is not working, and would look at writing some form of 'test code' to put into this, to verify that all the lines are operable.
The code as ritten, looks 'possible', for the interface described, but tracking down where the problem lies, is going to involve simplifying, to smaller component parts.

Best Wishes
Guest








PostPosted: Thu Aug 12, 2004 6:12 am     Reply with quote

Thanks for the replies

I know the clock PIN_C1 and data PIN_C0 are fine, I have tested them with a scope and can change them high to low as I please.

I will write a little tester and try it step by step, as you suggest.
I have a funny feeling it is just a timing issue, sending the wrong nibble at the wrong time.

I'll keep ya posted, because I have noticed not many people have deployed this interface, save a lot of pins... Very Happy
Tool



Joined: 11 Aug 2004
Posts: 3

View user's profile Send private message

PostPosted: Thu Aug 12, 2004 6:30 am     Reply with quote

Sorry I am at work and forgot to log in before posting... Embarassed
Tool



Joined: 11 Aug 2004
Posts: 3

View user's profile Send private message

PostPosted: Thu Aug 12, 2004 12:55 pm     Reply with quote

Just to close this thread, I examined the back of the lcd and the data lines are on pins 12,13,14,15.........whoops

they should be on pins 11,12,13,14...15 is for the backlight

this is what happens when you are thrown into a project and assured all hardware is wired correctly Evil or Very Mad
rnielsen



Joined: 23 Sep 2003
Posts: 852
Location: Utah

View user's profile Send private message

PostPosted: Thu Aug 12, 2004 1:28 pm     Reply with quote

Now you know why Engineer's foreheads are always flat.

*Bangs head against wall* Rolling Eyes
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