Character display

I got a really nice, small character display from Farnell, and want to use it in a new project I’m building (A general temperature controller that can be used in a Sous Vide or even a hot plate for soldering surface mount components). Farnell (Element14) is a good site to get components for DIY projects from. I’ve bought lots of my supplies for the 3D printers there also. Here’s a picture of the display.

I thought I had messed it up a bit while connecting the display, as I connected GND and VCC wrong. But it still works. Though for some reason I’m not able to write to the second line. I think there’s probably a bug in my code.

I’ve also bought a B57560G104F thermistor and some other components to make up the controller, and will report back (though with the baby there isn’t so much time for projects right now). This thermistor is the same I use for my 3D printers, and is used widely by the 3D printing community. It measures temperatures up to 300 Degrees C, so it’s possible to use for soldering applications.

Code and more info below the line.


It’s also on Inventortown.


// Inspired by http://www.ccsinfo.com/forum/viewtopic.php?p=146564
// FORDATA LCD drivers for FDCC0802C-NSWBBH-91LE

#include 

void lcd_send_nibble(unsigned int nibble );
void lcd_send_byte(int address, int n);
void lcd_init(void) ;
void delay_ms(unsigned int ms);

// Define ports
#define LCD_DB4      BIT0
#define LCD_DB5      BIT1
#define LCD_DB6      BIT2
#define LCD_DB7      BIT3
#define LCD_E        BIT5
#define LCD_RS       BIT6
#define LCD_RW       BIT4 

#define lcd_type    2        // 0=5x7, 1=5x10, 2=2 lines 
#define lcd_line_two 0x40 // LCD RAM address for the 2nd line 

#define P1_HIGH(bit) P1OUT |= bit
#define P1_LOW(bit)  P1OUT &= ~bit


int const LCD_INIT_STRING[4] = 
{ 
   0x28, //0x20 | (lcd_type << 2), // Func set: 4-bit, 2 lines, 5x8 dots 
   0x0F, //0x0c,                    // Display on 
   0x01,                      // Clear display 
   0x04 // 0x06                    // Increment cursor 
}; 

int main(void)
{

  WDTCTL = WDTPW + WDTHOLD; // disable watchdog

  P1DIR = 0xFF;
  P1OUT = 0x00;
  
  P1_LOW(LCD_RW);
  
  delay_ms(100);

  lcd_init(); 
  delay_ms(5); 
  
  //lcd_send_byte(0,0x0F); // Cursor on, cursor blink
  lcd_send_byte(0,0x0C); // Display on, cursor off, no blink
  lcd_send_byte(0,0x10); // Shift right
  //lcd_send_byte(0,0x28);
      	
  lcd_putc('\f');
 
  while (1) {  
    lcd_putc('\f');
    lcd_gotoxy(1,1);
    for (int i = 0; i < 8; i++) {
    	lcd_putc('0'+i);
    	}
    delay_ms(2000);
    lcd_gotoxy(1,1);
    for (int i = 0; i < 8; i++) {
    	lcd_putc('A'+i);
    	}
    delay_ms(2000);
    
  }

}

void lcd_send_nibble(unsigned int nibble ) 
{ 
   //P1OUT |= (nibble & 0x0F);   
   P1OUT = (nibble & 0x0F) | (P1OUT & 0xF0);  
   __delay_cycles(10); //1
   
   P1_HIGH(LCD_E);
   __delay_cycles(20); //2
   P1_LOW(LCD_E);
} 

void lcd_send_byte(int address, int n) 
{ 
   P1_LOW(LCD_RS); 
    
   if(address) {
      P1_HIGH(LCD_RS);
      } 
   else {
      P1_LOW(LCD_RS); 
      }
         
   __delay_cycles(20); 
    
   P1_LOW(LCD_E); 
    
   lcd_send_nibble(n >> 4); 
   lcd_send_nibble(n & 0xf); 
} 

void lcd_init(void) 
{ 
   int i; 

   P1_LOW(LCD_RS); 

   P1_LOW(LCD_E); 

   delay_ms(15); 

   for(i=0 ;i < 3; i++) 
   { 
      lcd_send_nibble(0x03); 
      delay_ms(10); 
   } 

   lcd_send_nibble(0x02); 

   for(i=0; i < sizeof(LCD_INIT_STRING); i++) 
   { 
       lcd_send_byte(0, LCD_INIT_STRING[i]); 
       delay_ms(5); 
   } 
} 

void delay_ms(unsigned int ms)
{
   for (int i = 0; i < ms; i++) {
   	__delay_cycles(1000);
   }
}



void lcd_gotoxy(int x, int y) 
{ 
   int 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; 
   } 
} 

One thought on “Character display”

Leave a Reply

Your email address will not be published. Required fields are marked *