示例#1
0
main()
{
	P1DIR = BIT6;
	P1OUT = BIT6;
	init_adc();
	
	while(1)
	{
		start_conversion();
		
		while( converting() )
			;
			
		if( ADC10MEM > 380 )
			P1OUT = 0;
		else
			P1OUT = BIT6;
		delay();
		
	}
}
示例#2
0
void main()
{
	P1DIR = LED1|LED2;
	P1OUT = 0x0;
	adc_init();
	while(1)
	{
		start_conversion();
		if(!converting())
		{
			if(ADC10MEM>767)		/***Check whether the voltage is in between 2.7 and 3.6V*****/
				P1OUT = LED1|LED2;
			else if(ADC10MEM>511)   /****checking whether the voltage level is in between 1.8 and 2.7******/
				P1OUT = LED1;
			else if(ADC10MEM>255)  /***checking whether the voltage is in between 0.9 & 1.8 **/
				P1OUT = LED2;
			else					/****checking whether the voltage is in between 0 and 0.9 *****/
				P1OUT = 0x00;
		}
		delay(30000);
	}
			
}	
示例#3
0
__interrupt void Port_1(void)
{
	ADC10CTL0 = ADC10ON | SREF_0 | ADC10SHT_2;
	ADC10CTL1 = INCH_0 | SHS_0 | ADC10SSEL_0 | ADC10DIV_0 | CONSEQ_0;
	ADC10CTL0 |= ENC;
	ADC10AE0 = BIT0;
	ADC10CTL0 |= ADC10SC; 	// start conversion
	while (converting());
	if (ADC10MEM < 340)		// 340 Vss 3.0v, 360 Vss 3.6v
	{
		int j;
		for (j=0; j<40; j++)
		{
			volatile unsigned int i;

			P1OUT ^= BIT2;
			i = 2000;
			do i--;
			while(i != 0);
			P1OUT ^= BIT2;
			i = 3000;
			do i--;
			while(i != 0);

			P1OUT ^= BIT4;
			i = 2000;
			do i--;
			while(i != 0);
			P1OUT ^= BIT4;
			i = 3000;
			do i--;
			while(i != 0);

/*
 * 	P1.0 is used as light sensor
 */

	//		P1OUT ^= BIT0;
	//		i = 2000;
	//		do i--;
	//		while(i != 0);
	//		P1OUT ^= BIT0;
	//		i = 2000;
	//		do i--;
	//		while(i != 0);

			/*
			 *	for dog collar, don't use this one to save power
			 *
			 */
			P2OUT ^= BIT6;
			i = 2000;
			do i--;
			while(i != 0);
			P2OUT ^= BIT6;
			i = 3000;
			do i--;
			while(i != 0);
		}
	} // ADC10MEM

	// acknowledge interrupt by reading STATUS register
	ReadStatusRegister();

	P1IFG &= ~BIT3;                           // P1.3 IFG cleared

	// restart measurement in wakeup mode again after interrupt is cleared
	WriteByteToRegister( 0x2D, 0x0A );
}