Lcd I2c

LCD MC21605WD-BNMLW-V2 LCD is I2C device.

Its datasheet is here https://www.farnell.com/datasheets/2825693.pdf

It is 5V device, which has address 0x78.
I can check the address here
http://remotesmart.wikidot.com/i2c-converter
It was right.
CBS line must be Vss ie. gnd. So the device is enabled.

Now must start the device give to it
void Initial_RW1063()
{
delay_ms(100); //a small delay
writeI2C(0x00,0x38); //SET 2 LINE,5*8 FONT
delay_ms(100); //a small delay
writeI2C(0x00,0x08); //Display off
delay_ms(100); //a small delay
writeI2C(0x00,0x06); //Entry mode set
delay_ms(100); //a small delay
writeI2C(0x00,0x01); //CLEAR DISPLAY
delay_ms(100); //a small delay
writeI2C(0x00,0x0c); //DISPLAY ON,Cursor OFF,Cursor Blink OFF
delay_ms(100); //a small delay
}
Now the device should be in two line mode, but my LCD is not it is same as before one line mode.
Then I looked the datasheet very carefully and I found this

lcdbackdata.jpg

I checked my LCD and found

lcdback.jpg

It seemed right, it has JIF0 and JIF1 . it should be IF0 and IF1
I used these test program
#use i2c(MASTER, scl=PIN_C3, sda=PIN_C4, SLOW)
Here is the schematic

ONNELA.jpg

Here is a picture of LCD

LCDKUVA.jpg

Here is picture of Clock signal

i2c_clck.jpg

Here is picture of the data

ic2_data.jpg

Here are the both at same picture

I2CClock_IC2Data.jpg

Here are the main connections

onnelatest.jpg

Now it works!

working.jpg

It was missing I2C_SLAVE_ADDRESS!
//unsigned int8 data1[21]; // the data to LCD comes to here
void writeI2C ( unsigned int8 command, unsigned int8 data)
{
// 0x00 is command and 0x40 is data to command
// Data is the parameter for this command
i2c_start(); // Issues a start I2C
I2c_write(I2C_SLAVE_ADDRESS); //address the device
i2c_write(command); // 0x00 = command , 0x40 = data
i2c_write(data); // Sends a single byte over i2c
i2c_stop(); // stops i2c

}

Here is full working test code

// I2CLCD.c test program
// made by Pekka Ritamaki, Finland email: moc.liamg|odg3ho#moc.liamg|odg3ho
// date 2.2.2022
// proram: ccs c-cpmpiler v5.092
// for MIDAS I2C LCD MC2165A6WD-BNMLW-V2
// what: It does though PIC18F27K40 prossessor to LCD
// It does some simple tests to the I2C LCD
// Memory usage: ROM=1% RAM=1%
// I2C program for LCD MC1605A6WD-BNMLW-V2
#include <18F27K40.h> // define PIC type
#device ADC=10 // define ADC type, althoug it not here needed
#fuses RSTOSC_HFINTRC_64MHZ, NOXINST, NOMCLR, NOLVP, STVREN, NOFCMEN // setup
#fuses NOPUT, NODEBUG, NOPROTECT, NOWDT // setup for the processor
#fuses NOCPD, NOWRTD, NOWRTC, NOWRTB // setup for the processor
// if you use watchdog, use #fuses WDT512 or #fuses WDT4194304
#use delay(internal=32MHz,restart_wdt) // use internal oscillator
#pin_select U1TX=PIN_C6 // select UART TX pin
#pin_select U1RX=PIN_C7 // select UART RX pin

#use rs232(UART1,baud=9600) //Text through the UART

//The following define sets the I2C clock divisor, can be set to 4 or 5.
#define I2C_CLOCK_DIVISOR 4

// define how I2C is used in master mode
#use i2c(MASTER, scl=PIN_C3, sda=PIN_C4, SLOW)

//The following define sets the I2C LCD slave address that will be used
#define I2C_SLAVE_ADDRESS 0x78

The following define sets the MAX buffer size used with this device,
i.e. it controls the max number of bytes that can be written to or read from slave device.
#define MAX_BUFFER_SIZE 127

#define I2C_READ_DO_RESTART

The following is used to setup Timer 2, when USE_I2C_CLOCK_SOURCE is defined
as 2, so that it's setup to correctly generate the I2C clock for the specified
system clock, I2C_CLOCK_DIVISOR, and I2C_BAUD_RATE. If not specified the
I2C_BAUD_RATE is set for 400kHz.
#define LENGOFROW 16
//#define I2C_BAUD_RATE 400000
#define TIMER_PERIOD 1
#define TIMER_SETTINGS (T2_DIV_BY_128 | T2_CLK_INTERNAL)

#define one 0x80 // define command data for goto row 1
#define two 0xc0 // define command data for goto row 2
#define addr_row_one 0x00 //LCDN RAM address to row 1
#define addr_row_two 0x40 //LCDN RAM address to row 2
#define addr_row_three 0x14 //LCDN address to row 3
#define addr_row_four 0x54 //LCDN address to row 4
#define lcd_total_rows 2
#define lcd_total_columns 16
#include <stdlib.h>
#INCLUDE <STDLIB.H>
#include <input.c>

// the data to LCD comes to here
void writeI2C ( unsigned int8 command, unsigned int8 data)
{
// 0x00 is command and 0x40 is data to command
// Data is the parameter for this command

i2c_start(); // Issues a start I2C
I2c_write(I2C_SLAVE_ADDRESS); //address the device
i2c_write(command); // 0x00 = command , 0x40 = data
i2c_write(data); // Sends a single byte over i2c
i2c_stop(); // stops i2c

}
// goto row x and postion y
void lcd_gotoxy( byte x, byte y) // mene riville x ja sen paikkaan y
{
byte row,column,row_addr,lcd_address;

if (y>lcd_total_rows) row=lcd_total_rows; else row=y;

switch(row)
{
case 1: row_addr=addr_row_one; break;
case 2: row_addr=addr_row_two; break;
case 3: row_addr=addr_row_three; break;
case 4: row_addr=addr_row_four; break;
default: row_addr=addr_row_one; break;
}

if (x>lcd_total_columns) column=lcd_total_columns; else column=x;
lcd_address=(row_addr+(column-1));
writeI2C (0,0x80|lcd_address); // write command 0 ,address
}

=================================
INITIALIZE LCD writeI2C (command= 0x00, then data how command is done)
//==============================================
void Initial_I2C(){

writeI2C(0x00,0x38); //SET 2 LINE,5*8 FONT

writeI2C(0x00,0x08); //Display off

writeI2C(0x00,0x06); //Entry mode set

writeI2C(0x00,0x01); //CLEAR DISPLAY
delay_ms(100); //a small delay
writeI2C(0x00,0x0c); //DISPLAY ON,Cursor OFF,Cursor Blink OFF

}

#define CHARSINROW 16 // how menu characters in one row?
void LCD_PUTC(char in_data)
{
writeI2C(0x40, in_data); // commad =0x40 i.e data, and in_data is data character

}
// main program starts

void main ()
{
printf( "\rTesting"); // send data to seril poert
setup_timer_2(TIMER_SETTINGS, TIMER_PERIOD, 1);

Initial_I2C(); // initialize LCD to right mode
while(1)
{
printf(LCD_PUTC,"Testing…."); // send data to LCD
printf( "\rTesting…."); // send data to seril poert
delay_ms(100);
}
}

ok.jpg

Serial LCD adapter

SealLCD.jpg

Pekka moc.liamg|odg3ho#moc.liamg|odg3ho

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License