/**********************************************************
	switchtolcd.c
   Z-World, 2002

	This program is used with RCM3400 series controllers
	with prototyping boards.

	An optional LCD/Keypad Module is required to run this
	program.  #define PORTA_AUX_IO at top of program to
	enable external I/O bus for LCD/Keypad operations.
	
	Description
	===========
	This sample program demonstrates the use of the external
	I/O bus with the controller using an LCD/Keypad Module.
	The program will light-up an LED and will display a message
	on the LCD when a switch press is detected.

	DS1 and DS2 LED's on the proto-board will also light-up
	on a switch press.
	
	Instructions
	============
	1. Compile and run this program.
	2. Press and hold DS1 or DS2 on the prototyping board to
	   see a message displayed on the LCD and light up an LED.
	   Here's a list of how the switches are connected.      

	   Switch   Proto Board LED  Controller Keypad LED
	   ------   --------------  ---------------------
	    S2       DS1             DS6
	    S3       DS2             DS7 
			 
**********************************************************/
#class auto
#define PORTA_AUX_IO		//required to run LCD/Keypad for this demo
#memmap xmem

#define DS1(x) (BitWrPortI(PDDR, &PDDRShadow, x, 6))	//led, port D bit 6
#define DS2(x) (BitWrPortI(PDDR, &PDDRShadow, x, 7))	//led, port D bit 7
#define S2  (BitRdPortI(PDDR, 5)) 							//switch, port D bit 5
#define S3  (BitRdPortI(PDDR, 4))							//switch, port D bit 4
#define ON	0
#define OFF 1

// Structure to hold font information
fontInfo fi6x8;

///////////////////////////////////////////////////////////////////////////

main()
{

	//------------------------------------------------------------------------
	// Initialize the controller
	//------------------------------------------------------------------------	
	brdInit();				//initialize board for this demo

	dispInit();
			
	keypadDef();		// Use the default keypad ASCII return values

	glBackLight(1);	// Turn-on the backlight
	glXFontInit(&fi6x8, 6, 8, 32, 127, Font6x8);			//	Initialize 6x8 font
	glBlankScreen();
	for(;;)
	{
		glPrintf (0,  0, &fi6x8,  "Waiting for a Switch"); 
		glPrintf (0,  8, &fi6x8,  "to be pressed on the");
		glPrintf (0,  16, &fi6x8, "prototyping board...");
		
		while (S2 && S3);
		glBlankScreen();
		if (!S2)
		{
			glPrintf (0,  0, &fi6x8, "Switch 2 is Active!");
			dispLedOut(5, 1);   			//Turn-on Keypad LED DS1
			DS1(ON);							//proto-board DS1 on

			while (!S2);
			dispLedOut(5, 0); 			// Turn-OFF Keypad LED DS1
			DS1(OFF);						//proto-board DS1 off
		}
		if (!S3)
		{
			glPrintf (0,  0, &fi6x8, "Switch 3 is Active!");
			dispLedOut(6, 1); 			//Turn-on Keypad LED DS2
			DS2(ON);							//proto-board DS2 on

			while (!S3);
			dispLedOut(6, 0); 			// Turn-OFF Keypad LED DS2
			DS2(OFF);						//proto-board DS2 off
		}
		glBlankScreen();
	}
}			

	