void Print_result () { if (print3_check==false) { LCD_clear_sec_line(); LCD_GotoXY(1,0); LCD_Send_A_String("result ="); LCD_display_number(result); } }
/* * function name:System_Initial() * description: Initialize the system. include I/O, LCD and ADS1118 and meat select. */ void System_Initial() { flag = 0; //reset flag flag ^= BIT8; // Default to farenheit Thr_state = 0; //threshold temperature setting state machine counter time_state = 0; //time setting state machine counter Thr_temp = 100; //configure threshold temperature to 100; Act_temp = 250; meatState = 0; //No meat selected yet customThreshold = 0; //Clear custom threshold flag // IO initial P1OUT = 0x09; P2OUT = 0x3F; LCD_init(); // LCD initial LCD_clear(); // LCD clear //Display startup message for 2 seconds LCD_display_string(0," THERMOMEATER "); int i; for (i = 0; i < 2; i++) { _delay_cycles(1000000); } LCD_clear(); //Output Temperature read screen labels LCD_display_string(0,"Des:"); LCD_display_time(0,8,time); // display current time LCD_display_string(1," Probe :"); //Initially reading probe LCD_display_char(1,13,0xDF); //Degrees symbol LCD_display_char(1,14,'F'); //Initially farenheit LCD_display_number(0,4,Thr_temp); // display threshold temp number ADS_Config(0); // set ADS1118 to convert local temperature, //and start convertion. }
/* * ======== 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(); } }
void half_second() { flag &= ~ BIT7; // judge actual temperature is higher than threshold temperature - Buzzer if((Act_temp >= (10*Thr_temp)) && (flag & BIT6)) { BUZZ_ON; } else if(time >0 && time <= 3) { BUZZ_ON; } else { BUZZ_OFF; } //display threshold temperature setting if(Thr_state == 0x01) //threshold temperature state machine output. { if (flag & BIT6) LCD_display_char(0,4,' '); //display blank space for half a second else LCD_display_number(0,4,set_temp);//display hundred place for half a second } else if(Thr_state == 0x02) { if (flag & BIT6) LCD_display_char(0,5,' '); //display blank space for half a second else LCD_display_number(0,4,set_temp);//display decade for half a second } else if(Thr_state == 0x03) { if (flag & BIT6) LCD_display_char(0,6,' '); //display blank space for half a second else LCD_display_number(0,4,set_temp);//display unit's digit for half a second } // display time setting if(time_state == 0x01) { if (flag & BIT6) LCD_display_char(0,11,' '); //display blank space for half a second else LCD_display_time(0,8,set_time);//display hundred place for half a second } else if(time_state == 0x02) { if (flag & BIT6) LCD_display_char(0,12,' '); //display blank space for half a second else LCD_display_time(0,8,set_time);//display hundred place for half a second } else if(time_state == 0x03) { if (flag & BIT6) LCD_display_char(0,14,' '); //display blank space for half a second else LCD_display_time(0,8,set_time);//display hundred place for half a second } else if(time_state == 0x04) { if (flag & BIT6) LCD_display_char(0,15,' '); //display blank space for half a second else LCD_display_time(0,8,set_time);//display hundred place for half a second } }
void STM_refresh(void) { if(state_is_new) { execute_state_entry(AppState); } switch(AppState) { case READY_STATE: if (if_valve_open()) { STM_set_state(DRINKING_STATE); } break; case DRINKING_STATE: if (ADC_get_result() < ADC_LOW_SWITCH_VALUE) { STM_set_state(VERIFICATION_STATE); } if (If0_01secPassed) { LCD_display_time(get_current_time()); } break; case VERIFICATION_STATE: if(If0_01secPassed) { verification_state_duration ++; } if(ADC_get_result() > ADC_LOW_SWITCH_VALUE) { AppState = DRINKING_STATE; // don't execute drinking_state entry! } if(verification_state_duration >= VERIFICATION_LENGTH) { STM_set_state(DISPLAY_STATE); } break; case DISPLAY_STATE: if (If0_01secPassed) { led_flashing_duration ++; if (led_flashing_duration >= LED_BLINK_LENGTH) { led_off(); } } // poll the ADC (wait for the beer) if ((ADC_get_result() > ADC_HIGH_SWITCH_VALUE) && ! if_valve_open()) { STM_set_state(READY_STATE); } break; case ADC_STATE: // ADC_STATE NORMAL OPERATION if (If0_01secPassed) { LCD_carriage_return(); LCD_putsub(" "); LCD_carriage_return(); LCD_display_number((uint16_t)ADC_get_result()); } break; } clear_flags(); }