Example #1
0
void main(void)
{
	int result;
	float voltage;
	int status;
	
	M8C_EnableGInt ; // Uncomment this line to enable Global Interrupts
	// Insert your main routine code here.
	
	//Start PGA in high power mode
	PGA_Start(PGA_HIGHPOWER);
	
	//Start ADCINC in high power mode
	ADCINC_Start(ADCINC_HIGHPOWER);
	
	//Start LCD
	LCD_Start();
	
	//Run the ADC continuously
	ADCINC_GetSamples(0);
	
	SleepTimer_Start();
   	SleepTimer_SetInterval(SleepTimer_1_HZ);
   	SleepTimer_EnableInt();
	
	while (1)
	{
		SleepTimer_SyncWait(1, SleepTimer_WAIT_RELOAD);
		
		// Wait for data to be ready
		while (ADCINC_fIsDataAvailable() == 0);
		
		// Get Data and clear flag
		result=ADCINC_iClearFlagGetData();
		voltage = result * SCALE_FACTOR;
		
		LCD_Position(0, 0);
		LCD_PrCString("                ");
		LCD_Position(0, 0);
		LCD_PrHexInt(result);
		
		LCD_Position(1, 0);
		LCD_PrCString("                ");
		LCD_Position(1, 0);
		LCD_PrString(ftoa(voltage, &status));
	}
}
Example #2
0
void main(void)  
{
    // Initialize Pull Up/Down ressistors
    //Port_0_Data_SHADE = 0x80;                     // Enable distance input pull-up P0.7
    //PRT0DR = Port_0_Data_SHADE;
    Port_2_Data_SHADE = 0x04;                     // Enable pull-down resistor on LED P2.2
    PRT2DR = Port_2_Data_SHADE;
    Port_3_Data_SHADE = 0x20;                     // Enable pull-up on button bit P3.5 
    PRT3DR = Port_3_Data_SHADE;
    Port_4_Data_SHADE = 0x44;						// Enable pull-down LED P4.2, P4.6
    PRT4DR = Port_4_Data_SHADE;

    Timer8_WritePeriod(50);				// 12MHz/15/16/50 = 1KHz => 1ms main timer interrupt
    Timer8_WriteCompareValue(0);
    Timer8_EnableInt();
    Timer8_Start();
	PRS8_WritePolynomial(0x78);			// load the PRS polynomial
	PRS8_WriteSeed(0xFF);				// load the PRS seed
	PRS8_Start();						// start the PRS8
	RED_Start();
	GREEN_Start();
	BLUE_Start();
    PWM8_WritePeriod(100);				// set period to eight clocks
    PWM8_WritePulseWidth(0); 			// set pulse width to generate a % duty cycle 
    PWM8_EnableInt(); 					// ensure interrupt is enabled  
    PWM8_Start();						// start PWM 
    //DAC_CR &= ~0x80;	                // turn off SplitMUX bit 7 (P0[7] on right, others on left)    
    PGA_Start(PGA_HIGHPOWER);           // Start PGA
    ADCINC_Start(ADCINC_HIGHPOWER);     // Start ADC
    ADCINC_GetSamples(1);               // initiate the first sample
	
    M8C_EnableGInt;						// Global interrupt enable
  
	ReadFlash();						// read on/off times and LED dutycyle from FLASH
    if(!(RamFlashBlock.Dummy == 0x55))
    {
        SetFlashDefaults();             // clear flash first time
    } 

	LedPowerTog = 1;						// flag change				
	LedPower = RamFlashBlock.PowerState;
    RedDutyMax = RamFlashBlock.RedDuty;
    BlueDutyMax = RamFlashBlock.BlueDuty;
    GreenDutyMax = RamFlashBlock.GreenDuty;
	the_state = RamFlashBlock.the_state;		
	ledChangeRate = RamFlashBlock.ledChangeRate;
	
    Events.press = 0;
    Events.hold = 0;
    Events.release = 0;  	
    MenuFsm(&Events, &the_state);       // initlaize the state machine 
	
    USB_Start(0, USB_3V_OPERATION);     // Start USB
    //while (!USB_bGetConfiguration());   // Wait to be enumerated
    USB_INT_REG |= USB_INT_SOF_MASK;
    USB_EnableOutEP(1);                 // Post a buffer to wait for a command
			    
    while(1)                            // cycle the puck here
    {       
        MeasureTemperature();               // sample input temperature sensor voltage
        ThermalProtection();                 // decrease LED power if temperature rises above limit
		ButtonStates();                    // button driver
        CommunicateUSB();                       // USB driver
		LedStates();						// LED Cadence state machine
		DelayedSaveFlash();					// Save power state and RGB dutycycle 10 seconds after last button event
	}
}