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

Powertip LCD with 16F84A

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



Joined: 11 Feb 2005
Posts: 11

View user's profile Send private message Send e-mail

Powertip LCD with 16F84A
PostPosted: Mon Sep 19, 2005 11:10 am     Reply with quote

Hi,

This is driving me crazy! Aim: to use a 16 by 2 powertip LCD module for in write mode to display a character.

Have studied the data sheet for many hours and played with my code but just cant get this going.

When I power up I get one row of solid blue boxes. My initialisation routine is called and I get two rows of very light blue boxes. Does this mean its initialised - I thought i would see a cursor or something. At no point during initialisation does the lcd turn on/off so I think there is something wrong with the initialisation routine.

Can anyone see if there is anything wrong with my code?
I have made timings quite long (since there is no maximum time according to the datasheet) so that I can see what is happening on a scope.

Someone must have written something similar in ccs.

Grateful for any help!!


Code below should send the letter 'M'

Code:

/////////////////////////////////////////////////////////////////////////
////                    16*2 LCD Display Driver                      ////
////                                                                 ////
////                          Matt Holmes                            ////
/////////////////////////////////////////////////////////////////////////

#include <16f84a.h>
#include <stdio.h>
#include <stdlib.h>
#fuses XT,NOWDT,NOPUT,NOPROTECT

#use delay (clock=4000000)  // Clock Frequency 4 MHz

#define RS PIN_A0 // Define portA pins
#define RW PIN_A1
#define EN PIN_A2

#define DB0 PIN_B0 // Define portB pins
#define DB1 PIN_B1
#define DB2 PIN_B2
#define DB3 PIN_B3
#define DB4 PIN_B4
#define DB5 PIN_B5
#define DB6 PIN_B6
#define DB7 PIN_B7

/////////////////////////////////////////////////////////////////////////
// Subroutine: Enable data transmission
/////////////////////////////////////////////////////////////////////////

Enable()
   {
      output_high(EN);
      delay_ms(10);
      output_low(EN);
      //delay_us(1);
      delay_ms(10);

   }

/////////////////////////////////////////////////////////////////////////
// Subroutine: Write Character to LCD screen
/////////////////////////////////////////////////////////////////////////

Write_Data(int Character)
   {
      OUTPUT_B(Character);
      output_high(RS);  // Select data register for write
      output_low(RW);  // Write mode
      Enable();
   }

/////////////////////////////////////////////////////////////////////////
// Subroutine: Initialisation procedure for power up
/////////////////////////////////////////////////////////////////////////

Initialisation (int N_Lines, int Font)
   {
      delay_ms(20);

      output_low(RS); //Select instruction register for write
      output_low(RW);
      OUTPUT_B(0b00110000);
      Enable();

     Delay_ms(1000);

      OUTPUT_B(0b00110000);
      Enable();

      Delay_ms(1000);

      OUTPUT_B(0b00110000);
      Enable();

      if (N_Lines=2){
         output_high(DB3);
      }else{
         output_low(DB3);
      }
      if (Font=1){
         output_high(DB2);
      }else{
         output_low(DB2);
        }
      Enable();
Delay_ms(3000);
      OUTPUT_B(0b00001000); //Display off
      Enable();
Delay_ms(3000);
      OUTPUT_B(0b00000001); //Display on
      Enable();
Delay_ms(3000);
      OUTPUT_B(0b00000110);
      Enable();
  }

/////////////////////////////////////////////////////////////////////////

void main()

{

// Define Port i/o settings

SET_TRIS_A(0b00000000); // Set PortA as output
SET_TRIS_B(0b00000000); // Set PortB as output

OUTPUT_B(0b00000000);
OUTPUT_A(0b00000000);
Delay_ms(500);

Initialisation(1,1);  // (int N_Lines, int Font) N_Lines = Number of lines (1 or 2), Font = Font style (0=5*7 or 1=5*10)
Delay_ms(1000);

Write_Data(77);
while (TRUE) { // Continuous loop through
             // Writes letter 'M'
             Delay_ms(20);
             }
return;
}

PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Sep 20, 2005 6:53 pm     Reply with quote

My suggestion is don't try to re-invent the wheel. Use the CCS driver
and it will work. Also, for 16x2 LCDs, no one uses the 8-bit data bus.
The upper 4-bits are used. This saves valuable pins on your PIC for
other uses. Here's a page that has a schematic that shows how
to connect the LCD to your PIC, when using the CCS driver on Port B.
http://academic1.bellevue.edu/robots/16f84lcd.html

Remember that the CCS driver, LCD.C, must be configured to use
Port B. Do this by placing the #define statement shown below
in the line above the #include statement for the LCD driver file.
Example:

#define use_portb_lcd TRUE
#include <lcd.c>
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Tue Sep 20, 2005 10:07 pm     Reply with quote

PCM programmer wrote:
no one uses the 8-bit data bus.
Somebody does Razz
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Sep 20, 2005 11:11 pm     Reply with quote

Yes, I knew I took a risk in saying that. Mr. Green
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Wed Sep 21, 2005 6:07 am     Reply with quote

I probably will not use all 8 in future designs unless I have an 8 bit data bus going to other IC's Smile
Guest








PostPosted: Wed Sep 21, 2005 11:52 am     Reply with quote

Ok thanks for your help will try it out. Still would like to know why my code doesnt work though!!!
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