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 support@ccsinfo.com

LCD interface on Port J

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



Joined: 28 Feb 2005
Posts: 24

View user's profile Send private message

LCD interface on Port J
PostPosted: Fri Mar 18, 2005 12:10 pm     Reply with quote

Hi all
I am interfacing LCD with PIC 18F8720 with CCS version 3.219 and I am using driver (4 bit interface) for 20x2 LCD given with the compiler. This driver uses pin A1,A2,A3 for control and lower nibble of port D for data. Now if I want to change the control pins to other port like J(J1,J2,J3) then what I need to change in order to do that. I changed the given code with address of port J and TRIS J but it didnt work. so can you tell me what else need to be changed.

Code:

////////////////////////////////////////////////////////////////////////////
////                             LCDD.C                                 ////
////                 Driver for common LCD modules                      ////
////                                                                    ////
////  lcd_init()   Must be called before any other function.            ////
////                                                                    ////
////  lcd_putc(c)  Will display c on the next position of the LCD.      ////
////                     The following have special meaning:            ////
////                      \f  Clear display                             ////
////                      \n  Go to start of second line                ////
////                      \b  Move back one position                    ////
////                                                                    ////
////  lcd_gotoxy(x,y) Set write position on LCD (upper left is 1,1)     ////
////                                                                    ////
////  lcd_getc(x,y)   Returns character at position x,y on LCD          ////
////                                                                    ////
////////////////////////////////////////////////////////////////////////////
////        (C) Copyright 1996,1997 Custom Computer Services            ////
//// This source code may only be used by licensed users of the CCS C   ////
//// compiler.  This source code may only be distributed to other       ////
//// licensed users of the CCS C compiler.  No other use, reproduction  ////
//// or distribution is permitted without written permission.           ////
//// Derivative programs created using this software in object code     ////
//// form are not restricted in any way.                                ////
////////////////////////////////////////////////////////////////////////////

// This structure is overlayed onto the data ports so that you may use
// whatever ports you desire
struct lcd_pin_map

  BOOLEAN dummy;      // PinA0 is not used
  BOOLEAN enable;     // PinA1
  BOOLEAN rw;         // PinA2
  BOOLEAN rs;         // PinA3
  int unusedA  : 4;   // The rest of portA
  int unusedB;        // portB is not used
  int unusedC;        // portC is not used
  int     data : 4;   // lower nibble of portD is used for data lines
  int unusedD  : 4;   // The rest of portD
} lcd;
#if defined(__PCH__)
  #locate lcd = 0xF88 <--- here I made change in address for port J
#else
  #locate lcd = 5
#endif

struct lcd_tris_map
{
  BOOLEAN dummy;      // PinA0 is not used
  int control  : 3;
  int unusedA  : 4;   // The rest of portA
  int unusedB;        // portB is not used
  int unusedC;        // portC is not used
  int data     : 4;   // lower nibble of portD is used for data lines
  int unusedD  : 4;   // The rest of portD
} lcdtris;

#if defined(__PCH__)
  #locate lcdtris = 0xF9A <-- here I changed address of tris port J
#else
  #locate lcdtris = 0x85
#endif

#define set_tris_lcd(x) lcdtris.data = (x); lcdtris.control = 0;



#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.

#define LCD_WRITE    0       // For write mode all pins are out
#define LCD_READ     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;                                                                                                             
}
Mark



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

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

PostPosted: Fri Mar 18, 2005 12:46 pm     Reply with quote

is the data on port J as well?
csshah



Joined: 28 Feb 2005
Posts: 24

View user's profile Send private message

PostPosted: Fri Mar 18, 2005 12:50 pm     Reply with quote

No there is no data on port J, I am using only lower nibble of D for data and port B for pushbuttons. all other ports are free. and I am using microchip 80 pin TQFP board

[url]
http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=84&useSecondary=true&device=en010058&ds=on&uguide=on&dnotes=on&errt=on&mig=on&tut=on&refm=on&broc=on[/url]
Mark



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

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

PostPosted: Fri Mar 18, 2005 8:03 pm     Reply with quote

Well then that's your problem!

Code:

// This structure is overlayed onto the data ports so that you may use
// whatever ports you desire
struct lcd_pin_map

  int unusedA;
  int unusedB;
  int unusedC;
  int     data : 4;   // lower nibble of portD is used for data lines
  int unusedD  : 4;   // The rest of portD
  int unusedE;       
  int unusedF;       
  int unusedG;       
  int unusedH;       
  BOOLEAN dummy;     
  BOOLEAN enable;     
  BOOLEAN rw;         
  BOOLEAN rs;       
  int unusedJ : 4;     
} lcd;
#if defined(__PCH__)
  #locate lcd = 0xF80
#else
  #locate lcd = 5
#endif

struct lcd_tris_map
{
  int unusedA;
  int unusedB;
  int unusedC;       
  int data     : 4;   // lower nibble of portD is used for data lines
  int unusedD  : 4;   // The rest of portD
  int unusedE;       
  int unusedF;       
  int unusedG;       
  int unusedH;       
  BOOLEAN dummy;     
  int control  : 3;
  int unusedJ : 4;     
} lcdtris;

#if defined(__PCH__)
  #locate lcdtris = 0xF92
#else
  #locate lcdtris = 0x85
#endif
csshah



Joined: 28 Feb 2005
Posts: 24

View user's profile Send private message

it works now!!!
PostPosted: Mon Mar 21, 2005 7:51 am     Reply with quote

Hey Mark!!!

Thanks a lot man!! You r GREAT!!!

I really appreciate ur help.

take care
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