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

Picdem 2 Plus LCD Driver

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



Joined: 02 Jun 2004
Posts: 16

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

Picdem 2 Plus LCD Driver
PostPosted: Wed Jun 02, 2004 5:10 am     Reply with quote

I am new to writing code but i have been involved in debugging other peoples code for some time. I need an lcd driver for the picdem 2 plus board. I have tryed some of the posted examples but i am not yet up to speed and i don't think i am editing the correctly etc. if anyone has a full lcd driver that works well please could they email it to me or provide any help to get me started. I have used the ccs lcd.c driver before and it worked on other boards but not the Picdem 2. all i need is to change the ports and i can get on with learning how to program pics.

Any help is great

Thanks

Mad
treitmey



Joined: 23 Jan 2004
Posts: 1094
Location: Appleton,WI USA

View user's profile Send private message Visit poster's website

PostPosted: Wed Jun 02, 2004 7:45 am     Reply with quote

here is what I came up with. I just made some mods to other dirvers.
drop it in the drivers subdirectory and include it in the *.h files
Code:

///////////////////////////////////////////////////////////////////////////
////                 PICDEM2_LCD.C                                 ////
////                 Driver for common PICDEM2 PLUS 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         ////
////                                                                   ////
///////////////////////////////////////////////////////////////////////////

#define use_PICDEM2_lcd TRUE


#if defined use_PICDEM2_lcd
   #define  lcd_en  PIN_A1   
   #define  lcd_rw  PIN_A2   
   #define  lcd_rs  PIN_A3   
   #define  lcd_type 2           // 0=5x7, 1=5x10, 2=2 lines
   #define  lcd_line_two 0x40    // LCD RAM address for the second line
   #define  d_cycle 1
#endif

void lcd_send_nibble( BYTE n ) {
   n=n&0x0f; //Strip off the top 4 bits.. This only sends bit 3:0
   output_d(n);
   delay_cycles(d_cycle);
   output_high(lcd_en);
   delay_us(20);
   output_low(lcd_en);
}
   
BYTE lcd_read_byte() {
   BYTE low,high;
   output_high(lcd_rw);
   delay_cycles(d_cycle);
   output_high(lcd_en);
   delay_cycles(d_cycle);
   high = input_d(); //using d0:d3 for 4 bit data bus
   output_low(lcd_en);
   delay_cycles(d_cycle);
   output_high(lcd_en);
   delay_us(1);
   low = input_d(); //using d0:d3 for 4 bit data bus
   output_low(lcd_en);
   return((high<<4) | low);
}
   
void lcd_send_byte( BYTE A0, BYTE n ) {    //A0:  0=instruction, 1=Data
   output_low(lcd_rs);
   while ( bit_test(lcd_read_byte(),7) ) ; // wait until busy flag is low
   if (A0==0){ output_low(lcd_rs);} //0=Instruction  and 1=Data
   if (A0==1){output_high(lcd_rs);} //0=Instruction  and 1=Data
   delay_cycles(d_cycle);
   output_low(lcd_rw);
   delay_cycles(d_cycle);
   output_low(lcd_en);
   lcd_send_nibble(n >> 4);
   lcd_send_nibble(n & 0xf);
}
   
void lcd_init() {
   BYTE const LCD_INIT_STRING[4] = {0x20 | (lcd_type << 2), 0xc, 1, 6};
   // These bytes need to be sent to the LCD for initialization.
   BYTE i;
   //fprintf(debug,"Init!!\n\r");
   output_low(lcd_rs);
   output_low(lcd_rw);
   output_low(lcd_en);
   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 Data;
   if(y!=1)
      Data=lcd_line_two;
   else
      Data=0;
   Data+=x-1;
   lcd_send_byte(0,0x80|Data);
}
   
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;
   }
}
   
char lcd_getc( BYTE x, BYTE y) {
   char value;
   lcd_gotoxy(x,y);
   while ( bit_test(lcd_read_byte(),7) ); // wait until busy flag is low
   output_high(lcd_rs);   
   value = lcd_read_byte();
   output_low(lcd_rs);   
   return(value);
}


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