C++ and the LCD function.

This is the English forum for all topics related to IO-Warrior. Please post in English only

Moderator: Guido Körber

williamk
Posts: 20
Joined: Thu Feb 19, 2004 8:06 am
Contact:

C++ and the LCD function.

Post by williamk »

Hy, sorry that I took so long to start the project I was working on. (had to relocate from Canada) Anyway ...

I got my LCD working, it works with the included VBLCD Example.

But my software is done with C++, so I'm trying to understand how to write a Report 4 to the IOW40.

Could you give me an example in C++ on how to turn-on the LCD and clear it? From this, I can do the rest.

Best Regards, WilliamK
supachris
Posts: 124
Joined: Tue Mar 16, 2004 12:30 am
Location: Dresden

Post by supachris »

I added following to the iowklass.h to get access to the Display

Code: Select all

ULONG LCD_Enable()
	{
	
		ULONG bytes;
		char data[7];

		data[0] = 0x04;
		data[1] = 0x01;


		bytes = IowKitWrite(m_devHandle, 1, data, 8);

		return bytes;
	}

		ULONG LCD_Disable()
	{
	
		ULONG bytes;
		char data[7];

		data[0] = 0x04;
		data[1] = 0x00;


		bytes = IowKitWrite(m_devHandle, 1, data, 8);

		return bytes;
	}
	
		ULONG LCD_Init()
	{
		ULONG bytes;
		char data[7];

		data[0] = 0x05;
		data[1] = 0x03;
		data[2] = 0x28 | 0x10; // for 2*16 display
		data[3] = 0x01;
		data[4] = 0x0F;

		bytes = IowKitWrite(m_devHandle, 1, data, 8);
		
		return bytes;
	}
	
	ULONG LCD_Cmd(int cmd)
	{
		ULONG bytes;
		char data[7];

		data[0] = 0x05;
		data[1] = 0x01;
		data[2] = cmd;

		bytes = IowKitWrite(m_devHandle, 1, data, 8);
		
		return bytes;
	}

	ULONG LCD_Set_Addr(int addr)
	{
		ULONG bytes;
		char data[7];

		data[0] = 0x05;
		data[1] = 0x01;
		data[2] = (0x80 | addr);

		bytes = IowKitWrite(m_devHandle, 1, data, 8);
		
		return bytes;
	}

	
	

	ULONG LCD_String(char *string)
	{
		ULONG bytes;
		char data[7];
		int nchars=0;
		int nnow=0;
		int ncurr=0;

		data[0]=0x05;

		nchars = strlen(string);
		while (ncurr < nchars)
		{
			if ((ncurr+6)>nchars)
			{
				nnow = nchars - ncurr;
			}
			else
			{
				nnow = 6;
			}

			data[1] = (0x80 | nnow);

			for (int x=0; x<nnow; x++)
			{
				data[x+2] = string[x+ncurr];
			}

			bytes = IowKitWrite(m_devHandle, 1, data, 8);

			ncurr = ncurr +6;
		}
		return bytes;
}
For clear you have to choose the right command code and give them to the LCD_Cmd methode off your iow class
williamk
Posts: 20
Joined: Thu Feb 19, 2004 8:06 am
Contact:

Post by williamk »

:mrgreen: :mrgreen:

I can't thank you enought! THANKS!

It works perfectly for what I need. Now I have to learn how to handle graphics on my 4 line display. ;-)

Best Regards, WilliamK
supachris
Posts: 124
Joined: Tue Mar 16, 2004 12:30 am
Location: Dresden

Post by supachris »

Graphics on an alphanumeric display? With user defined chars? Hmm...I think that wouldn´t look pretty...
williamk
Posts: 20
Joined: Thu Feb 19, 2004 8:06 am
Contact:

Post by williamk »

If I'm not wrong, the datasheet of the LCD I got has some basic graphics. Anyway, is not a must for my project. ;-)

I just tested and your code works like a charm. 8)

My other problem is how I will manage a data-entry pot.
http://www.codemercs.com/phpBB2/viewtopic.php?t=23
If it won't work, I just use some +/- knobs...

Wk
williamk
Posts: 20
Joined: Thu Feb 19, 2004 8:06 am
Contact:

Post by williamk »

Ahhh, just one small problem. When I plug the USB cable to the IOW40, the LCD starts with a series of squares. Is there a way to make it init BLANK? Do "I" have to put something on the board to make that? Otherwise it will look strange...

Wk
williamk
Posts: 20
Joined: Thu Feb 19, 2004 8:06 am
Contact:

Post by williamk »

I just read that you can have 8 user-built characters.

http://www.repairfaq.org/filipg/LINK/F_LCD_HD44780.html

Wk
Guido Körber
Site Admin
Posts: 2856
Joined: Tue Nov 25, 2003 10:25 pm
Location: Germany/Berlin
Contact:

Post by Guido Körber »

williamk wrote:If I'm not wrong, the datasheet of the LCD I got has some basic graphics.
The HD44780 LCD controllers support a few (8 if I remember correctly) programmable characters. Usually sufficenty for just a few special thing but not really graphics.
Guido Körber
Site Admin
Posts: 2856
Joined: Tue Nov 25, 2003 10:25 pm
Location: Germany/Berlin
Contact:

Post by Guido Körber »

williamk wrote:Ahhh, just one small problem. When I plug the USB cable to the IOW40, the LCD starts with a series of squares. Is there a way to make it init BLANK? Do "I" have to put something on the board to make that? Otherwise it will look strange...
This depends on the contrast setting of the LCD, but it is perfectly normal behaviour and there is nothing you can do to prevent this. Until the LCD controller gets initialized this is what it does.
Robert Marquardt
Posts: 543
Joined: Mon Dec 01, 2003 6:09 pm

Post by Robert Marquardt »

williamk wrote:Ahhh, just one small problem. When I plug the USB cable to the IOW40, the LCD starts with a series of squares. Is there a way to make it init BLANK? Do "I" have to put something on the board to make that? Otherwise it will look strange...

Wk
You will have to initialize the LCD with some commands.
williamk
Posts: 20
Joined: Thu Feb 19, 2004 8:06 am
Contact:

Post by williamk »

Guido Körber wrote:
williamk wrote:Ahhh, just one small problem. When I plug the USB cable to the IOW40, the LCD starts with a series of squares. Is there a way to make it init BLANK? Do "I" have to put something on the board to make that? Otherwise it will look strange...
This depends on the contrast setting of the LCD, but it is perfectly normal behaviour and there is nothing you can do to prevent this. Until the LCD controller gets initialized this is what it does.
Is there a way to add on the driver an option to init on plug? It is a big deal, as most users will just leave the USB connected until they run the software.

Maybe I will just add an On/Off knob on my project, that's all...

Wk
Guido Körber
Site Admin
Posts: 2856
Joined: Tue Nov 25, 2003 10:25 pm
Location: Germany/Berlin
Contact:

Post by Guido Körber »

williamk wrote:Is there a way to add on the driver an option to init on plug? It is a big deal, as most users will just leave the USB connected until they run the software.
If you want to write a new Windows driver...

IO-Warrior uses the HID drivers of the system. They know nothing about an LCd connected to the IO-Warrior, they don't even know anything about IO-Warrior.

What you could do though is write an application that runs in the background and waits for the device to get plugged in.

But the other thing you can do is play with the contract setting pot for the LCD to see if you can reduce the intensity of the squares. Usually the squares are not very prominent if the setting is done properly.
williamk
Posts: 20
Joined: Thu Feb 19, 2004 8:06 am
Contact:

Post by williamk »

Thanks Guido, for now I will leave like that and just add an On/Off switch.

Wk
williamk
Posts: 20
Joined: Thu Feb 19, 2004 8:06 am
Contact:

Post by williamk »

BTW: Can't I use the same ON port that lights the backlite to open the 5+V or Ground to the LCD? So it stays OFF until you send the LCD-ON command? If I said something stupid, ignore me ...

Wk
Guido Körber
Site Admin
Posts: 2856
Joined: Tue Nov 25, 2003 10:25 pm
Location: Germany/Berlin
Contact:

Post by Guido Körber »

williamk wrote:BTW: Can't I use the same ON port that lights the backlite to open the 5+V or Ground to the LCD? So it stays OFF until you send the LCD-ON command? If I said something stupid, ignore me ...

Wk
If you make sure that the voltage drop across your transistor (or whatever you use to switch the supply voltage) is low enough you can do that. You should switch the +5V end of the power, switching ground is more critical as this is the comman reference and if that changes you can get errors.
Post Reply