//---------------------------------------------------------------------------- // C main line //---------------------------------------------------------------------------- #include // part specific constants and macros #include "PSoCAPI.h" // PSoC API definitions for all User Modules #include "stdlib.h" int MAXC=0; int TEMPC=500; char degC[]="500"; char degF[]="932"; int TEMPF=932; void main() { int w,z; int KeyRead,KeyBuffer; int x,buffer; float temperature=0; float temperature2=0; int count=0; int stop=1; int CycleBuffer; int base=1; int InputADC; int InputADC2; char lcd_Reading[8]; char lcd_Setting[8]; PGA_1_SetGain(PGA_1_G1_00); PGA_1_Start(PGA_1_LOWPOWER); DAC9_1_Start(DAC9_1_FULLPOWER); LCD_1_Start(); // Initialize LCD M8C_EnableGInt; // Enable Global Interrupts AboveTop: DAC9_1_WriteBlind(0); //set output to 0V ADCINC12_1_Start(ADCINC12_1_LOWPOWER); // Apply power to the SC Block ADCINC12_1_GetSamples(0); // Have ADC run continuously LCD_1_Control(LCD_1_DISP_CLEAR_HOME); LCD_1_Position(0,0); LCD_1_PrCString("MAX Limit"); LCD_1_Position(0,10); if (base==0) { MAXC=TEMPF; LCD_1_PrString(degF); LCD_1_Position(0,14); LCD_1_PrCString("F"); }else { MAXC=TEMPC; LCD_1_PrString(degC); LCD_1_Position(0,14); LCD_1_PrCString("C"); } for(;;){ Top: KeyRead=PRT1DR; //read for keypress while(ADCINC12_1_fIsDataAvailable() == 0); // Loop until value ready ADCINC12_1_ClearFlag(); // Clear ADC flag x=ADCINC12_1_iGetData(); // Get ADC result if (InputADC>=temperature) // Set up autostop and initial condition { DAC9_1_WriteBlind(0); //output 0V } if (stop==0) // loop for auto restart in start condition { if (CycleBuffer"); LCD_1_Position(1,10); LCD_1_PrString(lcd_Setting); // set key repeat function for up down keys only if (KeyRead!=0x00) //0x03 when programmer attached { count++; if (count>15) if (KeyRead==0x80||KeyRead==0x40) goto HERE; }else count=0; if (KeyBuffer==KeyRead) // duplicate key ignore goto Top; HERE: //Programmer will add 0X03 to all cases when attached switch (KeyRead){ case (0x80): // increment temperature if(count>15) {temperature=temperature+10; count=0; if (temperature >=MAXC) {goto HIGHlimit; } goto Top; } KeyBuffer=KeyRead; if (temperature >=MAXC) {goto HIGHlimit; } goto TempUp; break; case (0x40): // decrement temperature if(count>15) {temperature=temperature-10; count=0; if (temperature <=0) {goto LOWlimit; } goto Top; } KeyBuffer=KeyRead; if (temperature <=0) {goto LOWlimit; } goto TempDown; break; case (0x20): // clear KeyBuffer=KeyRead; goto Clear; break; case (0X10): //start KeyBuffer=KeyRead; goto Start; break; case (0x08): //stop KeyBuffer=KeyRead; goto Stop; break; case (0x04): //base change KeyBuffer=KeyRead; if (base==1) { //Change to F base=0; goto Base; } if (base==0) { //Change to C base=1; } goto Base; break; default: KeyBuffer=KeyRead; break; } } buffer=x; // ADC validation buffer goto Top; TempUp: temperature++; // increment setting goto Top; TempDown: temperature--; // decrement setting goto Top; Clear: temperature=0; count =0; LCD_1_Position(1,10); LCD_1_PrString(lcd_Setting); goto AboveTop; Stop: LCD_1_Control(LCD_1_DISP_CLEAR_HOME); LCD_1_Position(0,0); LCD_1_PrCString("STOPPED at"); LCD_1_PrString(lcd_Reading); DAC9_1_WriteBlind(0); stop=1; if (base==0) { MAXC=TEMPF; LCD_1_Position(0,15); LCD_1_PrCString("F"); }else { MAXC=TEMPC; LCD_1_Position(0,15); LCD_1_PrCString("C"); } goto Top; Start: LCD_1_Control(LCD_1_DISP_CLEAR_HOME); LCD_1_Position(0,0); LCD_1_PrCString("HEATING to "); LCD_1_PrString(lcd_Setting); if (InputADC<=temperature) { DAC9_1_WriteBlind(510); }else { DAC9_1_WriteBlind(0); } stop=0; if (base==0) { MAXC=TEMPF; LCD_1_Position(0,15); LCD_1_PrCString("F"); }else { MAXC=TEMPC; LCD_1_Position(0,15); LCD_1_PrCString("C"); } goto Top; LOWlimit: temperature=0; goto Top; HIGHlimit: temperature=MAXC; goto Top; Base: if (base==1)//Degrees F to Degrees C { if (temperature!=0) { temperature2=temperature; temperature=(5.0/9.0*(temperature2-32)); // convert F to C } goto BaseBottom; }else if (temperature!=0) { temperature2=temperature; temperature=(9.0/5.0*temperature2)+32; // convert C to F } BaseBottom: if (stop==0) { goto Top; }else goto AboveTop; } }