4-line I2C LCD Test on nanoWipom board


4-line I2C LCD Test.

Toolkit:STM Development System

Location:/bipom/devtools/STM32/examples/nanoWipom/i2c_lcd

Code Example


int main(void) 
{
	ERRCODE ec;
	// Initialize all port pins 

	NWDIO_Init();
	
	delayMs(250);
	
	// Send welcome message

	tprintf("\n\rNanoWipom %s %s",__DATE__,__TIME__);
	tprintf("\n\rI2C LCD TEST REV 1.01");
	delayMs(250);
	// Initialize I2C

	Soft_I2C_Config(&I2C_SETTINGS); 
	// Repair I2C

	ec = Soft_I2C_Repair();
	if (ec)
	{
		tprintf("\r\nERROR:can't repair I2C bus, ec=%d", ec);
		goto func_end;
	}
	// Initialize LCD

	ec = InitializeI2CLCD();
	if (ec)
	{
		tprintf("\r\nERROR:can't initialize I2C LCD, ec=%d", ec);
		goto func_end;
	}
	//

	while(1) 
	{
		// Clear LCD

		ec = ClearI2CLCD();
		if (ec)
		{
			tprintf("\r\nERROR:can't clear I2C LCD, ec=%d", ec);
			goto func_end;
		}
		// Set Top line

		SetTopLineI2CLCD();
		if (ec)
		{
			tprintf("\r\nERROR:can't set TOP line of I2C LCD, ec=%d", ec);
			goto func_end;
		}
		//

		ec = printf_I2CLCD("This is %dst line",1);
		if (ec)
		{
			tprintf("\r\nERROR:can't set TOP line of I2C LCD, ec=%d", ec);
			goto func_end;
		}
		// Set 2nd line

		Set2ndLineI2CLCD();
		if (ec)
		{
			tprintf("\r\nERROR:can't set 2nd line of I2C LCD, ec=%d", ec);
			goto func_end;
		}
		//

		ec = printf_I2CLCD("This is %dnd line",2);
		if (ec)
		{
			tprintf("\r\nERROR:can't set 2nd line of I2C LCD, ec=%d", ec);
			goto func_end;
		}
		// Set 3rd line

		Set3rdLineI2CLCD();
		if (ec)
		{
			tprintf("\r\nERROR:can't set 3rd line of I2C LCD, ec=%d", ec);
			goto func_end;
		}
		//

		ec = printf_I2CLCD("This is %drd line",3);
		if (ec)
		{
			tprintf("\r\nERROR:can't set 3rd line of I2C LCD, ec=%d", ec);
			goto func_end;
		}
		// Set 4th line

		SetBottomLineI2CLCD();
		if (ec)
		{
			tprintf("\r\nERROR:can't set 4th line of I2C LCD, ec=%d", ec);
			goto func_end;
		}
		//

		ec = printf_I2CLCD("This is %dth line",4);
		if (ec)
		{
			tprintf("\r\nERROR:can't set 4th line of I2C LCD, ec=%d", ec);
			goto func_end;
		}
		//

		delayMs(2000);
  	}
	//

func_end:	
	tprintf("\r\nERROR:I2C LCD test failed");
	for(;;);
	return 0;
}