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 Hitachi HD44780 16x2 Driver

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



Joined: 08 Mar 2012
Posts: 38
Location: Canada

View user's profile Send private message

LCD Hitachi HD44780 16x2 Driver
PostPosted: Wed Mar 28, 2012 3:18 pm     Reply with quote

Hey everyone,
I have made a header file that I am using to display various information on my LCD Hitachi HD44780 16x2 screen.
I have gotten it completely initialized and I have successfully sent data to it.

My problem is when to much data needs to be displayed some of the data does not get displayed since it is only a 16x2 screen.

I would like to figure out how to get the data displayed to automatically step to the second line before going "out of bounds" and either shift the screen down as data is being displayed or loop between the two lines.

Here is the what I have gotten so far:
Code:


#byte TRISC = 0x87
#byte TRISB = 0x86


#bit LCD_RS = 0x6.3 // Register select PORT B
#bit LCD_EN = 0x6.2 // Enable PORT B

#bit LCD_D4 = 0x6.4 // Data bits PORT B
#bit LCD_D5 = 0x6.5 // Data bits PORT B
#bit LCD_D6 = 0x6.6 // Data bits PORT B
#bit LCD_D7 = 0x6.7 // Data bits PORT B

int16 data_val;
int16 num_val;
int16 ones;
int16 tens;
int16 hundreds;

int line_mode;

void pulse(void)
         {
         LCD_EN = 0;
         delay_ms(10);
         LCD_EN = 1;
         }

void set_lcd_pins(int data_val)
         {
         
         if( data_val & 0x80) LCD_D7=1; else LCD_D7=0;
         if( data_val & 0x40) LCD_D6=1; else LCD_D6=0;
         if( data_val & 0x20) LCD_D5=1; else LCD_D5=0;
         if( data_val & 0x10) LCD_D4=1; else LCD_D4=0;
         pulse();
         }

void send_nibbles(int data_val)

         {
         set_lcd_pins(data_val&0xf0);
         delay_ms(10);
         set_lcd_pins((data_val&0x0f)<<4);
         delay_ms(10);
         }
void shift_display_left(void)
{
   LCD_RS = 0;
   send_nibbles(0x18);//Shifts display left
}
void Entry_Mode(void)
{
   LCD_RS = 0;// COMAND MODE
   send_nibbles(0x07);//display moves with cursor & increments(L to R)
}
void Clear_LCD(void)

      {
      LCD_RS = 0;// COMAND MODE
      send_nibbles(0x01);// Clear LCD
      }
     
void LCD_On_Blink_Cursor(void)
      {
      LCD_RS = 0;// COMAND MODE
      send_nibbles(0x0f);// Turn LCD On and Set Blinking Cursor
      }
     
void set_line_mode(int line_mode)
      {
     
      LCD_RS = 0; // COMMAND MODE
     
      If (line_mode == 2)
      {
         send_nibbles(0x28); // Function set to 2 line mode
      }
      If (line_mode == 0)
      {
         send_nibbles(0x20); // Function set to 1 line mode
      }
      }

void set_disp_add_first_line(void)
      {
      LCD_RS = 0; // COMAND MODE
      send_nibbles(0x80); // Set Cursor to First Square
     }
void set_disp_add_second_line(void)
      {
      LCD_RS = 0; // COMAND MODe
      send_nibbles(0xC0);
      }
void LCD_Left_Shifting(void)
      {
      LCD_RS = 0;//Comand mode
      send_nibbles(0x18);
      }
void LCD_Right_Shifting(void)
      {
      LCD_RS = 0;//Comand mode
      send_nibbles(0x1C);
      }
void LCD_Cursor_Home(void)
      {
      LCD_RS = 0;//Comand mode
      send_nibbles(0x02);
      }
void LCD_init(void)
      {
     
      TRISB = 0x00;
      LCD_EN = 1;
      LCD_RS = 0;// COMAND MODE

      set_lcd_pins(0x30);
      set_lcd_pins(0x30);
      set_lcd_pins(0x30);
      set_lcd_pins(0x20);
     
      Clear_LCD();
      LCD_On_Blink_Cursor();
      set_line_mode(2); // SET THE LINE MODE
     
      }
     
 void text_string(char string1)
      {
      LCD_RS = 1;
      send_nibbles(string1);
      }
 void binary2dec(long value)
   {
   num_val=value;
   ones=num_val%10;
   num_val=num_val/10;
   tens=num_val%10;
   hundreds=num_val/10;
   
   send_nibbles(hundreds+0x30);
   send_nibbles(tens+0x30);
   send_nibbles(ones+0x30);
   }


Thanks
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

LCD dislay scrolling
PostPosted: Wed Mar 28, 2012 4:40 pm     Reply with quote

I believe that the display you're using is an 80 character display, but you can only see a window of 32.

When you "go out of bounds" as you call it you're writing to RAM locations outside the visible window.

You have loads of options including:-

(1) Write 16 chars to line 1, jump to line 2, write 16 chars, clear line 1, copy line 2 to line 1, clear line 2, continue writing to line 2.
(2) Start as (1) but shift different blocks of RAM into visible area. (Saves some copying)
(3) Start as (1), use the automatic write and shift feature.
(4) .................

Which ever way you decide to go, I believe you need to keep track of the number of characters sent to the display.

Mike
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