void main(void) { // Insert your main routine code here. unsigned char c = 0; M8C_EnableGInt; UART_EnableInt(); UART_Start(UART_PARITY_NONE); PGA_1_Start(PGA_1_HIGHPOWER); ADCINC_Start(ADCINC_HIGHPOWER); // Apply power to the SC Block ADCINC_GetSamples(0); DAC6_Start(DAC6_HIGHPOWER); PWM8_DisableInt(); PWM8_Start(); for(;;) { PWM8_WritePulseWidth(m_to_s_mem[0]); DAC6_WriteBlind(m_to_s_mem[1]); //if ( DELSIG8_bfStatus ) { // DELSIG8_bfStatus = 0; // s_to_m_mem[0] = DELSIG8_cResult; //} //ADCINC_GetSamples(1); //while(ADCINC_fIsDataAvailable() == 0); //s_to_m_mem[0] = ADCINC_bClearFlagGetData(); } //mainloop: // UART_SendData(temp++); //while( ++temp2 ); //goto mainloop; }
/************************************************************************ * DelayedSaveFlash - Save power state and RGB dutycycle 10 seconds after * last button event * * Parameters: none * Returns: none ************************************************************************/ void DelayedSaveFlash (void) { if((!SaveFlashTimer) && WriteFlashFlag) // If counter expires and flash flag set { WriteFlashFlag = 0; PWM8_Stop(); WriteFlash(); // store to Flash PWM8_Start(); } }
void main(void) { LCD_Start(); LCD_Init(); LCD_InitBG(LCD_SOLID_BG ); PWM8_Start(); M8C_EnableGInt ; // Uncomment this line to enable Global Interrupts INT_MSK0 |= 0x20; PRT0IE |= 0x01; PRT0DM0 = 0x01; //DM0[0-3] = 1 PRT0DM1 = 0x01; //DM1[0-3] = 0 PRT0DM2 = 0x00; //DM1[0-3] = 0 PRT0IC1 = 0x01; PRT0IC0 = 0x00; while(1){ if(pulsewidth==255){ pwDir = 1; } PWM8_WritePulseWidth(pulsewidth); LCD_DrawBG(0,0,16,pulsewidth/5); LCD_DrawBG(1,0,16,72); } }
/************************************************************************ * PWM8_ISR * Interrupt Period: 4ms 250Hz * Parameters: none * Returns: none ************************************************************************/ void PWM8_ISR(void) { PWM8_Stop(); // There are 6 special cases of colour display where the dutycyle is // no longer 1/3 RGB, the first three cases the dutycycle is unity while // the last three are 1/2 dutycyle // 1. Red // 2. Green // 3. Blue // 4. Red/Green // 5. Red/Blue // 6. Blue/Green // 1. Red if(RedDuty && !GreenDuty && !BlueDuty) { MultiplexCount = 0; // Override multiplex = red/red/red if(!RedUpFlag) // First time for 100% red case { RedUpFlag = 1; if(RedBlueUpFlag || RedGreenUpFlag) { //RedDuty = RedDuty/2; // We are currently at 1/2 duty } else { //RedDuty = RedDuty/3; // We are currently at 1/3 duty } } } else { RedUpFlag = 0; // Clear flag on exit } // 2. Green if(!RedDuty && GreenDuty && !BlueDuty) { MultiplexCount = 1; // Override multiplex green if(!GreenUpFlag) // First time for 100% Green case { GreenUpFlag = 1; if(GreenBlueUpFlag || RedGreenUpFlag) { //GreenDuty = GreenDuty/2; // We are currently at 1/2 duty } else { //GreenDuty = GreenDuty/3; // We are currently at 1/3 duty } } } else { GreenUpFlag = 0; // Clear flag on exit } // 3. Blue if(!RedDuty && !GreenDuty && BlueDuty) { MultiplexCount = 2; // Override multiplex glue if(!BlueUpFlag) // First time for 100% Blue case { BlueUpFlag = 1; if(RedBlueUpFlag || GreenBlueUpFlag) { //BlueDuty = BlueDuty/2; // We are currently at 1/2 duty } else { //BlueDuty = BlueDuty/3; // We are currently at 1/3 duty } } } else { BlueUpFlag = 0; // Clear flag on exit } // 4. Red/Green if(RedDuty && GreenDuty && !BlueDuty) { if(MultiplexCount) { MultiplexCount = 0; // Override multiplex red } else { MultiplexCount = 1; // Override multiplex green } if(!RedGreenUpFlag) { //RedDuty = RedDuty/2; // Reduce to 1/2 duty //GreenDuty = GreenDuty/2; // Reduce to 1/2 duty RedGreenUpFlag = 1; // Clear flag on exit } } else { RedGreenUpFlag = 0; // } // 5. Red/Blue if(RedDuty && !GreenDuty && BlueDuty) { if(MultiplexCount) { MultiplexCount = 0; // Override multiplex red } else { MultiplexCount = 2; // Override multiplex Blue } if(!RedBlueUpFlag) { //RedDuty = RedDuty/2; // Reduce to 1/2 duty //BlueDuty = BlueDuty/2; // Reduce to 1/2 duty RedBlueUpFlag = 1; // } } else { RedBlueUpFlag = 0; // } // 6. Green/Blue if(!RedDuty && GreenDuty && BlueDuty) { if(MultiplexCount == 1) { MultiplexCount = 2; // Override multiplex Blue } else { MultiplexCount = 1; // Override multiplex Green } if(!GreenBlueUpFlag) { //GreenDuty = GreenDuty/2; // Reduce to 1/2 duty //BlueDuty = BlueDuty/2; // Reduce to 1/2 duty GreenBlueUpFlag = 1; // } } else { GreenBlueUpFlag = 0; // } // Red/Green/Blue if(RedDuty && GreenDuty && BlueDuty) { if(MultiplexCount < 2) // count 0, 1, 2, 0, 1, 2 ... { MultiplexCount++; } else { MultiplexCount = 0; } } switch(MultiplexCount) // Multiplex LED { case 0: { PWM8_WritePulseWidth(RedDuty); GREEN_Switch(0); BLUE_Switch(0); RED_Switch(1); break; } case 1: { PWM8_WritePulseWidth(GreenDuty); RED_Switch(0); GREEN_Switch(1); BLUE_Switch(0); break; } case 2: { PWM8_WritePulseWidth(BlueDuty); GREEN_Switch(0); BLUE_Switch(1); RED_Switch(0); break; } default: { PWM8_WritePulseWidth(0); } } PWM8_Start(); }
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 } }