Example #1
0
void LCD_Initialization()
{
	output_low(LCD_CE);
	output_low(LCD_RS);
	output_low(LCD_RW);

	output_d(0);
	output_d(0x38);

	output_high(LCD_CE);
	Nop();
	Nop();
	output_low(LCD_CE);

	delay_ms(20);

	output_d(0x38);

	output_high(LCD_CE);
	Nop();
	Nop();
	output_low(LCD_CE);

	delay_ms(5);

	LCD_Cmd(DISPLAY_ON);		// display on, curse off, blink off
	LCD_Cmd(0x01);				// display on, curse off, blink off
	LCD_Cmd(0x06);				// LCD clear, curse home
	LCD_Cmd(0x80);				// initial DDRAM address
	LCD_Cmd(0x01);				// LCD clear,curse home
}
Example #2
0
// コントラスト設定
void LCD_SetContrast(uint8 contrast)
{
    LCD_Cmd(0b00111001);	// function set
    LCD_Cmd(0b01110000 | (contrast & 0xF));	// contrast Low
    LCD_Cmd(0b01011100 | ((contrast >> 4) & 0x3)); // contast High/icon/power 
	LCD_Cmd(0b00111000); // function set
    
}
Example #3
0
// ***************************************************************************************************************************************************************
void InitCustomChars()
{
  uint8_t i;
  LCD_Cmd(0x04);                        // Set CGRAM Address (in LCD))
  LCD_Cmd(0x00);                        // Set Starting Point in CGRAM Address (I think?))
  for (i = 0; i < sizeof(__cgram) ; i++)
    LCD_Write_Char(__cgram[i]);
  LCD_Cmd(0);                           // Return to Home
  LCD_Cmd(2);                           // .. return to Home
}
Example #4
0
bool LCD_Init ( LCD display ) {

    lcd = display;

    /*
     * TODO:
     * The function should clear only the appropriate bits, not the whole PORT
     */
    if ( lcd.PORT == &PORTA ) {
        TRISA = 0x00;
    }
    else if ( lcd.PORT == &PORTB ) {
        TRISB = 0x00;
    }
    else if ( lcd.PORT == &PORTC ) {
        TRISC = 0x00;
    }
    #if defined(_16F877) || defined(_16F877A)
    else if ( lcd.PORT == &PORTD ) {
        TRISD = 0x00;
    }
    else if ( lcd.PORT == &PORTE ) {
        TRISE = 0x00;
    }
    #endif
    else {
        return false;
    }

    // Give some time to the LCD to start function properly
    __delay_ms(20);

    // Send reset signal to the LCD
    LCD_Write(0x03);
    __delay_ms(5);
    LCD_Write(0x03);
    __delay_ms(16);
    LCD_Write(0x03);

    // Specify the data lenght to 4 bits
    LCD_Write(0x02);

    // Set interface data length to 8 bits, number of display lines to 2 and font to 5x8 dots
    LCD_Cmd(0x28);

    // Set cursor to move from left to right
    LCD_Cmd(0x06);

    LCD_Display(true, false, false); // Turn on display and set cursor off

    LCD_Clear();
    
    return true;
}
Example #5
0
// ***************************************************************************************************************************************************************
void LCD_Set_Cursor(char x, char y)
{
#ifdef LCD_TYPE_2_LINE

    char temp,z,w;
    
	if(x == 0)
	{                
        temp = 0x80 + y;
		z = temp>>4;
		w = temp & 0x0F;
		LCD_Cmd(z);
		LCD_Cmd(w);
	}
Example #6
0
void main()
{

	PowerOnSetProc();
	
	LCD_Cmd(DISPLAY_CURSE_BLINK_ON);
	machine_state = STATE_MONITOR_MODE;

	while(1){

		if( secWatchDog > 60 ){
			secWatchDog = 0;
			delay_ms(100); 
			sci_rx_msg_start = sci_rx_msg_end = 0;
			LCD_Initialization();				
			machine_state = STATE_MONITOR_MODE;
			delay_ms(100); 
		}
		

		if	   ( machine_state == STATE_SET_MODE ) SelectMenuPage1();			// 모드 선택
		else if( machine_state == STATE_SET_MODE2 ) SelectMenuPage2();			// 모드 선택
		else if( machine_state == STATE_EDIT_MODE) EditCodeDataProc();			// 사용자 에디터 모드
		else if( machine_state == STATE_TRIP_MODE) TripCodeDataProc();			// Trip 모드 (저장 데이터)
		else if( machine_state == STATE_RESET_MODE) ResetCodeDataProc();		// Reset 모드
		else if( machine_state == STATE_TIME_MODE) TimeDataSetProc();			// 시간 셋팅 모드
		// else if( machine_state == STATE_ERROR_MODE)	ErrorCodeDataProc();		// TRIP ERROR 모드
		else if( machine_state == RECORD_CLEAR_MODE) RecordClearProc();			// Trip 이력 모두 삭제
		else if( machine_state == SYSTEM_INIT_MODE) SystemInitProc();			// EEPROM DATA 초기화
		else if( machine_state == CHECKSUM_MODE) CheckSumErrorProc();			// Checksum 복구모드
		else if( machine_state == STATE_POSITION_MODE) PositionTestProc();		// TEST
		else {   machine_state = STATE_MONITOR_MODE; monitor_converter();}
	}
}
Example #7
0
void LCD_SC_DisplayRemainGas(void)
{
	uint32_t gas = 5;
	uint8_t gas_bcd[6] = {0};

	gas = DataMem_GetRemainGas();
	Covertu32To6bitBCD(gas,gas_bcd);
	if(!lcd_is_on)
	{
		LCD_SC_Init();
		lcd_is_on = 1;
	}
	disp_icon |= DISP_STERE_ICON;
	lcd_disp_info.is_disp_digits = 1;
	lcd_disp_info.is_disp_dot = 1;
	lcd_disp_info.is_disp_icon = 1;
	lcd_disp_info.p_disp_contex = gas_bcd;
	lcd_disp_info.disp_contex_len = sizeof(gas_bcd);
	lcd_disp_info.disp_dot_num = 4;
	lcd_disp_info.p_disp_icon = &disp_icon;
			
	LCD_SC_Init();
	LCD_SC_Display(&lcd_disp_info);
    LCD_SC_DoDisp();

	delay1s(10);

	disp_icon &= 0;
	memset(&lcd_disp_info, 0, sizeof(lcd_disp_info_t));
	LCD_SC_Display(&lcd_disp_info);
			
	/* Initialize the LCD */
	LCD_Cmd(DISABLE);
	LCD_DeInit();
}
/**
  * @brief This function initializes in Ultra Low Power mode, 
	*				disable the LCD, LSE and configures the unused IOs 
	*				in output push-pull
	* @caller main and ADC_Icc_Test
  * @param None
  * @retval None
  */ 
void Halt_Init(void)
{

/* Set STM8 in low power */
  PWR->CSR2 = 0x2;
  
  LCD_Cmd(DISABLE);

  /* To wait LCD disable */
  while ((LCD->CR3 & 0x40) != 0x00);
  
/* Set GPIO in low power*/	
  GPIO_LowPower_Config();
  
/* Stop RTC Source clock */
  CLK_RTCClockConfig(CLK_RTCCLKSource_Off, CLK_RTCCLKDiv_1);
  
  #ifdef USE_LSE
    CLK_LSEConfig(CLK_LSE_OFF);
    while ((CLK->ECKCR & 0x04) != 0x00);
  #else
    CLK_LSICmd(DISABLE);
    while ((CLK->ICKCR & 0x04) != 0x00);
  #endif
  
  /* Stop clock RTC and LCD */ 	
  CLK_PeripheralClockConfig(CLK_Peripheral_RTC, DISABLE);
  CLK_PeripheralClockConfig(CLK_Peripheral_LCD, DISABLE);
}
Example #9
0
void LCD_Window (unsigned int x, unsigned int y, unsigned int w, unsigned int h)
{
    LCD_Cmd(0x2A);
    SSP0_16(1);
    SSP0_Write(x);
    SSP0_Write(x+w-1);
    SSP0_WaitBusy();
    LCD_CS(1);
    SSP0_16(0);

    LCD_Cmd(0x2B);
    SSP0_16(1);
    SSP0_Write(y) ;
    SSP0_Write(y+h-1);
    SSP0_WaitBusy();
    LCD_CS(1);
    SSP0_16(0);
}
Example #10
0
void Cursor(int row,int offset,unsigned CursorCmd)
{
	int	Addr;
	switch (row)
	{
		case	0	:	Addr=ROW1;	break;
		case	1	:	Addr=ROW2;	break;
		case	2	:	Addr=ROW3;	break;
		case	3	:	Addr=ROW4;	break;
	}
	LCD_AddrSet(Addr+offset);
	LCD_Cmd(CursorCmd);
}
Example #11
0
// write direct to SSP0 register !
void LCD_Pixel(int x, int y, int color)
{
    LCD_Cmd(0x2A);   // Set the Horizontal GRAM Address
    SSP0_16(1);
    SSP0_Write(x);
    SSP0_WaitBusy();
    LCD_CS(1);

    SSP0_16(0);
    LCD_Cmd(0x2B);   // Set the Vertical GRAM Address
    SSP0_16(1);
    SSP0_Write(y);
    SSP0_WaitBusy();
    LCD_CS(1);
    SSP0_16(0);

    LCD_Cmd(0x2C);   // Send pixel
    SSP0_16(1);
    SSP0_Write(color);
    SSP0_WaitBusy();
    LCD_CS(1);
    SSP0_16(0);
}
Example #12
0
void lcd_init(void)
{
 LCD_Init(LCD_Prescaler_2, 
LCD_Divider_16,
LCD_Duty_1_4,
LCD_Bias_1_3,
LCD_VoltageSource_Internal);
LCD_PortMaskConfig(LCD_PortMaskRegister_0, 0xff);
LCD_PortMaskConfig(LCD_PortMaskRegister_1,0xff);
LCD_PortMaskConfig(LCD_PortMaskRegister_2,0x03);
LCD_PulseOnDurationConfig(LCD_PulseOnDuration_1);
LCD_Cmd(ENABLE);
LCD_ContrastConfig(LCD_Contrast_Level_5);

};
Example #13
0
void LCD_HardwareInit(void)
{
  unsigned long segments = S8 | S9 | S10 | S11 | S12 | S13 | S14 | S15 | S16 | S17 | S18 | S19;
  CLK_RTCClockConfig(CLK_RTCCLKSource_LSI, CLK_RTCCLKDiv_2);
  CLK_PeripheralClockConfig(CLK_Peripheral_RTC, ENABLE);
  
  CLK_PeripheralClockConfig(CLK_Peripheral_LCD, ENABLE);
  LCD_Init(LCD_Prescaler_4, LCD_Divider_24, LCD_Duty_1_3, LCD_Bias_1_3, LCD_VoltageSource_External);
  LCD_PortMaskConfig(LCD_PortMaskRegister_1, (uint8_t)(segments >> 8));
  LCD_PortMaskConfig(LCD_PortMaskRegister_2, (uint8_t)(segments >> 16));
  LCD_PortMaskConfig(LCD_PortMaskRegister_3, (uint8_t)(segments >> 24));
  LCD_PulseOnDurationConfig(LCD_PulseOnDuration_0);
  LCD_ContrastConfig(LCD_Contrast_Level_7);
  LCD_Cmd(ENABLE);
}
Example #14
0
void LCD_Init()
{
	CyDelay(40);
	LCD_Cmd(0b00111000);	// function set
	LCD_Cmd(0b00111001);	// function set
	LCD_Cmd(0b00010100);	// interval osc
	LCD_Cmd(0b01110000 | (contrast & 0xF));	// contrast Low
	LCD_Cmd(0b01011100 | ((contrast >> 4) & 0x3)); // contast High/icon/power
	LCD_Cmd(0b01101100); // follower control
	CyDelay(300);
	
	LCD_Cmd(0b00111000); // function set
	LCD_Cmd(0b00001100); // Display On
}
Example #15
0
void LCD_FillRect(int x0, int y0, int x1, int y1, int color)
{
    int h = y1 - y0 + 1;
    int w = x1 - x0 + 1;
    int pixels = h * w;
    //unsigned int dma_count;
    LCD_Window(x0,y0,w,h);

    LCD_Cmd(0x2C);  // send pixel
    SSP0_16(1);     // Use 16 bit transfers

    // Write to LCD using DMA
    SSP0_WriteLcdDMA(color, pixels);

#if 0
    LPC_GPDMACH0->DMACCSrcAddr = (uint32_t)&color;
    LPC_GPDMACH0->DMACCDestAddr = (uint32_t)&LPC_SSP0->DR; // we send to SSP0
    LPC_SSP0->DMACR = 0x2;


    // start DMA
    do {
        if (pixel > 4095) {
            dma_count = 4095;
            pixel = pixel - 4095;
        } else {
            dma_count = pixel;
            pixel = 0;
        }
        LPC_GPDMA->DMACIntTCClear = 0x1;
        LPC_GPDMA->DMACIntErrClr = 0x1;
        // Configure DMA to use 16bit transfers
        // no address increment, interrupt
        LPC_GPDMACH0->DMACCControl = dma_count | (1UL << 18) | (1UL << 21) | (1UL << 31) ;
        LPC_GPDMACH0->DMACCConfig  = DMA_CHANNEL_ENABLE | DMA_TRANSFER_TYPE_M2P | DMA_DEST_SSP0_TX;
        LPC_GPDMA->DMACSoftSReq = 0x1;   // DMA request
        do {
        } while ((LPC_GPDMA->DMACRawIntTCStat & 0x01) == 0); // DMA is running
    } while (pixel > 0);
#endif

    SSP0_WaitBusy();    // wait for end of transfer
    SSP0_16(0);
    LCD_CS(1);
    LCD_WindowMax();
    return;
}
Example #16
0
File: lcd.c Project: ezhov/test2
void startLcd()
{
    int i;
    long j;

    CLK_PeripheralClockConfig(CLK_Peripheral_RTC, ENABLE);
    CLK_RTCClockConfig(CLK_RTCCLKSource_LSI, CLK_RTCCLKDiv_1);
    CLK_PeripheralClockConfig(CLK_Peripheral_LCD, ENABLE);

    LCD_Init(LCD_Prescaler_1, LCD_Divider_31, LCD_Duty_1_4, LCD_Bias_1_3, LCD_VoltageSource_Internal);
    LCD_PortMaskConfig(LCD_PortMaskRegister_0, 0xff);
    LCD_PortMaskConfig(LCD_PortMaskRegister_1, 0xff);
    LCD_PortMaskConfig(LCD_PortMaskRegister_2, 0xff);
    LCD_ContrastConfig(LCD_Contrast_3V0);
    LCD_DeadTimeConfig(LCD_DeadTime_0);
    LCD_PulseOnDurationConfig(LCD_PulseOnDuration_1);

    LCD_Cmd(ENABLE);
}
Example #17
0
void LCD_SC_Init(void)
{
	/* Enable LCD clock */
	CLK_PeripheralClockConfig(CLK_Peripheral_RTC, ENABLE);
	CLK_PeripheralClockConfig(CLK_Peripheral_LCD, ENABLE);
	CLK_RTCClockConfig(CLK_RTCCLKSource_LSE, CLK_RTCCLKDiv_1);

	/* Initialize the LCD */
	LCD_Init(LCD_Prescaler_2, LCD_Divider_18, LCD_Duty_1_8,
	   		LCD_Bias_1_4, LCD_VoltageSource_Internal);

	/* Mask register*/
	LCD_PortMaskConfig(LCD_PortMaskRegister_0, 0xff);
	LCD_PortMaskConfig(LCD_PortMaskRegister_1, 0x3f);

	LCD_ContrastConfig(LCD_Contrast_Level_7);
	LCD_PulseOnDurationConfig(LCD_PulseOnDuration_7);

	/*  Enable LCD peripheral */
	LCD_Cmd(ENABLE);
}
Example #18
0
void LCD_SetOrientation(unsigned int o)
{
    orientation = o;
    LCD_Cmd(0x36);                     // MEMORY_ACCESS_CONTROL
    switch (orientation) {
        case 0:
            SSP0_Write(0x48);
            break;
        case 1:
            SSP0_Write(0x28);
            break;
        case 2:
            SSP0_Write(0x88);
            break;
        case 3:
            SSP0_Write(0xE8);
            break;
    }
    SSP0_WaitBusy();    // wait for end of transfer
    LCD_CS(1);
    LCD_WindowMax();
}
/**
  * @brief  Configures the LCD GLASS relative GPIO port IOs and LCD peripheral.
  * @param  None 
  * @retval None
  */
void LCD_GLASS_Init(void)
{
  LCD_InitTypeDef LCD_InitStructure;
  
  LCD_GPIOConfig(); /*!< Configure the LCD Glass GPIO pins */

  /*!< Configure the LCD interface -------------------------------------------*/
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_LCD, ENABLE); /*!< Enable LCD APB1 Clock */
  
  LCD_InitStructure.LCD_Prescaler = LCD_Prescaler_8;
  LCD_InitStructure.LCD_Divider = LCD_Divider_16;
  LCD_InitStructure.LCD_Duty = LCD_Duty_1_4;
  LCD_InitStructure.LCD_Bias = LCD_Bias_1_3;
  LCD_InitStructure.LCD_VoltageSource = LCD_VoltageSource_Internal;
  LCD_Init(&LCD_InitStructure);

  /*!< Configure the Pulse On Duration */
  LCD_PulseOnDurationConfig(LCD_PulseOnDuration_2);
  
  /*!< Configure the LCD Contrast (3.51V) */
  LCD_ContrastConfig(LCD_Contrast_Level_7);

  /*!< Wait Until the LCD FCR register is synchronized */
  LCD_WaitForSynchro();
  
  /*!< Enable LCD peripheral */
  LCD_Cmd(ENABLE);
  
  /*!< Wait Until the LCD is enabled */
  while(LCD_GetFlagStatus(LCD_FLAG_ENS) == RESET)
  {
  }
  /*!< Wait Until the LCD Booster is ready */  
  while(LCD_GetFlagStatus(LCD_FLAG_RDY) == RESET)
  {
  }    
}
Example #20
0
void LCD_SetPos(uint32 x, uint32 y)
{
	LCD_Cmd(0b10000000 | (x + y * 0x40));
}
Example #21
0
void LCD_Clear()
{
	LCD_Cmd(0b00000001); // Clear Display
	CyDelay(2);	// Clear Displayは追加ウェイトが必要
}
Example #22
0
void monitor_converter()
{
	BUTTON KeyIn;
	unsigned int disp_count=0;
	int loopCtrl =1;
	int debug;

	LCD_Clear();
	LCD_Cmd(CURSOR_OFF);

	while( loopCtrl)
	{ 
		KeyIn = GetKey();
		lcd_y_posi = 1; lcd_x_posi = 0;

		debug =getSciMsg(st); 		
		if( debug ) {
			if(debug > 19 ); st[19] = 0;
			printLCD(lcd_y_posi,lcd_y_posi,st);
		}

		if		( KeyIn == BTN_SET 	){	machine_state = STATE_SET_MODE; loopCtrl = 0;	return;}
		else if	(KeyIn == BTN_RUN	){	strcpy(gSciTxBuf,"9:4:905:0.000e-0"); SendSciString( gSciTxBuf );}
		else if	(KeyIn == BTN_STOP	){	strcpy(gSciTxBuf,"9:4:905:1.000e-0"); SendSciString( gSciTxBuf );}
		else if	(KeyIn == BTN_UP	){ 	strcpy(gSciTxBuf,"9:4:905:2.000e-0"); SendSciString( gSciTxBuf );}
		else if	(KeyIn == BTN_DOWN	){	strcpy(gSciTxBuf,"9:4:905:3.000e-0"); SendSciString( gSciTxBuf );}
		else{
			if( disp_count == 0){ 
				lcd_y_posi = 0; lcd_x_posi = 0;
				strcpy(gSciTxBuf,"9:4:901:0.000e-0");
			}
			else if( disp_count == 1){
				lcd_y_posi = 0; lcd_x_posi = 10;
				strcpy(gSciTxBuf,"9:4:902:0.000e-0");	// Power Input
			}	
			else if( disp_count == 2){
				lcd_y_posi = 2; lcd_x_posi = 0;
				strcpy(gSciTxBuf,"9:4:902:1.000e-0");	// Vdc
			}
			else if( disp_count == 3){
				lcd_y_posi = 2; lcd_x_posi = 10;
				strcpy(gSciTxBuf,"9:4:902:2.000e-0");	// I RMS Source 
			}
			else if( disp_count == 4){
				lcd_y_posi = 3; lcd_x_posi = 0;
				strcpy(gSciTxBuf,"9:4:902:3.000e-0");	// I alpa
			}
			else {
				lcd_y_posi = 3; lcd_x_posi = 10;
				strcpy(gSciTxBuf,"9:4:902:4.000e-0");	// I beta
			}
			sci_rx_msg_start = sci_rx_msg_end = 0;
			SendSciString( gSciTxBuf );
			delay_ms(50);
			debug = getSciMsg(st);
			if( debug ) {
				if( debug> 9);
				st[10] = 0;
				printLCD(lcd_y_posi,lcd_x_posi,st);
			}
			else {
				strcpy(st,"  ---   ");	
				st[0] = disp_count + '0';
				printLCD(lcd_y_posi,lcd_x_posi,st);
			}
			if(disp_count >= 5 ) disp_count = 0; 
			else disp_count ++;
		}
		delay_ms(100);
	} // while loop
}
Example #23
0
/**
  * @brief Current measurement in different MCU modes:
  * RUN/SLEEP/LowPower/STANDBY with/without RTC
  * @caller main and ADC_Icc_Test
  * @param MCU state
  * @retval ADC value.
  */
uint16_t ADC_Icc_Test(uint8_t Mcu_State)
{
  GPIO_InitTypeDef GPIO_InitStructure;
  uint16_t adc_measure;
  uint32_t i;
  RCC_TypeDef SavRCC;
  /* Reset UserButton State */
  UserButton = FALSE;
  /* Start counter */
  GPIO_HIGH(CTN_GPIO_PORT,CTN_CNTEN_GPIO_PIN);
  /* Disable the RTC Wakeup Interrupt */
  RTC_ITConfig(RTC_IT_WUT, DISABLE);
  /* Disable LCD */
  LCD_Cmd(DISABLE);
  /* wait until LCD disable */
  while (LCD_GetFlagStatus(LCD_FLAG_ENS) == SET);
  /*Reset Idd-WakeUP flag*/
  Idd_WakeUP = FALSE;
  /* Set IO in lowpower configuration*/
  GPIO_LowPower_Config(); 
  /*Disable fast wakeUp*/
  PWR_FastWakeUpCmd(DISABLE);
  
/* Test MCU state for configuration */
  switch (Mcu_State)
  {
    /* Run mode : Measurement Measurement performed with MSI 4 MHz without RTC*/	
    case MCU_RUN:
        /* switch on MSI clock */
        SetHSICLKToMSI(RCC_MSIRange_6,NoDIV2,NoRTC) ;   
        /* shitch on MSI clock */
        Config_RCC(&SavRCC);    
        SysTick->CTRL = 0;     
        RCC->APB1ENR = 0;

        /* To run nops during measurement:
        it's the best case for low current */     

        for (i=0;i<0xffff;i++) {
          __NOP();  __NOP();    __NOP();  __NOP();
          __NOP();  __NOP();    __NOP();  __NOP();
          __NOP();  __NOP();    __NOP();  __NOP();
          __NOP();  __NOP();    __NOP();  __NOP();
          __NOP();  __NOP();    __NOP();  __NOP();
          __NOP();  __NOP();    __NOP();  __NOP();
          __NOP();  __NOP();    __NOP();  __NOP();
          __NOP();  __NOP();    __NOP();  __NOP();
          __NOP();  __NOP();    __NOP();  __NOP();
          __NOP();  __NOP();    __NOP();  __NOP();
          __NOP();  __NOP();    __NOP();  __NOP();
        }
        
    break;

    /* SLEEP mode : Measurement performed with MSI 4 MHz without RTC in WFI mode*/
    case MCU_SLEEP:
         
        SetHSICLKToMSI(RCC_MSIRange_6,NoDIV2,NoRTC) ;   
        Config_RCC(&SavRCC);  
        Config_Systick_50ms();
        Delay(1);

       /* Request Wait For Interrupt */
        PWR_EnterSleepMode(PWR_Regulator_ON,PWR_SLEEPEntry_WFI);   
           
        break;    

   /* RUN LOW POWER mode :   Measurement performed with MSI 32 Khz without RTC */
    case MCU_LP_RUN:
      
        /* Disable PVD */
        PWR_PVDCmd(DISABLE);

        /* Enable The ultra Low Power Mode */
        PWR_UltraLowPowerCmd(ENABLE);         

        /* Save the RCC configuration registers */
        Config_RCC(&SavRCC);      
        
        /* Stop the sys tick in order to avoid IT */
        SysTick->CTRL = 0; 
        
#ifdef TESTINRAM        
        SetHSICLKToMSI(RCC_MSIRange_0,DIV2,NoRTC) ; 
        
        PWR_EnterLowPowerRunMode(ENABLE);
        while(PWR_GetFlagStatus(PWR_FLAG_REGLP) == RESET) ;  

        DisableInterrupts();
        EnterLPRUNModeRAM();
        EnableInterrupts();        
#else         
        /* Swith in MSI 32KHz */
        SetHSICLKToMSI(RCC_MSIRange_64KHz,DIV2,NoRTC) ;    
                
        PWR_EnterLowPowerRunMode(ENABLE);
        while(PWR_GetFlagStatus(PWR_FLAG_REGLP) == RESET) ;              
        
        /* Launch the counter */
        GPIO_LOW(CTN_GPIO_PORT,CTN_CNTEN_GPIO_PIN);           
           
        /* To run the nop during measurement:
        it's the best case for low current
        until counter reach detected by IT --> Idd_WakeUP */
        do{
          __NOP();  __NOP();    __NOP();  __NOP();
          __NOP();  __NOP();    __NOP();  __NOP(); 
          __NOP();  __NOP();    __NOP();  __NOP();
          __NOP();  __NOP();    __NOP();  __NOP();  
          __NOP();  __NOP();    __NOP();  __NOP();
          __NOP();  __NOP();    __NOP();  __NOP(); 
          __NOP();  __NOP();    __NOP();  __NOP();
          __NOP();  __NOP();    __NOP();  __NOP();            
        }  while (Idd_WakeUP == FALSE );       
#endif        
        
        PWR_EnterLowPowerRunMode(DISABLE);
        while(PWR_GetFlagStatus(PWR_FLAG_REGLP) != RESET) ;  
    
        break; 
      
      /* SLEEP LOW POWER mode
         Measurement done to MSI 32 Khz without RTC
      */	
      case MCU_LP_SLEEP:
        
        /* Disable PVD */
        PWR_PVDCmd(DISABLE);   
        
        /* Enable Ultra low power mode */
        PWR_UltraLowPowerCmd(ENABLE);

                
        /* To save the RCC configuration registers */
        Config_RCC(&SavRCC);     
        
        /* To stop the sys tick for avoid IT */
        SysTick->CTRL = 0; 
        
        /* Swith in MSI 32KHz */
        SetHSICLKToMSI(RCC_MSIRange_0,DIV2,NoRTC) ;

#ifdef TESTINRAM
        DisableInterrupts();
        EnterLPSLEEPModeRAM();
        EnableInterrupts();
#else        
        /* Falling edge for start counter */		
        GPIO_LOW(CTN_GPIO_PORT,CTN_CNTEN_GPIO_PIN);

        /* Request Wait For Interrupt */    
        PWR_EnterSleepMode(PWR_Regulator_LowPower,PWR_SLEEPEntry_WFI);
#endif              
        break;   
        
      /* STOP modes
       Measurement done to MSI 32 Khz without or with RTC
       */		
      case MCU_STOP_NoRTC:
      case MCU_STOP_RTC:

        /* Disable PVD */
        PWR_PVDCmd(DISABLE);
          
        /* Enable Ultra low power mode */
        PWR_UltraLowPowerCmd(ENABLE);           
        
        /* To save the RCC configuration registers */
        Config_RCC(&SavRCC);  

        /* To stop the sys tick for avoid IT */
        SysTick->CTRL = 0; 
               
       /* Swith in MSI 32KHz */
        if( Mcu_State == MCU_STOP_NoRTC )
          SetHSICLKToMSI(RCC_MSIRange_0,DIV2,NoRTC) ;
        else
         SetHSICLKToMSI(RCC_MSIRange_0,DIV2,WITHRTC) ;          

        /* Falling edge for start counter */		
        GPIO_LOW(CTN_GPIO_PORT,CTN_CNTEN_GPIO_PIN);
        
        /* Request Wait For Interrupt */    
        PWR_EnterSTOPMode(PWR_Regulator_LowPower,PWR_STOPEntry_WFI);              

        break;        
          
        /* Standby mode without RTC
          Measurement done to MSI 32 Khz without RTC
        */
        case MCU_STBY:
          
          /* Disable PVD */
          PWR_PVDCmd(DISABLE);
          
          /* Enable Ultra low power mode */
          PWR_UltraLowPowerCmd(ENABLE);
          
          RTC_OutputTypeConfig(RTC_OutputType_PushPull);
          RTC_OutputConfig(RTC_Output_WakeUp,RTC_OutputPolarity_High);        
          
          /* To configure PC13 WakeUP output */
         GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13  ;
          //GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0  ;
          GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
          GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
          GPIO_InitStructure.GPIO_Speed = GPIO_Speed_400KHz;  
          GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
          GPIO_Init( GPIOC, &GPIO_InitStructure); 
         // GPIO_Init( GPIOA, &GPIO_InitStructure);
          
         GPIO_PinAFConfig(GPIOC, GPIO_PinSource13,GPIO_AF_RTC_AF1) ;
          //GPIO_PinAFConfig(GPIOA, GPIO_PinSource0,GPIO_AF_RTC_AF1) ;
          Config_RCC(&SavRCC);  
          
          SysTick->CTRL = 0; 
                  
          /* Swith in MSI 32KHz */
          SetHSICLKToMSI(RCC_MSIRange_0,DIV2,NoRTC) ;     
          
          PWR_WakeUpPinCmd(PWR_WakeUpPin_1,ENABLE);
          
          PWR_UltraLowPowerCmd(ENABLE); 
          
           PWR_EnterSTANDBYMode();
          /* Stop here WakeUp EXIT on RESET */
        
        break;
      }
  
  SetHSICLK();  

  Config_Systick(); 
  RCC->AHBENR = SavRCC.AHBENR;	
         
  PWR_VoltageScalingConfig(PWR_VoltageScaling_Range1);
  /* Wait Until the Voltage Regulator is ready */
  while (PWR_GetFlagStatus(PWR_FLAG_VOS) != RESET) ;

   /* Read ADC for current measurmeent */
   adc_measure = Current_Measurement();
    
  /* ICC_CNT_EN Hi */
  GPIO_HIGH(CTN_GPIO_PORT,CTN_CNTEN_GPIO_PIN);
  UserButton = TRUE;

  /* To restore RCC registers */
  RCC->APB1ENR = SavRCC.APB1ENR;
  RCC->APB2ENR = SavRCC.APB2ENR; 
  RCC->AHBLPENR = SavRCC.AHBLPENR;	
  RCC->APB1LPENR = SavRCC.APB1LPENR;
  RCC->APB2LPENR = SavRCC.APB2LPENR;
  
  /* Need to reinit RCC for LCD*/
  RCC_Configuration();

  PWR_EnterLowPowerRunMode(DISABLE);
  
  /* Disable Ultra low power mode */
  PWR_UltraLowPowerCmd(DISABLE);
  
  /* Disable FLASH during SLeep LP */
  FLASH_SLEEPPowerDownCmd(DISABLE);
  
  Restore_GPIO_Config();  
 
  /* Clear Wake Up flag */
  PWR_ClearFlag(PWR_FLAG_WU);
  
  /* Enable PVD */
  PWR_PVDCmd(ENABLE);

  LCD_GLASS_Init();
   
  return (adc_measure);
}
Example #24
0
// LCD Reset Sequence is copied from
// internet sources. There are a number of
// command registers needed to be set, some of
// which I wonder what they are being used for?
void LCD_Reset()
{
    //int i;
    LCD_CS(1);        // cs high
    LCD_DC(1);        // dc high
    LCD_RST(0);       // display reset

    // wait_us(50);
    Delay(1);         // Delay 1 ms
    LCD_RST(1);       // end hardware reset
    Delay(5);

    LCD_Cmd(0x01);    // SW reset
    Delay(5);
    LCD_Cmd(0x28);    // display off

    /* Start Initial Sequence */
    LCD_Cmd(0xCF);
    SSP0_Write(0x00);
    SSP0_Write(0x83);
    SSP0_Write(0x30);
    SSP0_WaitBusy();
    LCD_CS(1);

    LCD_Cmd(0xED);
    SSP0_Write(0x64);
    SSP0_Write(0x03);
    SSP0_Write(0x12);
    SSP0_Write(0x81);
    SSP0_WaitBusy();
    LCD_CS(1);

    LCD_Cmd(0xE8);
    SSP0_Write(0x85);
    SSP0_Write(0x01);
    SSP0_Write(0x79);
    SSP0_WaitBusy();
    LCD_CS(1);

    LCD_Cmd(0xCB);
    SSP0_Write(0x39);
    SSP0_Write(0x2C);
    SSP0_Write(0x00);
    SSP0_Write(0x34);
    SSP0_Write(0x02);
    SSP0_WaitBusy();
    LCD_CS(1);

    LCD_Cmd(0xF7);
    SSP0_Write(0x20);
    SSP0_WaitBusy();
    LCD_CS(1);

    LCD_Cmd(0xEA);
    SSP0_Write(0x00);
    SSP0_Write(0x00);
    SSP0_WaitBusy();
    LCD_CS(1);

    LCD_Cmd(0xC0);          // POWER_CONTROL_1
    SSP0_Write(0x26);
    SSP0_WaitBusy();
    LCD_CS(1);

    LCD_Cmd(0xC1);          // POWER_CONTROL_2
    SSP0_Write(0x11);
    SSP0_WaitBusy();
    LCD_CS(1);

    LCD_Cmd(0xC5);          // VCOM_CONTROL_1
    SSP0_Write(0x35);
    SSP0_Write(0x3E);
    SSP0_WaitBusy();
    LCD_CS(1);

    LCD_Cmd(0xC7);          // VCOM_CONTROL_2
    SSP0_Write(0xBE);
    SSP0_WaitBusy();
    LCD_CS(1);

    LCD_Cmd(0x36);          // MEMORY_ACCESS_CONTROL
    SSP0_Write(0x48);
    SSP0_WaitBusy();
    LCD_CS(1);

    LCD_Cmd(0x3A);          // COLMOD_PIXEL_FORMAT_SET
    SSP0_Write(0x55);        // 16 bit pixel
    SSP0_WaitBusy();
    LCD_CS(1);

    LCD_Cmd(0xB1);          // Frame Rate
    SSP0_Write(0x00);
    SSP0_Write(0x1B);
    SSP0_WaitBusy();
    LCD_CS(1);

    LCD_Cmd(0xF2);          // Gamma Function Disable
    SSP0_Write(0x08);
    SSP0_WaitBusy();
    LCD_CS(1);

    LCD_Cmd(0x26);
    SSP0_Write(0x01);        // gamma set for curve 01/2/04/08
    SSP0_WaitBusy();
    LCD_CS(1);

    LCD_Cmd(0xE0);          // positive gamma correction
    SSP0_Write(0x1F);
    SSP0_Write(0x1A);
    SSP0_Write(0x18);
    SSP0_Write(0x0A);
    SSP0_Write(0x0F);
    SSP0_Write(0x06);
    SSP0_Write(0x45);
    SSP0_Write(0x87);
    SSP0_Write(0x32);
    SSP0_Write(0x0A);
    SSP0_Write(0x07);
    SSP0_Write(0x02);
    SSP0_Write(0x07);
    SSP0_Write(0x05);
    SSP0_Write(0x00);
    SSP0_WaitBusy();
    LCD_CS(1);

    LCD_Cmd(0xE1);          // negativ gamma correction
    SSP0_Write(0x00);
    SSP0_Write(0x25);
    SSP0_Write(0x27);
    SSP0_Write(0x05);
    SSP0_Write(0x10);
    SSP0_Write(0x09);
    SSP0_Write(0x3A);
    SSP0_Write(0x78);
    SSP0_Write(0x4D);
    SSP0_Write(0x05);
    SSP0_Write(0x18);
    SSP0_Write(0x0D);
    SSP0_Write(0x38);
    SSP0_Write(0x3A);
    SSP0_Write(0x1F);
    SSP0_WaitBusy();
    LCD_CS(1);

    LCD_WindowMax();

    //LCD_Cmd(0x34);        // tearing effect off
    //LCD_CS(1);

    //LCD_Cmd(0x35);        // tearing effect on
    //LCD_CS(1);

    LCD_Cmd(0xB7);          // entry mode
    SSP0_Write(0x07);
    SSP0_WaitBusy();
    LCD_CS(1);

    LCD_Cmd(0xB6);          // display function control
    SSP0_Write(0x0A);
    SSP0_Write(0x82);
    SSP0_Write(0x27);
    SSP0_Write(0x00);
    SSP0_WaitBusy();
    LCD_CS(1);

    LCD_Cmd(0x11);          // sleep out
    SSP0_WaitBusy();
    LCD_CS(1);

    // wait_ms(100);
    Delay(100);

    LCD_Cmd(0x29);          // display on
    SSP0_WaitBusy();
    LCD_CS(1);

    // wait_ms(100);
    Delay(100);


}
Example #25
0
void LCD_Character(int x, int y, int c)
{
    unsigned int hor,vert,offset,bpl,j,i,b;
    unsigned char* charbit;
    unsigned char z,w;
#ifdef use_ram
    unsigned int pixel;
    unsigned int p;
    unsigned int dma_count,dma_off;
    uint16_t *buffer;
#endif

    // Position characters
    LCD_Locate(x, y);

    if ((c < 31) || (c > 127)) return;   // test char range

    // read font parameter from start of array
    offset = font[0];                    // bytes / char
    hor = font[1];                       // get hor size of font
    vert = font[2];                      // get vert size of font
    bpl = font[3];                       // bytes per line

    if (((int) (char_x + hor)) > LCD_Width()) {
        char_x = 0;
        char_y = char_y + vert;
        if (((int) char_y) >= LCD_Height() - font[2]) {
            char_y = 0;
        }
    }
    LCD_Window(char_x, char_y,hor,vert);           // setup char box
    LCD_Cmd(0x2C);
    SSP0_16(1);                                 // switch to 16 bit Mode
#ifdef LCD_USE_RAM
    pixel = hor * vert;                        // calculate buffer size
    buffer = (uint16_t *) malloc (2*pixel);    // we need a buffer for the font
    if(buffer != NULL) {                       // there is memory space -> use dma
        charbit = &font[((c -32) * offset) + 4]; // start of char bitmap
        w = charbit[0];                          // width of actual char
        p = 0;
        // construct the font into the buffer
        for (j=0; j<vert; j++) {            //  vert line
            for (i=0; i<hor; i++) {         //  horz line
                z =  charbit[bpl * i + ((j & 0xF8) >> 3)+1];
                b = 1 << (j & 0x07);
                if (( z & b ) == 0x00) {
                    buffer[p] = background;
                } else {
                    buffer[p] = foreground;
                }
                p++;
            }
        }
        // copy the buffer with DMA SPI to display
        dma_off = 0;  // offset for DMA transfer

        LPC_GPDMACH0->DMACCDestAddr = (uint32_t)&LPC_SSP0->DR; // we send to SSP0
        LPC_SSP0->DMACR = 0x2;

        // start DMA
        do {
            if (pixel > 4095) {         // this is a giant font !
                dma_count = 4095;
                pixel = pixel - 4095;
            } else {
                dma_count = pixel;
                pixel = 0;
            }
            LPC_GPDMA->DMACIntTCClear = 0x1;
            LPC_GPDMA->DMACIntErrClr = 0x1;
            LPC_GPDMACH0->DMACCSrcAddr = (uint32_t) (buffer + dma_off);
            LPC_GPDMACH0->DMACCControl = dma_count | (1UL << 18) | (1UL << 21) | (1UL << 31) |  DMA_CHANNEL_SRC_INC ; // 16 bit transfer , address increment, interrupt
            LPC_GPDMACH0->DMACCConfig  = DMA_CHANNEL_ENABLE | DMA_TRANSFER_TYPE_M2P | DMA_DEST_SSP0_TX);
            LPC_GPDMA->DMACSoftSReq = 0x1;
            do {
            } while ((LPC_GPDMA->DMACRawIntTCStat & 0x01) == 0); // DMA is running
            dma_off = dma_off + dma_count;
        } while (pixel > 0);


        SSP0_WaitBusy();
        free ((uint16_t *) buffer);
        SSP0_16(0);
    }
Example #26
0
void lcd_display(uint8_t on)
{
    LCD_Cmd(0xAE | (on ? 1 : 0));
}
Example #27
0
void lcd_set_page_address(uint8_t page)
{
    LCD_Cmd(0xB0 | (page & 0x07));
}
Example #28
0
// ***************************************************************************************************************************************************************
void LCD_Clear()
{
	LCD_Cmd(0);
	LCD_Cmd(1);
}
Example #29
0
/***********************************************************************
  * @brief  Handles the event for LCD displaying.
  * @param  None
  * @retval None
************************************************************************/
void lcd_event_handler(void * p_event_data, uint16_t event_size)
{
	lcd_event_t * lcd_event_tmp = p_event_data;
	uint8_t temp[6] = {8,8,8,8,5,6};
	uint32_t u32temp = 654321;
	
	switch(lcd_event_tmp->eLcd_event)
	{
        case LCD_INIT:
			#ifdef LCD_DEBUG
				printf("LCD_INIT ...\r\n");
			#endif
			LCD_SC_Init_A();
			LCD_SC_DeInit();
            break;
            
        case lCD_HANDLE:
			#ifdef LCD_DEBUG
				printf("lCD_HANDLE ...\r\n");
			#endif
			if(!lcd_is_on)
			{
				LCD_SC_Init();
				lcd_is_on = 1;
			}
			disp_icon |= (DISP_VALVE_CLOSE_ICON | DISP_STERE_ICON);
			lcd_disp_info.is_disp_digits = 1;
			lcd_disp_info.is_disp_dot = 1;
			lcd_disp_info.is_disp_icon = 1;
			lcd_disp_info.p_disp_contex = temp;
			lcd_disp_info.disp_contex_len = sizeof(temp);
			lcd_disp_info.disp_dot_num = 2;
			lcd_disp_info.p_disp_icon = &disp_icon;
			
			LCD_SC_Init();
			LCD_SC_Display(&lcd_disp_info);
            LCD_SC_DoDisp();

			delay1s(2);

			disp_icon &= 0;
			memset(&lcd_disp_info, 0, sizeof(lcd_disp_info_t));
			LCD_SC_Display(&lcd_disp_info);
			
			/* Initialize the LCD */
			LCD_Cmd(DISABLE);
			LCD_DeInit();
			
			lcd_event.eLcd_event = LCD_DEINIT;
			app_sched_event_put(&lcd_event,sizeof(lcd_event),lcd_event_handler);
            break;

		case LCD_DISPLAY_REMAIN_GAS:
			#ifdef LCD_DEBUG
				printf("LCD_DISPLAY_REMAIN_GAS ...\r\n");
			#endif
			LCD_SC_DisplayRemainGas();
			
			lcd_event.eLcd_event = LCD_DEINIT;
			app_sched_event_put(&lcd_event,sizeof(lcd_event),lcd_event_handler);
            break;

		case LCD_DEINIT:
			#ifdef LCD_DEBUG
				printf("LCD_DEINIT ...\r\n");
			#endif
			
			/* Initialize the LCD */
			LCD_Cmd(DISABLE);
			LCD_DeInit();
			LCD_SC_DeInit();
			lcd_is_on = 0;
			break;
        
		default:
			break;
	}
}
Example #30
0
int main(void)
{
    ConfigureOscillator();

    InitApp();
    
    ADCInit();

    LCD_Init(NONE);
    
    __delay_ms(100);
    
    LCD_Clear();
    
    RTCC_Initialize();
    
    InitCustomChars();
    
// ******************************************************************************
    char * WeekDay[7] = {"Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"};
    
    int8_t loopCounter = 12, previousLoopCounter = 12;
    
    int OutAirTemp;                                                     

    int Temp[11];

    int OldTemp[11] = {300};

    _Bool Out[11] = {0};                                                         // Startup values for all outputs, 0 = OFF (Output 0 - 11))
    
    _Bool OutSum = 0, outSumOldState = 0;                                        // Sum of all Outputs, Previous scan OutSum state
    
    unsigned char i = 0;
    
    char reset = 0;

    char TestKey;                                                               // Variable used for Storing Which Menu Key is Pressed

    int internalBGV;
    
    unsigned int backLightTimer = 0;

// ******************************************************************************

    while(1)
    {
        time = getRTCTime();                                                    // get the time
        
        unsigned int timer = 0;                                                 // Used to count up time in a loop, to auto exit if user in a menu too long

// ******************************************************************************
//        OutAirTemp = ((ADCRead(9) - 785)/3.2 - 500);                            // Setup for protoBoard 
//        OutAirTemp = ((ADCRead(9) - 804)/3.178 - 500);                          // Setup for first Board built, Green LED's 
        OutAirTemp = ((ADCRead(9) - 807)/3.196 - 500);                          // Setup for second Board built, Blue LED's  
// ******************************************************************************
        Temp[0] = ADCRead(0);   //Read Deck air temperature Pin 19
// ******************************************************************************
        Temp[1] = ADCRead(4);   //Read Deck floor temperature Pin 23
// ******************************************************************************
        Temp[2] = ADCRead(5);   //Read Utility room floor temperature Pin 24
// ******************************************************************************
        Temp[3] = ADCRead(6);   //Read Entrance floor temperature Pin 25
// ******************************************************************************
        Temp[4] = ADCRead(10);   //Read Master bathroom floor temperature Pin 14
// ******************************************************************************
        Temp[5] = ADCRead(11);   //Read Office floor temperature Pin 11
// ******************************************************************************
        Temp[6] = ADCRead(12);   //Read Craft room floor temperature Pin 10
// ******************************************************************************
        Temp[7] = ADCRead(17);   //Read SE basement bedroom floor temperature Pin 41
// ******************************************************************************
        Temp[8] = ADCRead(18);   //Read Media room floor temperature Pin 42
// ******************************************************************************
        Temp[9] = ADCRead(19);   //Read Garage floor temperature Pin 43
// ******************************************************************************
        Temp[10] = ADCRead(20);   //Read Garage room air temperature Pin 44
// ******************************************************************************
        internalBGV = ADCRead(0x1A);
        
         for(i = 0;i<11;++i)
        {
        Temp[i] = TempCalc(Temp[i]);
        
        if(Temp[i] > OldTemp[i] + 1 || Temp[i] < OldTemp[i] - 1)
        {
            Temp[i] = ((OldTemp[i] + Temp[i])/2);
            OldTemp[i] = Temp[i];
        }
        else Temp[i] = OldTemp[i];
        }
// ******************************************************************************
        for(i=0;i<11;i++)
        {
            if(OutAirTemp <= -250)
            {
                Bias[i] = eepromGetData(biasNeg25[i]);
            }
            
            else if (OutAirTemp > -250 && OutAirTemp <= -240)
            {
                Bias[i] = Bias[i];
            }
    
            else if (OutAirTemp > -240 && OutAirTemp <= -150)
            {
                Bias[i] = eepromGetData(biasNeg15[i]);
            }
            
            else if (OutAirTemp > -150 && OutAirTemp <= -140)
            {
                Bias[i] = Bias[i];
            }
    
            else if (OutAirTemp > -140 && OutAirTemp <= -50)
            {
                Bias[i] = BiasNeg5[i];
            }

            else if (OutAirTemp > -50 && OutAirTemp <= -40)
            {
                Bias[i] = Bias[i];
            }
    
            else if (OutAirTemp > -40 && OutAirTemp <= 0)
            {
                Bias[i] = Bias0[i];
            }
    
            else if (OutAirTemp > 0 && OutAirTemp <= 10)
            {
                Bias[i] = Bias[i];
            }
    
            else if (OutAirTemp > 10 && OutAirTemp <= 50)
            {
                Bias[i] = Bias5[i];
            }

            else if (OutAirTemp > 50 && OutAirTemp <= 60)
            {
                Bias[i] = Bias[i];
            }
    
            else 
            {
                Bias[i] = BiasWarm[i];
            }
        }
// ******************************************************************************
        for (i=0;i<11;i++)
        {
            Out[i] = SetOutput(Out[i], eepromGetData(setpoint[i]), Bias[i], Temp[i], eepromGetData(deadband[i]));
        }
// ******************************************************************************
        for(i=0;i<11;i++)
        {
            if (Temp[i] <= eepromGetData(setpoint[i]) + Bias[i])                //If Out is not Off
            {
                outState[i] = 1;
            }
          
            else if (Temp[i] >= eepromGetData(setpoint[i]) + Bias[i] + eepromGetData(deadband[i]))
            {
                outState[i] = 0;
            }
            
            else
            {
                outState[i] = outState[i];
            }
            
            if(outState[i] != 0)
            {
                if (outState[i] != lastOutState[i])                             //If Out changed since last read
                {
                    outStateCounter[i]+=1;                                      //Increment the OutState Counter
                }
            }
            lastOutState[i] = outState[i];                                      //And set them equal to each other, so, it doesn't count again next time through
        }
// ******************************************************************************
        OutSum = Out[1] + Out[2] + Out[3] + Out[4] + Out[5] + Out[6] + Out[7] + Out[8] + Out[9];
        
        if(outSumOldState != OutSum)                                            // OutSum has changed,
        {
            if(OutSum != 0)                                                     // because an Out is turned on
            {
                for(i=0;i<11;i++)
                {
                    if (Temp[i] < eepromGetData(setpoint[i]) + eepromGetData(deadband[i]) + Bias[i])// Check for other PV's below SP + DB + Bias,
                    {
                        Out[i] = 1;                                             // and turn them on.
                    }

                    else
                    {
                        Out[i] = 0;                                             // Turn them off if they are already too hot!!
                    }
                }
            }
            outSumOldState = OutSum;
        }
// ******************************************************************************
        if(Out[0] == 0)                                                         // If Deck Air Temp is NOT calling,
        {
            Out[1] = 0;                                                         // turn OFF Deck Floor Out           
        }
        
        if(Out[10] == 0)                                                        // If Garage Air Temp is NOT calling,
        {
            Out[9] = 0;                                                         // turn OFF Garage Floor Out
        }
        
        DeckFloorOut =          Out[1];
        UtilityRoomFloorOut =   Out[2];
        EntranceFloorOut =      Out[3];
        MasterBathFloorOut =    Out[4];
        OfficeFloorOut =        Out[5];
        CraftRoomFloorOut =     Out[6];
        SEBasementFloorOut =    Out[7]; 
        MediaRoomFloorOut =     Out[8];
        GarageFloorOut =        Out[9];

// ******************************************************************************
        if(previousLoopCounter != loopCounter)
        {
            LCD_Clear();
            mainTimer = 0;
            previousLoopCounter = loopCounter;
        }

        
        if(loopCounter < 11)
        {
            LCD_Set_Cursor(0,0);                                                //LCD Line 0 Display
            LCD_Write_String(desc[loopCounter]);
            LCDWriteStringXY(0,13,"Loop ");
            LCD_Write_Int(loopCounter,2);
            
            LCDWriteStringXY(1,0,"Bs:");                                        //LCD Line 1 SetPoint Display
            LCDWriteDecIntXY(1,3,eepromGetData(setpoint[loopCounter]) + Bias[loopCounter],3);
            LCD_Write_Char(0);
            LCD_Write_Char('C');
            LCDWriteStringXY(1,10,"Set:");
            LCDWriteDecIntXY(1,14,eepromGetData(setpoint[loopCounter]),3);
            LCD_Write_Char(0);
            LCD_Write_Char(67);

            LCDWriteStringXY(2,0,"Temp:");                                      //LCD Line 2 Temperature Display
            LCDWriteDecIntXY(2,5,Temp[loopCounter],3);
            LCD_Write_Char(0);
            LCD_Write_Char(67);

            LCDWriteStringXY(2,12,"Db:");                                       //LCD Line 2 Deadband Display
            LCDWriteDecIntXY(2,15,eepromGetData(deadband[loopCounter]),2);
            LCD_Write_Char(0);
            LCD_Write_Char(67);
            
            LCDWriteIntXY(3,0,outStateCounter[loopCounter],5);
            
            LCDWriteStringXY(3,6,"On: ");                                       //LCD Line 3 Out Display
            
            if(outState[loopCounter] == 1)
            {
                LCD_Write_Char('Y');
            }
            
            else
            {
                LCD_Write_Char('N');
            }

            LCDWriteStringXY(3,12,"FOn: ");
            
            if(outState[loopCounter] == 1 || Out[loopCounter] == 0)
            {
                LCD_Write_Char('N');
            }
            
            else
            {
                LCD_Write_Char('Y');
            }
        }

        if(loopCounter == 11)
        {
            if(mainTimer < 10)
            {
            LCDWriteStringXY(0,0,"Output loop counters");
            }
            if(mainTimer >= 10)
            {
            LCDWriteStringXY(0,0,"Hold Cancel to Reset");
            }
            
            LCDWriteIntXY(1,0,outStateCounter[0],4);
            LCDWriteIntXY(1,5,outStateCounter[1],4);
            LCDWriteIntXY(1,10,outStateCounter[2],4);
            LCDWriteIntXY(1,15,outStateCounter[3],4);
            LCDWriteIntXY(2,0,outStateCounter[4],4);
            LCDWriteIntXY(2,5,outStateCounter[5],4);
            LCDWriteIntXY(2,10,outStateCounter[6],4);
            LCDWriteIntXY(2,15,outStateCounter[7],4);
            LCDWriteIntXY(3,0,outStateCounter[8],4);
            LCDWriteIntXY(3,5,outStateCounter[9],4);
            LCDWriteIntXY(3,10,outStateCounter[10],4);
            LCD_Set_Cursor(3,15);
//            LCD_Write_2VDec_Int(421872/internalBGV,3);                          // Board with Green LCD's
            LCD_Write_2VDec_Int(405070/internalBGV,3);                          // Board with Blue LCD's

            if(TestKey == KEY_CANCEL)
            {
                reset += 1;
                
                if(reset > 10)
                {
                    for(i=0;i<11;i++)
                    {
                        outStateCounter[i]= 0;
                        reset = 0;
                    }
                }
            }
            else
            {
                reset -= 1;
                if(reset < 0)
                {
                    reset = 0;
                }
            }
        }
        
        if(loopCounter == 12)
        {
            if(powerFail == 1)
            {
                if(toggle == 1)
                {
                    LCDWriteIntXY(0,0,time.year,2);
                    LCDWriteStringXY(0,2,"/");
                    LCDWriteIntXY(0,3,time.month,2);
                    LCDWriteStringXY(0,5,"/");
                    LCDWriteIntXY(0,6,time.day,2);
                    LCDWriteStringXY(0,9,WeekDay[time.weekday]);
                    LCDWriteIntXY(0,12,time.hour,2);
                    LCDWriteStringXY(0,14,":");
                    LCDWriteIntXY(0,15,time.minute,2);
                    LCDWriteStringXY(0,17,":");
                    LCDWriteIntXY(0,18,time.second,2);
                }
                
                else 
                {
                    LCDWriteStringXY(0,0,"                    ");
                }
            }
            
            else
            {
                LCDWriteIntXY(0,0,time.year,2);
                LCDWriteStringXY(0,2,"/");
                LCDWriteIntXY(0,3,time.month,2);
                LCDWriteStringXY(0,5,"/");
                LCDWriteIntXY(0,6,time.day,2);
                LCDWriteStringXY(0,9,WeekDay[time.weekday]);
                LCDWriteIntXY(0,12,time.hour,2);
                LCDWriteStringXY(0,14,":");
                LCDWriteIntXY(0,15,time.minute,2);
                LCDWriteStringXY(0,17,":");
                LCDWriteIntXY(0,18,time.second,2);
            }
               
/*            LCDWriteStringXY(1,0,"X Pos:");
            LCDWriteIntXY(1,7,x,5);
            LCDWriteStringXY(1,13,"Col:");
            LCDWriteIntXY(1,18,col,1);

            LCDWriteStringXY(2,0,"Y Pos:");
            LCDWriteIntXY(2,7,y,5);
            LCDWriteStringXY(2,13,"Row:");
            LCDWriteIntXY(2,18,row,1);
*/
            if(mainTimer <= 8)
            {
                LCDWriteStringXY(1,0,"OutSide Temp:");
                LCDWriteSignedDecIntXY(1,13,OutAirTemp,3);
                LCD_Write_Char(0);
                LCD_Write_Char(67);
//                LCDWriteSignedDecIntXY(2,0,ADCRead(6),6);
                LCDWriteStringXY(2,0,"Enter Key Sets Time ");
                LCDWriteStringXY(3,0,"Menu Key Sets Temp ");
            }
            
            if(mainTimer > 8 && mainTimer <= 16)
            {
                LCDWriteStringXY(1,0,"OutSide Temp:");
                LCDWriteSignedDecIntXY(1,13,OutAirTemp,3);
                LCD_Write_Char(0);
                LCD_Write_Char(67);
                LCDWriteStringXY(2,0," <- / -> Keys page ");
                LCDWriteStringXY(3,0," through Loop Info ");
            }
            
            if(mainTimer > 16 && mainTimer <= 20)
            {
                LCDWriteStringXY(1,0,"Left Key to display ");
                LCDWriteStringXY(2,0," all Loop Run-time  ");
                LCDWriteStringXY(3,0,"  Info on One Page ");
            }
        }
        

        if(mainTimer > 19)
        {
            mainTimer = 0;
//            loopCounter = 12;
        }
// ******************************************************************************
        TestKey = menuRead();
// ******************************************************************************
        heartBeat();                                                            // HeartBeat displays the HeartBeat on the LCD,
// ******************************************************************************  but, also increments mainTimer every second 
     
        if(TestKey == KEY_NONE)             // If no key is pressed for 60 seconds
        {                                   // Turn OFF the LCD Backlight
            backLightTimer += 1;
        }
        
        else
        {
            backLightTimer = 0;
        }
        
        if (backLightTimer < 4450)
        {
            backLightOn = 1;
            
        }
        else
        {
            backLightTimer = 4450;
            backLightOn = 0;
        }
            
        
        if (TestKey == KEY_ENTER)
        {
//            TestKey = 9;
            SetTime();
        }

        if (TestKey == KEY_RESET_LCD)
        {
            LCD_Cmd(0x08);
            LCD_Cmd(0x00);
            LCD_Cmd(0x0C|0);      //Enable Display ON with style selected (BLINK, ULINE, BLUL, or NONE))
            LCD_Cmd(0x00);
        }

        if(TestKey == KEY_LEFT)
        {
            loopCounter -=1;
            
            if(loopCounter < 0)
            {
                loopCounter = 12;
            }
        }

        if(TestKey == KEY_RIGHT)
        {
            loopCounter +=1;
            
            if(loopCounter >12)
            {
                loopCounter = 0;
            }
        }

        if (TestKey == KEY_MENU)
        {
            signed char choice = 5;

            while(TestKey != KEY_ENTER)
            {
                TestKey = menuRead();
                
                if(timer > 1000)
                {
                    timer = 0;
                    goto Exit;                                                  //This uses less memory than TestKey = KEY_ENTER
                    
//                    TestKey = KEY_ENTER;                                      // This functions fine, but forces a write to EEProm
                }

                switch(TestKey)
                {
                    case KEY_DOWN:
                    {
                        choice -=1;
                            
                        if (choice < 0)
                        {
                            choice = 0;
                        }
                    }
                    break;

                    case KEY_LEFT:
                    {
                        choice -=1;
                            
                        if (choice < 0)
                        {
                            choice = 0;
                        }
                    }
                    break;
                        
                    case KEY_UP:
                    {
                        choice += 1;
                            
                        if(choice > 10)
                        {
                            choice = 10;
                        }
                    }
                    break;
                        
                    case KEY_RIGHT:
                    {
                        choice += 1;
                            
                        if(choice > 10)
                        {
                            choice = 10;
                        }
                    }
                    break;
                    
                    case KEY_CANCEL:
                    {
                        goto Exit;
                    }
                    break;
                        
                }

                if(timer < 2)
                {
                    LCD_Clear();
                }

                LCD_Set_Cursor(0,0);
                LCD_Write_String("Set Temperature for");
                LCD_Set_Cursor(1,0);
                LCD_Write_String(desc[choice]);
                LCDWriteStringXY(2,0,"Up/Dn Keys to change");
                LCDWriteStringXY(3,0,"Enter Key for Yes   ");
                
                heartBeat();                                                    // HeartBeat displays the HeartBeat on the LCD,
                                                                                // but, also increments mainTimer every second
                timer += 1;
            }
            
//            TestKey = 9;
            
            LCD_Clear();


            LCD_Set_Cursor(0,0);
            LCD_Write_String(desc[choice]);
            LCDWriteStringXY(0,strlen(desc[choice]),"Set Tmp");
            eepromPutData(setpoint[choice], TempSetpoint(eepromGetData(setpoint[choice])));
            
            LCD_Set_Cursor(2,0);
            LCD_Write_String(desc[choice]);
            LCDWriteStringXY(2,strlen(desc[choice]),"Set DB");
            eepromPutData(deadband[choice], SetDeadband(eepromGetData(deadband[choice])));            

            LCD_Clear();

            LCD_Set_Cursor(0,0);
            LCD_Write_String(desc[choice]);
            LCDWriteStringXY(0,strlen(desc[choice]),"15 Bias");
            eepromPutData(biasNeg15[choice], SetBiasNeg15(eepromGetData(biasNeg15[choice])));

            LCD_Set_Cursor(2,0);
            LCD_Write_String(desc[choice]);
            LCDWriteStringXY(2,strlen(desc[choice]),"25 Bias");
            eepromPutData(biasNeg25[choice], SetBiasNeg25(eepromGetData(biasNeg25[choice])));
            
            Exit:
                        
            LCD_Clear();
        }
// ******************************************************************************
        ClrWdt();                                                               //Clr (Re-Set) the WatchDog Timer
    }
    return(0);
}