/*
	SC1LAD.C

	CM71xx/Z1 and CM72xx/Z2

	Translate (the inverse of) the state of the pushbutton switches to the LEDs.
	The LED is on when the adjacent switch is pushed down, and off when the
	adjacent switch is not pushed. The program beeps for 100 ms if any switch is
	pushed.
*/

#use vdriver.lib
#define BeepScale 0.04	// scale the time in up_beep(ms) to turn on beeper for
								// the correct millisecond ON time. Since lc_beepscan
								// is called every 25 ms, 1/25 = 0.04. 
main(){
	int state;

	VdInit();            // initialize the virtual driver
	while(1){
		runwatch();	hitwd();
		
		state = inport(CS2+1);			// read all the pushbuttons SW2..SW5    

		if( (state & 0x0F) != 0x0F)	// if any switch is pressed,
		up_beep(100);						// beep for 100 ms.
		
		outport( CS1  , ~(state     ));	// state of SW2 to led D2
		outport( CS1+1, ~(state >> 1));	// state of SW3 to led D3
		outport( CS1+2, ~(state >> 2));	// state of SW4 to led D4
		outport( CS1+3, ~(state >> 3));	// state of SW5 to led D5

		costate{
			waitfor(DelayMs(25L));			// monitor beeper every 25ms.
			lc_beepscan();
		}
	}
}

	
