Example #1
0
/**
  * @brief Validation firmware main entry point.
  * @par Parameters:
  * None
  * @retval 
  * None
  */
void main(void)
{
    int ButtonIndex =0;
    u8 i =0;
    u8 LedState =1;
    u8 pos =0;
    u8 s[16];

    /* Initialize I/Os in Output Mode for LEDs */
    GPIO_Init(LEDS_PORT, LED1_PIN | LED2_PIN | LED3_PIN | LED4_PIN,GPIO_MODE_OUT_PP_LOW_FAST);

    /* Initialization of I/O in Input Mode with Interrupt for Key button */
    GPIO_Init(BUTTON_PORT, BUTTON_PIN, GPIO_MODE_IN_FL_IT);

    /* Initialization of the Interrupt sensitivity */
    EXTI_SetExtIntSensitivity(EXTI_PORT_GPIOC, EXTI_SENSITIVITY_FALL_ONLY);

    /* Enable general interrupts for Key button reading */
    enableInterrupts();

    /* Initialize SPI */
    SPI_DeInit();
    SPI_Init(SPI_FIRSTBIT_MSB, SPI_BAUDRATEPRESCALER_128, SPI_MODE_MASTER,
             SPI_CLOCKPOLARITY_HIGH, SPI_CLOCKPHASE_2EDGE, SPI_DATADIRECTION_1LINE_TX,
             SPI_NSS_SOFT, 0x07);
    SPI_Cmd(ENABLE);

    /* Initialize LCD */
    LCD_Init();

    /* Clear LCD lines */
    LCD_Clear();

    /* Display "moving" ST logo on first line */
    for (pos = 0x80; pos < 0x88; pos++)
    {
        LCD_Clear();
        LCD_DisplayLogo(pos);
        Delay(20000);
    }

    /* Display "moving" ST logo on second line */
    for (pos = 0x90; pos < 0x98; pos++)
    {
        LCD_Clear();
        LCD_DisplayLogo(pos);
        Delay(20000);
    }

    LCD_Clear();

    /* More than 15 characters: the message is displayed on 2 lines */
    /* LCD_PrintMsg("STM8S - SPI/LCD example"); */

    /* Max 15 characters per line */
    LCD_PrintString(LCD_LINE1, ENABLE, DISABLE, " *** STM8S *** ");
    LCD_PrintString(LCD_LINE2, ENABLE, DISABLE, "SPI-LCD example");

    for (i = 0; i < 10; i++)
    {
        Delay(0xFFFF);
    }

    LCD_Clear();

    LCD_PrintString(LCD_LINE1, ENABLE, DISABLE, "Press KEY...");

    while (1)
    {
        /* Check button status */
        if (GetVar_ButtonPressed() == TRUE) /* Button is pressed */
        {
            ButtonPressed = FALSE;
            LCD_ClearLine(LCD_LINE2);
            LCD_PrintString(LCD_LINE2, DISABLE, DISABLE, "LED #");
						
           /*Use the  sprintf() and LCD_Print() function to print a digit on the LCD */
 					 if (LedState == 0)
            {
                sprintf(s,"%d ", ButtonIndex + 1);
                LCD_Print(s);
								LCD_SetCursorPos(LCD_LINE2, 4); /* 8th position */
                LCD_PrintChar('O');
                LCD_PrintChar('F');
                LCD_PrintChar('F');
            }
						/*Use the LCD_PrintDec1() function to print a digit on the LCD */
            else
            {
                LCD_PrintDec1((u8)(ButtonIndex + 1)); /* Display at current cursor position */
                LCD_SetCursorPos(LCD_LINE2, 4); /* 8th position */ 
								LCD_PrintChar('O');
                LCD_PrintChar('N');
                LCD_PrintChar(' ');
            }
             switch (ButtonIndex)
            {
            case 0:
                GPIO_WriteReverse(LEDS_PORT, LED1_PIN);
                ButtonIndex++;
                break;
            case 1:
                GPIO_WriteReverse(LEDS_PORT, LED2_PIN);
                ButtonIndex++;
                break;
            case 2:
                GPIO_WriteReverse(LEDS_PORT, LED3_PIN);
                ButtonIndex++;
                break;
            default:
            case 3:
                GPIO_WriteReverse(LEDS_PORT, LED4_PIN);
                ButtonIndex = 0;
                LedState ^= 0x01;
                break;
            }
        }
    }

}
Example #2
0
/*!
 *******************************************************************************
 * main program
 ******************************************************************************/
int main(void)
{
    bool last_state_mnt;        //!< motor mounted
    bool state_mnt;             //!< motor mounted
    bool err;                   //!< error
    bool ref_pos_changed;       //!< ref Position changed

    uint8_t last_statekey;      //!< state of keys on last loop
    uint8_t last_second;        //!< RTC-second of last main cycle
    uint8_t ref_position;       //!< desired position in percent
    motor_speed_t speed;        //!< motor speed (fast or quiet)
    uint8_t display_mode;       //!< desired display output
    uint16_t value16;           //!< 16 Bit value
    int16_t value16s;           //!< signed 16 Bit value
    uint8_t value8;             //!<  8 Bit value

    //! initalization
    init();

    //! load/set default values
    load_defauls();
    
    //! Enable interrupts
    sei();

    //! show POST Screen
    LCD_AllSegments(LCD_MODE_ON);                   // all segments on
    delay(1000);
    LCD_AllSegments(LCD_MODE_OFF);        
    LCD_PrintDec(REVHIGH, 1, LCD_MODE_ON);          // print version
    LCD_PrintDec(REVLOW, 0, LCD_MODE_ON);
    LCD_Update();
    delay(1000);
    LCD_AllSegments(LCD_MODE_OFF);                  // all off

    //! \todo Send Wakeup MSG

    state_mnt=false;
    ref_pos_changed=true;
    last_second=99;
    speed=full;
    last_statekey = 0;
    last_state_mnt = false;
    m_key_action = true;
    ref_position = 10;
    display_mode=3;

    ISR(PCINT1_vect);                  // get keystate

		// We should do the following once here to have valid data from the start
    ADC_Measure_Ub();
		ADC_Measure_Temp();

		
    /*!
    ****************************************************************************
    * main loop
    *
    * 1) process keypresses
    *    - m_state_keys and m_wheel are set from IRQ, only process them
    *    - you can set m_wheel to a new value
    *    - controll content of LCD
    * 2) \todo calc new valveposition if new temp available
    *    - temp is measured by IRQ
    * 3) calibrate motor
    *    - start calibration is valve mounted changed to on
    *      (during calibration the main loop stops at least for 10 seconds)
    *    - reset calibration is valve mounted changed to off
    * 4) start motor if
    *    - actual valveposition != desired valveposition && motor is off
    * 5) if motor is on call MOTOR_CheckBlocked at least once a second
    *    - that switches motor of if it is blocked
    * 6) store keystate at end of loop before going to sleep
    * 7) Check for serial command to process
    * 8) \todo goto sleep if
    *    - motor is of
    *    - no key is pressed (AUTO, C, PROG)
    *    - no serial communication active
    ***************************************************************************/
    for (;;){        // change displaystate every 10 seconds 0 to 5
        // Activate Auto Mode
        // setautomode(true);

        // 1) process keypresses
        if (m_key_action){
            m_key_action = false;
            state_mnt = !(m_state_keys & KEYMASK_MOUNT);

            // State of keys AUTO, C and PROG and valve mounted
            if ((m_state_keys & KEYMASK_AUTO) != 0){
                display_mode--;
                LCD_SetHourBarVal(display_mode, LCD_MODE_ON);
                ref_pos_changed = true;
                LCD_SetSeg(LCD_SEG_AUTO, LCD_MODE_ON);
            } else {
                LCD_SetSeg(LCD_SEG_AUTO, LCD_MODE_OFF);
            }
            if ((m_state_keys & KEYMASK_C) != 0){
                if (display_mode==9){
                      m_reftemp = input_temp(m_reftemp);                      
                }                 
                //LCD_SetHourBarVal(display_mode, LCD_MODE_ON);                
                //ref_pos_changed = true;
                //LCD_SetSeg(LCD_SEG_MANU, LCD_MODE_ON);
            } else {
                LCD_SetSeg(LCD_SEG_MANU, LCD_MODE_OFF);
            }
            if ((m_state_keys & KEYMASK_PROG)!= 0){
                display_mode++;
                LCD_SetHourBarVal(display_mode+1, LCD_MODE_ON);
                ref_pos_changed = true;
                LCD_SetSeg(LCD_SEG_PROG, LCD_MODE_ON);
            } else {
                LCD_SetSeg(LCD_SEG_PROG, LCD_MODE_OFF);
            }
        }

        // 2) calc new valveposition if new temp available
        //    - temp is measured by IRQ


        // 3) calibrate motor
        //    - start calibration if valve is now mounted
        //      TODO:
        //      (during calibration the main loop stops for a long time
        //       maybe add global var to cancel callibration, e.g.: if
        //       HR20 removed from ther gear)
        //    - reset calibration is valve mounted changed to off
        if (last_state_mnt != state_mnt) {
            MOTOR_SetMountStatus(state_mnt);
            if (state_mnt) {
                LCD_ClearNumbers();
                LCD_PrintChar(LCD_CHAR_C, 3, LCD_MODE_ON);
                LCD_PrintChar(LCD_CHAR_A, 2, LCD_MODE_ON);
                LCD_PrintChar(LCD_CHAR_L, 1, LCD_MODE_ON);
                LCD_Update();
                // DEBUG: if next line is disabled, not calibration and no
                //        motor control is done
                // MOTOR_Calibrate(ref_position, speed);
                LCD_ClearNumbers();
            } 
        }

        // 4) start motor if
        //    - actual valveposition != desired valveposition
        //    - motor is off
        //    - motor is calibrated
        if ((ref_pos_changed) && (MOTOR_IsCalibrated())){
            err = MOTOR_Goto(ref_position, speed);
            ref_pos_changed = false;
        }

        // 5) if motor is on call MOTOR_CheckBlocked at least once a second
        //    - that switches motor of if it is blocked
        if (MOTOR_On()){
            if (last_second != RTC_GetSecond()){
                MOTOR_CheckBlocked();
                last_second = RTC_GetSecond();
            }
        }
        
        
        // 6) store keystate at end of loop before going to sleep
        last_statekey = m_state_keys;
        last_state_mnt = state_mnt;
	
        
        // 7) Check if there is a serial command to process
        //    Loop until all is processed
				e_meassure();	// test call to sample values and send them to serial port
	
        while( (COM_Process() == true) ){};

        // 8) goto sleep if
        //    - motor is of
        //    - no key is pressed (AUTO, C, PROG)
        //    - no serial communication active
                
        
        if (display_mode==1) {
            // Ub: ADC Value Hex 
            ADC_Measure_Ub();
            value16 = ADC_Get_Bat_Val();
            LCD_PrintHexW(value16, LCD_MODE_ON);
        }else if (display_mode==2) {
            // Ub: ADC Value Decimal 
            ADC_Measure_Ub();
            value16 = ADC_Get_Bat_Val();
            LCD_PrintDecW(value16, LCD_MODE_ON);
        }else if (display_mode==3) {
            // Ub: Voltage [mV]
            ADC_Measure_Ub();            
            value16 = ADC_Get_Bat_Voltage();
            LCD_PrintDecW(value16, LCD_MODE_ON);
        }else if (display_mode==4) {
            // Temp: ADC Value Hex
            ADC_Measure_Temp();
            value16 = ADC_Get_Temp_Val();
            LCD_PrintHexW(value16, LCD_MODE_ON);
        }else if (display_mode==5) {
            // Temp: ADC Value Decimal
            ADC_Measure_Temp();
            value16 = ADC_Get_Temp_Val();
            LCD_PrintDecW(value16, LCD_MODE_ON);            
        }else if (display_mode==6) {
            // Temp: Temperature (Degree)
            ADC_Measure_Temp();
            value16s = ADC_Get_Temp_Degree();
            LCD_PrintTempInt(value16s, LCD_MODE_ON);
        }else if (display_mode==7) {
            // - 9,87 °C            
            value16s = -987;
            LCD_PrintTempInt(value16s, LCD_MODE_ON);
        }else if (display_mode==8) {
            // 98,76 °C            
            value16s = 9876;
            LCD_PrintTempInt(value16s, LCD_MODE_ON);
        }else{
            value16 = display_mode;                      
            LCD_PrintDecW(value16, LCD_MODE_ON);
        }           
        /*
        // Bar 24 on if calibrated
        if (MOTOR_IsCalibrated()) {
            LCD_SetSeg(LCD_SEG_BAR24, LCD_MODE_ON);
        } else {
            LCD_SetSeg(LCD_SEG_BAR24, LCD_MODE_OFF);
        }

        // Hour 0 on if state_mnt
        if (state_mnt) {
            LCD_SetSeg(LCD_SEG_B0, LCD_MODE_ON);
        } else {
            LCD_SetSeg(LCD_SEG_B0, LCD_MODE_OFF);
        }
        
        // Hour 1 on if last_state_mnt
        if (last_state_mnt) {
            LCD_SetSeg(LCD_SEG_B1, LCD_MODE_ON);
        } else {
            LCD_SetSeg(LCD_SEG_B1, LCD_MODE_OFF);
        }

        
        if (!MOTOR_IsCalibrated()) {
            LCD_PrintChar(LCD_CHAR_E, 3, LCD_MODE_ON);
            LCD_PrintChar(LCD_CHAR_2, 2, LCD_MODE_ON);
        } else {
            LCD_PrintDec(ref_position,  1, LCD_MODE_ON);
            LCD_PrintDec(MOTOR_GetPosPercent(),  0, LCD_MODE_ON);
        }
        */
        
        // impulses = MOTOR_GetImpulses();

        // update Display each main loop
        LCD_Update();
    } //End Main loop
    return 0;
}
Example #3
0
/*!
 *******************************************************************************
 * \brief menu View
 ******************************************************************************/
void menu_view(bool clear) {
  switch (menu_state) {
    case menu_startup:
        LCD_AllSegments(LCD_MODE_ON);                   // all segments on
        break;
    case menu_version:
        clr_show1(LCD_SEG_COL1);
        LCD_PrintHexW(VERSION_N,LCD_MODE_ON);
        break; 
#if (! REMOTE_SETTING_ONLY)
	case menu_set_year:
        LCD_AllSegments(LCD_MODE_OFF); // all segments off
        LCD_PrintDecW(RTC_GetYearYYYY(),LCD_MODE_BLINK_1);
       break;
    case menu_set_month:
    case menu_set_day:
        clr_show1(LCD_SEG_COL1);           // decimal point
        LCD_PrintDec(RTC_GetMonth(), 0, ((menu_state==menu_set_month)?LCD_MODE_BLINK_1:LCD_MODE_ON));
        LCD_PrintDec(RTC_GetDay(), 2, ((menu_state==menu_set_day)?LCD_MODE_BLINK_1:LCD_MODE_ON));
       break;
    case menu_set_hour:
    case menu_set_minute: 
    case menu_home4: // time
#if HAVE_NEWLCD
        if (clear) clr_show1(LCD_SEG_COL2);
#else
        if (clear) clr_show2(LCD_SEG_COL1,LCD_SEG_COL2);
#endif
        LCD_PrintDec(RTC_GetHour(), 2, ((menu_state == menu_set_hour) ? LCD_MODE_BLINK_1 : LCD_MODE_ON));
        LCD_PrintDec(RTC_GetMinute(), 0, ((menu_state == menu_set_minute) ? LCD_MODE_BLINK_1 : LCD_MODE_ON));
       break;                                       
#else
    case menu_home4: // time
#if HAVE_NEWLCD
        if (clear) clr_show1(LCD_SEG_COL2);
#else
        if (clear) clr_show2(LCD_SEG_COL1,LCD_SEG_COL2);
#endif
        LCD_PrintDec(RTC_GetHour(), 2,  LCD_MODE_ON);
        LCD_PrintDec(RTC_GetMinute(), 0, LCD_MODE_ON);
       break;                                       
#endif
#if MENU_SHOW_BATTERY
	case menu_home5:        // battery 
		LCD_AllSegments(LCD_MODE_OFF);
        LCD_PrintDec(bat_average/100, 2, LCD_MODE_ON);
        LCD_PrintDec(bat_average%100, 0, LCD_MODE_ON);
       break;        
#endif                                                       
		

    case menu_home: // wanted temp / error code / adaptation status
        if (MOTOR_calibration_step>0) {
            clr_show1(LCD_SEG_BAR24);
            LCD_PrintChar(LCD_CHAR_A,3,LCD_MODE_ON);
            if (MOTOR_ManuCalibration==-1) LCD_PrintChar(LCD_CHAR_d,2,LCD_MODE_ON);
            LCD_PrintChar(LCD_CHAR_0 + (MOTOR_calibration_step%10), 0, LCD_MODE_ON);
            goto MENU_COMMON_STATUS; // optimization
        } else {
            if (clear) clr_show1(LCD_SEG_BAR24);
            if (CTL_error!=0) {
#if HAVE_NEWLCD==0
                if (CTL_error & CTL_ERR_BATT_LOW) {
                    LCD_PrintStringID(LCD_STRING_BAtt,LCD_MODE_BLINK_1);
                } else
#endif
								if (CTL_error & CTL_ERR_MONTAGE) {
                    LCD_PrintStringID(LCD_STRING_E2,LCD_MODE_ON);
                } else if (CTL_error & CTL_ERR_MOTOR) {
                    LCD_PrintStringID(LCD_STRING_E3,LCD_MODE_ON);
                } else
#if HAVE_NEWLCD==0
								if (CTL_error & CTL_ERR_BATT_WARNING) {
                    LCD_PrintStringID(LCD_STRING_BAtt,LCD_MODE_ON);
                } else
#endif
								if (CTL_error & CTL_ERR_RFM_SYNC) {
                    LCD_PrintStringID(LCD_STRING_E4,LCD_MODE_ON);
                }
                goto MENU_COMMON_STATUS; // optimization
            } else {
                if (mode_window()) {
                    LCD_PrintStringID(LCD_STRING_OPEn,LCD_MODE_ON);
                    goto MENU_COMMON_STATUS; // optimization
                }
            }
        } 
        // do not use break at this position / optimization
    case menu_home_no_alter: // wanted temp
        if (clear) clr_show1(LCD_SEG_BAR24);
        LCD_PrintTemp(CTL_temp_wanted,LCD_MODE_ON);
        //! \note hourbar status calculation is complex we don't want calculate it every view, use chache
        MENU_COMMON_STATUS:
        LCD_SetSeg(LCD_SEG_AUTO, (CTL_test_auto()?LCD_MODE_ON:LCD_MODE_OFF));
        LCD_SetSeg(LCD_SEG_MANU, (CTL_mode_auto?LCD_MODE_OFF:LCD_MODE_ON));
#if HAVE_NEWLCD
				if (CTL_error & (CTL_ERR_BATT_LOW | CTL_ERR_BATT_WARNING))
					LCD_SetSeg(LCD_SEG_BAT, (CTL_error & CTL_ERR_BATT_LOW)?LCD_MODE_BLINK_1:LCD_MODE_ON);
#endif
        LCD_HourBarBitmap(hourbar_buff);
       break;
    case menu_home2: // real temperature
        if (clear) LCD_AllSegments(LCD_MODE_OFF);
        LCD_PrintTempInt(temp_average,LCD_MODE_ON);
        break;
    case menu_home3: // valve pos
        if (clear) LCD_AllSegments(LCD_MODE_OFF);
        // LCD_PrintDec3(MOTOR_GetPosPercent(), 1 ,LCD_MODE_ON);
        // LCD_PrintChar(LCD_CHAR_2lines,0,LCD_MODE_ON);
        {
            uint8_t prc = MOTOR_GetPosPercent();
            if (prc<=100) {
                LCD_PrintDec3(MOTOR_GetPosPercent(), 0 ,LCD_MODE_ON);
            } else {
                LCD_PrintStringID(LCD_STRING_minusCminus,LCD_MODE_ON);
            }
        }
        break;
#if (! REMOTE_SETTING_ONLY)
    case menu_set_timmer_dow:
        clr_show1(LCD_SEG_PROG); // all segments off
        LCD_PrintDayOfWeek(menu_set_dow, LCD_MODE_BLINK_1);
        break;
    case menu_set_timmer:
        //! \todo calculate "hourbar" status, actual position in mode LCD_MODE_BLINK_1
        
//        clr_show3(LCD_SEG_COL1,LCD_SEG_COL2,LCD_SEG_PROG);
        clr_show2(LCD_SEG_COL1,LCD_SEG_COL2);
        timmers_patch_offset=timers_get_raw_index(menu_set_dow, menu_set_slot);
        timmers_patch_data = menu_set_time +  ((uint16_t)menu_set_mode<<12);
        LCD_HourBarBitmap(RTC_DowTimerGetHourBar(menu_set_dow));
        timmers_patch_offset=0xff;
        LCD_SetHourBarSeg(menu_set_time/60, LCD_MODE_BLINK_1);
        if (menu_set_time < 24*60) {
            LCD_PrintDec(menu_set_time/60, 2, LCD_MODE_BLINK_1);
            LCD_PrintDec(menu_set_time%60, 0, LCD_MODE_BLINK_1);        
        } else {
            LCD_PrintStringID(LCD_STRING_4xminus,LCD_MODE_BLINK_1);
        }
        show_selected_temperature_type(menu_set_mode,LCD_MODE_BLINK_1);
        break;                                                             
#endif
    case menu_lock:        // "bloc" message
        LCD_AllSegments(LCD_MODE_OFF); // all segments off
        LCD_PrintStringID(LCD_STRING_bloc,LCD_MODE_ON);
        break;
    case menu_service1: 
    case menu_service2:
        // service menu; left side index, right value
        LCD_AllSegments(LCD_MODE_ON);
        LCD_PrintHex(service_idx, 2, ((menu_state == menu_service1) ? LCD_MODE_BLINK_1 : LCD_MODE_ON));
        LCD_PrintHex(config_raw[service_idx], 0, ((menu_state == menu_service2) ? LCD_MODE_BLINK_1 : LCD_MODE_ON));
       break;
    case menu_service_watch:
        LCD_AllSegments(LCD_MODE_ON);
        LCD_PrintHexW(watch(service_watch_n),LCD_MODE_ON);
        LCD_SetHourBarSeg(service_watch_n, LCD_MODE_BLINK_1);
        break;
#if (! REMOTE_SETTING_ONLY)
    case menu_preset_temp0:
    case menu_preset_temp1:
    case menu_preset_temp2:
    case menu_preset_temp3:
        LCD_AllSegments(LCD_MODE_OFF);
        LCD_PrintTemp(menu_set_temp,LCD_MODE_BLINK_1);
        show_selected_temperature_type(menu_state-menu_preset_temp0,LCD_MODE_ON);
#endif
    default:
        break;                   
    }
    
    LCD_Update();
}
void PrintTime(double dat, unsigned char precision, unsigned char EditChevron) {
    char Hours, Minutes, Seconds;
    int Milliseconds;

    ConvertTimeToDiscrete(dat, &Hours, &Minutes, &Seconds, &Milliseconds);

    //Change Milliseconds to 10ths of a second.
    Milliseconds /= 100;

    //Time provided in the dat variable which is in milliseconds...
    if (precision & 0b1000) {
        if (EditChevron & 0b1000) LCD_PrintChar('<');
        LCD_PrintLong((int) Hours, 2, 0);
        if (EditChevron & 0b1000) LCD_PrintChar('>');
    }

    if (precision & 0b0100) {
        if (precision & 0b00001000) LCD_PrintChar(':');
        if (EditChevron & 0b0100) LCD_PrintChar('<');
        LCD_PrintLong((int) Minutes, 2, 0);
        if (EditChevron & 0b0100) LCD_PrintChar('>');
    }

    if (precision & 0b0010) {
        if (precision & 0b00000100) LCD_PrintChar(':');
        if (EditChevron & 0b0010) LCD_PrintChar('<');
        LCD_PrintLong((int) Seconds, 2, 0);
        if (EditChevron & 0b0010) LCD_PrintChar('>');
    }

    if (precision & 0b0001) {
        if (precision & 0b00000010) LCD_PrintChar('.');
        if (EditChevron & 0b0001) LCD_PrintChar('<');
        LCD_PrintLong((int) Milliseconds, 1, 0);
        if (EditChevron & 0b0001) LCD_PrintChar('>');
    }
}
Example #5
0
void LCD_PrintLong(long dat, char places, char sign) {
    long temp;

    if (dat < 0) {
        LCD_PrintChar('-');
        dat = 0 - dat;
    } else {
        if (sign) LCD_PrintChar('+');
    }

    temp = dat / 1000000000;
    dat -= temp * 1000000000;
    temp += 48;
    if (places > 9) LCD_PrintChar(temp);

    temp = dat / 100000000;
    dat -= temp * 100000000;
    temp += 48;
    if (places > 8) LCD_PrintChar(temp);

    temp = dat / 10000000;
    dat -= temp * 10000000;
    temp += 48;
    if (places > 7) LCD_PrintChar(temp);

    temp = dat / 1000000;
    dat -= temp * 1000000;
    temp += 48;
    if (places > 6) LCD_PrintChar(temp);

    temp = dat / 100000;
    dat -= temp * 100000;
    temp += 48;
    if (places > 5) LCD_PrintChar(temp);

    temp = dat / 10000;
    dat -= temp * 10000;
    temp += 48;
    if (places > 4) LCD_PrintChar(temp);

    temp = dat / 1000;
    dat -= temp * 1000;
    temp += 48;
    if (places > 3) LCD_PrintChar(temp);

    temp = dat / 100;
    dat -= temp * 100;
    temp += 48;
    if (places > 2) LCD_PrintChar(temp);

    temp = dat / 10;
    dat -= temp * 10;
    temp += 48;
    if (places > 1) LCD_PrintChar(temp);

    temp = dat;
    temp += 48;
    LCD_PrintChar(temp);
}
Example #6
0
//collection of ADC data and also real precise values from external voltmeter
//external data is entered with joystick movement as 0.000 number
static unsigned int ADCCollectDataCalib(unsigned int * ADCBuffer, double * ADCRealValues)
{
  unsigned int i;
  unsigned int multiplier;
  signed int Voltage;
  unsigned char cursorPos;
  unsigned char ArrowChar = '^';
  unsigned char JoyUp,JoyDown,JoyLeft,JoyRight,JoySel;

  //disable ADC interrupts
  ADC2_ITConfig(DISABLE);
  //enable ADC
  ADC2_Init(ADC2_CONVERSIONMODE_SINGLE, ADC2_CHANNEL_12, ADC2_PRESSEL_FCPU_D6, ADC2_EXTTRIG_TIM, DISABLE, ADC2_ALIGN_RIGHT, ADC2_SCHMITTTRIG_CHANNEL12, DISABLE);
  //clear end of conversion bit
  ADC2_ClearFlag();

  //for joystick control (init)
  //pull-ups on on all used buttons
  GPIOB->CR1 |= 0xF0;
  GPIOD->CR1 |= 0x80;
  Voltage = 0;
  multiplier = 1000;
  cursorPos = 2;
  //print values on LCD display
  LCD_Clear();
  LCD_SetCursorPos(LCD_LINE1, 1);
  LCD_PrintDec4(Voltage);
  LCD_PrintString(LCD_LINE1, DISABLE, ENABLE, "  =Real U");
  LCD_SetCursorPos(LCD_LINE2, cursorPos/2);
  LCD_PrintChar(ArrowChar); 
  
  //set external voltage - measure it with external voltmeter - enter voltmeter
  //value into LCD - measure ADC data - store real and ADC data to buffers
  //finish data collecting by KEY button on PCB board
  for(i=0; i<ADC_BUFFER_SIZE; i++)
  {
    LCD_SetCursorPos(LCD_LINE2, 0);
    LCD_PrintDec2(i);
    while(JOY_SEL);
    while(!JOY_SEL)
    {
      if(BUTTON_LOW)
        break;
      JoyUp   = JOY_UP;
      JoyDown = JOY_DOWN;
      JoyLeft = JOY_LEFT;
      JoyRight= JOY_RIGHT;
      JoySel  = JOY_SEL;
      if(JoyLeft)//increase multiplier
      {
        if (cursorPos!=2) 
        {
          multiplier *= 10;
          cursorPos  -= 1;
        }        
      }
      if(JoyRight)//decrease multiplier
      {
        if (cursorPos!=5) 
        {
          multiplier /= 10;
          cursorPos  += 1;
        }
      }
      if(JoyRight || JoyLeft)//repaint cursor position
      {
        LCD_PrintString(LCD_LINE2, DISABLE, DISABLE, "      ");//clear cursor
        LCD_SetCursorPos(LCD_LINE2, cursorPos/2);//set cursor position
        if(cursorPos & 1)
          LCD_PrintChar(' ');//print space
        LCD_PrintChar(ArrowChar);//print cursor
        while (JOY_RIGHT || JOY_LEFT);
        delay(1000l);
      }
      if(JoyUp)//increase real value
      {
        Voltage += multiplier;
      }
      if(JoyDown)//decrease real value
      {
        Voltage -= multiplier;
      }
      if(JoyUp || JoyDown)//repaint real value
      {
        LCD_PrintString(LCD_LINE1, DISABLE, DISABLE, "      ");//clear voltage
        if (Voltage<0)
        {
          LCD_SetCursorPos(LCD_LINE1, 1);
          LCD_PrintDec4(-Voltage);
          LCD_SetCursorPos(LCD_LINE1, 0);
          LCD_PrintChar('-');//print sign
        }
        else
        {
          LCD_SetCursorPos(LCD_LINE1, 1);
          LCD_PrintDec4(Voltage);
          LCD_SetCursorPos(LCD_LINE1, 0);
          LCD_PrintChar('+');//print sign
        }
        while (JOY_UP || JOY_DOWN);
        delay(1000l);
      }
      
      //start single conversion
      ADC2_StartConversion();
      while (!ADC2_GetFlagStatus());
      //clear end of conversion bit
      ADC2_ClearFlag();
      //collect ADC value and display it
      LCD_SetCursorPos(LCD_LINE2, 5);//set cursor position
      LCD_PrintDec4(ADC2_GetConversionValue());
    }
    
    //stop collecting if KEY buttom pressed
    if(BUTTON_LOW)
    {
      break;
    }
    //otherwise collect ADC data (+ real data) and store them
    else
    {
      //start single conversion
      ADC2_StartConversion();
      while (!ADC2_GetFlagStatus());
      //clear end of conversion bit
      ADC2_ClearFlag();
      //collect ADC value
      ADCBuffer[i] = ADC2_GetConversionValue();
      //collect real value
      ADCRealValues[i] = (double)Voltage/1000;
    }
  }
  return i;
}//ADCCollectDataCalib
Example #7
0
int main(void) {
	init();

	uart_init();
	MSG("INIT");
//	cli();

	LCD_init();

	LCD_contrast(0xff);

	LCD_PrintStr(STR_HELLO);

	LCD_GotoXY(1, 1);

	//LCD_PrintStr(STR_WORLD);
	//LCD_PrintInt((uint8_t)'А');
	// en  A - 65 => 65+128 = 193
	// rus A - 144
//	LCD_PrintInt(a);
//
//	LCD_PrintChar(' ');
	for (uint8_t i = 0; i < 16;i++) {
		LCD_PrintChar(40+i);
	}

	uint8_t i = 0;
	while (true) {
		keyboardCheck();
		bool update = false;
		if (key_click_flag[KEY_UP]) {
			if (i < 2) {
				i++;
				update = true;
			}
		}
		if (key_click_flag[KEY_DOWN]) {
			if (i != 0) {
				i--;
				update = true;
			}
		}
		if (update) {
			LCD_Clear();
			switch(i) {
				case 0:
					LCD_PrintStr(STR_START);
					break;
				case 1:
					LCD_PrintStr(STR_PROFILE);
					break;
				case 2:
					LCD_PrintStr(STR_SETTINGS);
					break;
			}
			LCD_GotoXY(0, 1);
			LCD_PrintInt(i);
			_delay_ms(500);
		}

//		LCD_GotoXY(0, 1);
//		LCD_PrintInt(key_counter[KEY_UP]);
//		LCD_PrintChar(' ');
//		LCD_PrintInt(key_counter[KEY_DOWN]);
//		LCD_PrintChar(' ');
//		LCD_PrintInt(key_click_flag[KEY_UP]);
		_delay_us(1000);
	}
}
Example #8
0
/*
 * You can use printCharLCD here. Note that every time you write a character
 * the cursor increments its position automatically.
 * Since a string is just a character array, try to be clever with your use of pointers.
 */
void LCD_PrintString(const char* s) {
  int x = 0;
  for(x = 0;x<strlen(s);x++)LCD_PrintChar(s[x]);
}