Пример #1
0
//子main函数
void ADC_read_W1(){                     
    static U32 save_A, save_B, save_BD;
    int read_xpdata0;
     
//**********************保护现场************************** 
    save_A   = rADCCON;  
    save_B   = rGPBCON;
    save_BD  = rGPBDAT;
//********************************************************
    
    ADC_display();  
    LED_INIT();  //初始化LED
   
    //while(1)
    Delay(100);Uart_Printf("\n\nq:退出\n");
    while(Uart_GetKey() != 'q')
    {
     /*串口打印变阻器模拟信号数值*/
     W1_ADC( &read_xpdata0 );//传递read_xpdata0地址,改变read_xpdata0的值来给W1_LED函数使用
    
     /*****LED点亮函数*****/
     W1_LED(read_xpdata0);                 //LED函数
     
    }
    
//**********************还原现场**************************         
    rADCCON = save_A;
    rGPBCON = save_B;
    rGPBDAT = save_BD;
//********************************************************    

}
Пример #2
0
/*
 *  ======== main ========
 */
int main(int argc, char *argv[])
{
	CSL_init();                 // Activate Grace-generated configuration
	delay();					//
    System_Initial();			// initialize system.
   	delay();					// delay and wait the first conversion.
   	_enable_interrupt();		// enable interrupt

   	while(1)
   	{
   		// half a second interrupt.
   		if(flag & BIT7)
   		{
   			half_second();
   		}

   		// read ADC result
   		if(flag & BIT4)			//Read ADC result
   		{
   			ADC_display();
   		}

   		// one second interrupt to display time
   		if (flag & BIT3)
   		{
   			time_display();
   		}

   		if(flag & BIT1)				// if SW1 is pushed, threshold temperature
   		{							//   state machine will be changed
   			flag &= ~ BIT1;			// flag is reset
   			time_state = 0;			//when threshold temperature is setting,
   									//setting time is disable.
   			if(!customThreshold) {
   				meatSelect();		//Enter meat select menu if not setting custom
   			}
   			if(Thr_state >= 3)		// if in state 3, change to state 0;
   			{
   				Thr_state = 0;
   				Thr_temp = set_temp;				// assign threshold temperature
   				LCD_display_number(0,4,Thr_temp);	// display threshold temperature

   				customThreshold = 0;		//Reset custom threshold flag
   			}
   			else							//else, Thr_state is changed to next state
   			{
   				Thr_state ++;
   			}
   		}

   		if((flag & BIT2) && (!Thr_state))	// if SW2 is pushed, and Thr_state = 0,
   		{									// time setting state machine will be changed
   			flag &= ~ BIT2;					// flag is reset

   			if(!(P1IN & BIT3))
   			{
   				flag ^= BIT9;		// S2 and SW2 are pushed together to change input
   				flag ^= BIT8;
   				if(flag & BIT9)		// Display external temp
   					LCD_display_string(1,"   Ext :");
   				else				//Display probe temp
   					LCD_display_string(1," Probe :");
   			}
   			else
   			{
   				if(time_state >= 4)					// if in state 4, change to state 0;
   				{
   					time_state = 0;
   				 	time = set_time;				// assign actual time
   					set_time = 0;
   					LCD_display_time(0,8,time);		// display setting time
   				}
   				else
   				{
   					time_state ++;
   				}
   			}
   		}

   		if(flag & BIT0)				// P1.3 service, set the Threshold temp or Time.
   		{
   			flag &= ~ BIT0;			// flag is reset
   			if(Thr_state != 0)
   			{
   				set_Thrtemp();		// set threshold temperature.
   			}
   			else if(time_state != 0)
   			{
   				set_Time();			// set timer.
   			}
   			else
   				flag ^= BIT8;		// display temperature in Fahrenheit
   		}

   		else
   		__no_operation();
   	}
}