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 Driver for Microchip Explorer16 using PMP module

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



Joined: 01 Oct 2003
Posts: 132
Location: Punta Gorda, Florida USA

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

LCD Driver for Microchip Explorer16 using PMP module
PostPosted: Tue Jul 01, 2008 8:13 am     Reply with quote

The following code will allow those of you who own a Microchip Explorer16 development board to easily adapt the PCD compiler to drive the Explorer16 lcd module using the PMP module of the PIC24 series in 8bit mode rather than nibble mode. Note, that this code will only work with devices that have the PMP port module only. The advantages of using the PMP module are very clear, as there is no need to bit-bang all the LCD control lines, like: EN, RD/WR..etc which makes the driver code far simpler and more streamlined.
Also for those of you that have the Explorer16 development boards; I will shortly have available a couple of new prototyping extension boards that will interface with the Explorer board, see my web at:
http://www.bartek.com/Bartek/PTB-X.html


CODE:
Code:
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////                             EXPLCD.C
////      Driver for PIC Explorer16 Board LCD module using PMP Module
////
////  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
////
////  Modified and improved version of LCD.C by C. Barberis  July,1 2008
////  Works only on Explorer16 Board with PIC24 pimm, does NOT work on devices without PMP.
////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


// Special Display Functions:
#define   Write_Inc_LtoR               lcd_send_byte(0,0x06)   // increments the cursor after writing data from L to R **(normal)
#define   Write_Inc_RtoL               lcd_send_byte(0,0x07)   // increments the cursor after writing data from R to L
#define   Write_Dec_LtoR            lcd_send_byte(0,0x05)   // decrements the cursor after writing data from R to L
#define    Write_Dec_RtoL            lcd_send_byte(0,0x04)   // decrements the cursor after writing data from R to L
#define   Display_Blank_No_Clr      lcd_send_byte(0,0x08)   //display off, without clearing
#define   Display_No_Cursor         lcd_send_byte(0,0x0C)   //display on, cursor off
#define   Display_Cursor_On         lcd_send_byte(0,0x0E)   //display on, cursor on
#define   Display_On_Blink             lcd_send_byte(0,0x0F)   //display on, blinking cursor
#define   MoveCursorRight             lcd_send_byte(0,0x10)   //Move cursor one char to the left, same as '\b'
#define   MoveCursorLeft                lcd_send_byte(0,0x14)   //Move cursor one char to the right
#define   MoveCursorHome             lcd_send_byte(0,0x02)   //Move cursor to top left char position (1,1)
#define ClearScreen                  lcd_send_byte(0,0x01)   //clears the screen an alternate to '\f'


//Define PMP Registers
#word PMCON = 0x600
#word PMMODE = 0x602
#word PMAEN = 0x60C
#word PMADDR = 0x604
#byte PMDIN1 = 0x608
#bit BUSY_BIT = PMMODE.15

#define  LCDCMD  0x0  // RS = 0
#define  LCDDATA  0x1 // RS =1
#define  PMDATA   PMDIN1
#define  busyLCD() lcd_read_byte(LCDCMD) & 0x80 //BUSY_BIT is used instead
#define lcd_line_two 0x40      // LCD RAM address for the second line

//////// Function Prototypes ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

unsigned int8 lcd_read_byte(int8 address);
void lcd_init();
void lcd_gotoxy( unsigned int8 x, unsigned int8 y);
void LCDCursor_gotoxy( unsigned int8 x, unsigned int8 y);
void lcd_send_byte( unsigned int8 address, unsigned int8 n );
void lcd_putc( char c);
char lcd_getc( unsigned int8 x, unsigned int8 y);

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

unsigned int8 lcd_read_byte(int8 address)
{
      unsigned int8 dummy,data;

      while(BUSY_BIT);
      PMADDR = address;
      dummy = PMDATA;
      while(BUSY_BIT);
     
      return(PMDATA);
 }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

void lcd_init()
{
    unsigned int8 i;
   
    PMCON = 0x83BF; //enable the PMP, long waits
    PMMODE = 0x3FF; // PMP set to master mode1
    PMAEN = 0x0001; // PMA0 enabled
    PMADDR = LCDCMD;
    PMDATA = 0x38;      // Function set: 8 bit interface, 2 lines, 5X7
    delay_us(50);
    PMDATA = 0xC;      // Function set: display ON ,cursor OFF, blink OFF
    delay_us(50);
    PMDATA = 0x6;      // Function set: increment cursor, no shift
    delay_us(50);
 }


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

void lcd_gotoxy( unsigned int8 x, unsigned int8 y)
{
   unsigned int8 address;

   if(y!=1)
     address=lcd_line_two;
   else
     address=0;
   address+=x-1;
   lcd_send_byte(0,0x80|address);
                                          }

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

void LCDCursor_gotoxy( unsigned int8 x, unsigned int8 y)
{
   unsigned int8 address;
   address+=x-1;

   lcd_send_byte(0,0x40|address);
}

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

void lcd_send_byte( unsigned int8 address, unsigned int8 n )
{     
      while(BUSY_BIT);
      PMADDR = address;
      delay_us(50);
      PMDATA = n;
      delay_us(50);
}

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

void lcd_putc( char c)
{
  switch (c) {
     case '\f'   : lcd_send_byte(0,1);
                   delay_ms(10);
                                           break;
     case '\n'   : lcd_gotoxy(1,2);        break;
     case '\b'   : lcd_send_byte(0,0x10);  break;
     default     : lcd_send_byte(1,c);     break;
                                                         }
                                                         }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

char lcd_getc( unsigned int8 x, unsigned int8 y)
{
   char value;

    lcd_gotoxy(x,y);
    value = lcd_read_byte(LCDDATA);
    return(value);
}


void lcd_setcursor_vb(short visible, short blink) // new routine to make cursor visible or blink
{
  lcd_send_byte(0, 0xC|(visible<<1)|blink);
}





////////////////////////////////////////////     End of File    /////////////////////////////////////////////////////////////////////////////////////////////


Last edited by cbarberis on Tue Jun 05, 2012 9:11 am; edited 1 time in total
1Razorbill



Joined: 26 Jun 2008
Posts: 2
Location: Phoenix

View user's profile Send private message

PostPosted: Mon Aug 04, 2008 11:04 am     Reply with quote

Can you please post an example of how to properly call this code from main?

Also, in the PDM Project Wizard, is it necessary to check the interrupt box labeled "PMP" to activate the Parallel Master Port, or your code will manage the PMP by itself?

Thanks!
cbarberis



Joined: 01 Oct 2003
Posts: 132
Location: Punta Gorda, Florida USA

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

PostPosted: Mon Aug 04, 2008 11:23 am     Reply with quote

You do NOT require the use of the PMP interrupt
From your main() you would call first; lcd_init() also make sure to include EXPLCD.C in your main source file

then, like any other lcd application you can call any of the following functions:

lcd_gotoxy( unsigned int8 x, unsigned int8 y);
LCDCursor_gotoxy( unsigned int8 x, unsigned int8 y);
lcd_send_byte( unsigned int8 address, unsigned int8 n );
lcd_putc( char c);
lcd_getc( unsigned int8 x, unsigned int8 y);
1Razorbill



Joined: 26 Jun 2008
Posts: 2
Location: Phoenix

View user's profile Send private message

PostPosted: Mon Aug 04, 2008 11:40 am     Reply with quote

Beautifiul.

Thanks!
samil



Joined: 21 Aug 2007
Posts: 1

View user's profile Send private message

PostPosted: Sat Apr 25, 2009 12:27 pm     Reply with quote

Thanks a lot. It works seamlessly.
krys



Joined: 15 Jul 2010
Posts: 1

View user's profile Send private message

int8.h nt found
PostPosted: Thu Jul 15, 2010 4:34 am     Reply with quote

Hi,

I tried your code here on MPLAB IDE for pic32 but it says int8.h is missing. Can u plz tell me whr I can get this header file.

Thanks
Krys
Cityboy



Joined: 09 Jul 2010
Posts: 3

View user's profile Send private message

Re: LCD Driver for Microchip Explorer16 using PMP module
PostPosted: Thu Aug 05, 2010 1:22 am     Reply with quote

Will it work with dspic33fj?
cbarberis



Joined: 01 Oct 2003
Posts: 132
Location: Punta Gorda, Florida USA

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

PostPosted: Tue Jun 05, 2012 9:18 am     Reply with quote

This driver was intended only to be used using the CCS compiler, it will NOT work on the PIC32 microchip compiler (unless major changes are made). Additionally CCS does not support PIC32 and there is plenty of LCD drivers using the pmp module from Microchip. There is also source code to support the Explorer 16 equipped with a PIC32 pim.
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