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

16x2 LCD Driver For Mikroelektronika EasyPic 4 Dev Board

 
Post new topic   Reply to topic    CCS Forum Index -> Code Library
View previous topic :: View next topic  
Author Message
hansolo



Joined: 06 Oct 2006
Posts: 20

View user's profile Send private message

16x2 LCD Driver For Mikroelektronika EasyPic 4 Dev Board
PostPosted: Sun Oct 29, 2006 6:49 pm     Reply with quote

The driver was modified because in the Mikroelektronika EasyPic4 Board the LCD R/W is permanently wired to Gnd.

The original LCD.C driver uses the R/W pin to communicate.

Hope this is useful :

Code:
///////////////////////////////////////////////////////////////////////////
////                             LCD_mE_EP4.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)    ////
////                                                                   ////
////                                                                   ////
///////////////////////////////////////////////////////////////////////////
////        (C) Copyright 1996,2003 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.                               ////
///////////////////////////////////////////////////////////////////////////

// As defined in the following structure the pin connection is as follows:
//     Note: rw permanently connected to gnd
//     D2  rs
//     D3  en
//     D4  D4
//     D5  D5
//     D6  D6
//     D7  D7
//
//   LCD pins D0-D3 are not used and PIC D3 is not used.

// Un-comment the following define to use port B
// #define use_portb_lcd TRUE


struct lcd_pin_map {                 // This structure is overlayed
           BOOLEAN unused;           // on to an I/O port to gain
           BOOLEAN rw;               // access to the LCD pins.
           BOOLEAN rs;               // The bits are allocated from
           BOOLEAN enable;           // low order up.  RS will
           int     data : 4;         // be pin D2.
        } lcd;


#if defined(__PCH__)
#if defined use_portb_lcd
   #byte lcd = 0xF81                   // This puts the entire structure
#else
   #byte lcd = 0xF83                   // This puts the entire structure
#endif
#else
#if defined use_portb_lcd
   #byte lcd = 6                  // on to port B (at address 6)
#else
   #byte lcd = 8                 // on to port D (at address 8)
#endif
#endif

#if defined use_portb_lcd
   #define set_tris_lcd(x) set_tris_b(x)
#else
   #define set_tris_lcd(x) set_tris_d(x)
#endif


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

struct lcd_pin_map const LCD_WRITE = {0,0,0,0,0}; // For write mode all pins are out
struct lcd_pin_map const LCD_READ = {0,0,0,0,15}; // For read mode data pins are in


void lcd_send_nibble( BYTE n ) {
      lcd.data = n;
      delay_cycles(1);
      lcd.enable = 1;
      delay_us(2);
      lcd.enable = 0;
}


void lcd_send_byte( BYTE address, BYTE n ) {

      lcd.rs = 0;
      delay_ms(1);
      lcd.rs = address;
      delay_cycles(1);
      delay_cycles(1);
      lcd.enable = 0;
      lcd_send_nibble(n >> 4);
      lcd_send_nibble(n & 0xf);
}


void lcd_init() {
    BYTE i;
    set_tris_lcd(LCD_WRITE);
    lcd.rs = 0;
    lcd.enable = 0;
    delay_ms(15);
    for(i=1;i<=3;++i) {
       lcd_send_nibble(3);
       delay_ms(5);
    }
    lcd_send_nibble(2);
    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;
   }
}
JSS



Joined: 27 Dec 2006
Posts: 1

View user's profile Send private message

Thanks for the help
PostPosted: Wed Dec 27, 2006 9:29 pm     Reply with quote

I have an mE EP3 board, I was on the same path in changing the LCD.c of CCS, but I was missing somthing??? I seen your code, compared notes, uncommitted port-b for my board and volia. This to me also confirmed that a KS0066 display driver is the same as an HD44780. Once again THANKS

I have the GLCD working with CCS and using the Graphic LCD bitmap generator from mikroC (free 2k demo limited version) I can display my own bitmaps. I will be posting it soon. I did have one problem to work around though, making an array of 1024 is not able to be done in CCS as in mikroC, the bitmap had to be divided in 4 arrays of 256.
const INT maska_bmp1[256]
const INT maska_bmp2[256]
const INT maska_bmp3[256]
const INT maska_bmp4[256]
Or is there something I was doing wrong with not being able to create a 1024 array?? Rolling Eyes
Storic



Joined: 03 Dec 2005
Posts: 182
Location: Australia SA

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

PostPosted: Sun Dec 31, 2006 2:22 am     Reply with quote

a couple of minor changes that work for me.
Code:
struct lcd_pin_map {           // This structure is overlayed
           BOOLEAN unused : 2; // 2 x unused pins for LCD control
           BOOLEAN rs;         // RS LCD pin control. (RW pin grounded)
           BOOLEAN enable;     // enable LCD pin control.
           int     data : 4;   // High nibble of port is used for data lines
        } lcd;


and then
Code:
struct lcd_pin_map const LCD_WRITE = {0,0,0,0}; // For write mode all pins are out
struct lcd_pin_map const LCD_READ = {0,0,0,15}; // For read mode data pins are in
.

code works OK, it was just I removed reference to RW that not being used

it appears that you dont need as well
Code:
//struct lcd_pin_map const LCD_READ = {0,0,0,15}; // For read mode data pins are in

As the compiler said, variable never used : LCD_READ
_________________
What has been learnt if you make the same mistake? Wink
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> Code Library 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