int main(void)
{
	// configure WDT
	WDTCTL = WDTPW | WDTHOLD;							// stop watch dog timer

	P1DIR |= _LED | _SCLK | _SDATA;						// set all pins used to output
	P1OUT &= ~(_LED | _SCLK | _SDATA);					// set all outputs low

	P1SEL |= _SCLK | _SDATA;							// connect pins to USCI (secondary peripheral)
	P1SEL2 |= _SCLK | _SDATA;							// connect pins to USCI (secondary peripheral)

	P2DIR |= _DISP | _SCS;								// set all pins used to output
	P2OUT &= ~(_DISP | _SCS);							// set all outputs low

	// configure UCSI B0 for SPI
	UCB0CTL1 |= UCSWRST;								// reset USCI B0
	UCB0CTL0 = UCCKPH | UCMST | UCMODE_0 | UCSYNC;		// read on rising edge, inactive clk low, lsb, 8 bit, master mode, 3 pin SPI, synchronous
	UCB0BR0 = 8; UCB0BR1 = 0;							// clock scaler = 8, i.e 2 MHz SPI clock
	UCB0CTL1 = UCSSEL_2;								// clock source SMCLK, clear UCSWRST to enable USCI B0
	UCB0CTL1 &= ~UCSWRST;								// enable USCI B0

	// setup timer A, to keep time and alternate VCOM at 1Hz
	timeMSec = 0;										// initialize variables used by "clock"
	timeSecond = 0;
	timeMinute = 0;

	VCOM = 0;											// initialize VCOM, this flag controls LCD polarity
														// and has to be toggled every second or so

	TA0CTL = TASSEL_2 + MC_1;							// SMCLK (default ~1MHz), up mode
	TACCR0 = 1000;										// trigger every millisecond
	TACCTL0 |= CCIE;									// timer 0 interrupt enabled

	P2OUT |= _DISP;										// turn  display on

	// initialize display
	P2OUT |= _SCS;										// SCS high, ready talking to display
	SPIWriteByte(MLCD_CM | VCOM);						// send clear display memory command
	SPIWriteByte(0);									// send command trailer
	P2OUT &= ~_SCS;										// SCS lo, finished talking to display

	// write some text to display to demonstrate options
	printSharp("HELLO,WORLD?",1,0);
	printSharp(" SHARP",16,DISP_WIDE);
	printSharp("   MEMORY   ",24,DISP_INVERT);
	printSharp("  DISPLAY!",32,DISP_HIGH);
	printSharp("123456789012",56,0);

	while(1)
	{
		// show VCOM state on LED1 for visual control
		if(VCOM == 0)
		{
			P1OUT &= ~_LED;
		}
		else
		{
			P1OUT |= _LED;
		}

		// write clock to display
		TextBuff[0] = ' ';
		TextBuff[1] = timeMinute / 10 + '0';
		TextBuff[2] = timeMinute % 10 + '0';
		TextBuff[3] = ':';
		TextBuff[4] = timeSecond / 10 + '0';
		TextBuff[5] = timeSecond % 10 + '0';
		TextBuff[6] = 0;
		printSharp(TextBuff,72,DISP_HIGH | DISP_WIDE);

		// put display into low-power static mode
		P2OUT |= _SCS;									// SCS high, ready talking to display
		SPIWriteByte(MLCD_SM | VCOM);					// send static mode command
		SPIWriteByte(0);								// send command trailer
		P2OUT &= ~_SCS;									// SCS lo, finished talking to display

		// sleep for a while
		_BIS_SR(LPM0_bits + GIE);						// enable interrupts and go to sleep
	};
}
int main(void)
{
	// configure WDT
	WDTCTL = WDTPW | WDTHOLD;							// stop watch dog timer

	P1DIR |= _LED | _DISP | _SCLK | _SDATA | _SCS;		// set all pins used to output
	P1OUT &= ~(_LED | _DISP | _SCLK | _SDATA | _SCS);	// set all outputs low

	// setup USI for SPI
	USICTL0 = USIPE6 | USIPE5 | USILSB					// enable SDO and SCLK, LSB sent first
					 | USIMST | USIOE;					// master, enable data output
	USICTL1 = USICKPH;									// data captured on first edge
	USICKCTL = USIDIV_1 | USISSEL_2;					// /1 SMCLK (= default ~1MHz), clock low when inactive

	// setup timer A, to keep time and alternate VCOM at 1Hz
	timeMSec = 0;										// initialize variables used by "clock"
	timeSecond = 0;
	timeMinute = 0;

	VCOM = 0;											// initialize VCOM, this flag controls LCD polarity
														// and has to be toggled every second or so

	TA0CTL = TASSEL_2 + MC_1;							// SMCLK (default ~1MHz), up mode
	TACCR0 = 1000;										// trigger every millisecond
	TACCTL0 |= CCIE;									// timer 0 interrupt enabled

	P1OUT |= _DISP;										// turn  display on

	// initialize display
	P1OUT |= _SCS;										// SCS high, ready talking to display
	SPIWriteByte(MLCD_CM | VCOM);						// send clear display memory command
	SPIWriteByte(0);									// send command trailer
	P1OUT &= ~_SCS;										// SCS lo, finished talking to display

	// write some text to display to demonstrate options
	printSharp("HELLO,WORLD?",1,0);
	printSharp(" SHARP",16,DISP_WIDE);
	printSharp("   MEMORY   ",24,DISP_INVERT);
	printSharp("  DISPLAY!",32,DISP_HIGH);
	printSharp("123456789012",56,0);

	while(1)
	{
		// show VCOM state on LED1 for visual control
		if(VCOM == 0)
		{
			P1OUT &= ~_LED;
		}
		else
		{
			P1OUT |= _LED;
		}

		// write clock to display
		TextBuff[0] = ' ';
		TextBuff[1] = timeMinute / 10 + '0';
		TextBuff[2] = timeMinute % 10 + '0';
		TextBuff[3] = ':';
		TextBuff[4] = timeSecond / 10 + '0';
		TextBuff[5] = timeSecond % 10 + '0';
		TextBuff[6] = 0;
		printSharp(TextBuff,72,DISP_HIGH | DISP_WIDE);

		// put display into low-power static mode
		P1OUT |= _SCS;									// SCS high, ready talking to display
		SPIWriteByte(MLCD_SM | VCOM);					// send static mode command
		SPIWriteByte(0);								// send command trailer
		P1OUT &= ~_SCS;									// SCS lo, finished talking to display

		// sleep for a while
		_BIS_SR(LPM0_bits + GIE);						// enable interrupts and go to sleep
	};
}