St7920 problem - move text and picture to otherside

Hi.
I using ST7920 and Arduino nano. . I used the u8g library and its commands to launch ST7920+Arduino Nano . The problem I have is that when I run the code, everything is displayed correctly at first, but after a few minutes, the image shifts to one side, and the problem is solved only by disconnecting the power supply or resetting the LCD reset pin, but after a few minutes this problem repeats again.

my code:

//========== LCD ST7920 ========== Begin
#include "U8glib.h"
//U8GLIB_ST7920_128X64_4X u8g(10);
//U8GLIB_ST7920_128X64_1X u8g(10);
U8GLIB_ST7920_128X64 u8g(13, 11, 10, U8G_PIN_NONE);                  // SPI Com: SCK = en = 13, MOSI = rw = 11, CS = di = 0

//========== LCD ST7920 ========== End

//=========   Buzzer   ========== Begin
const int BuzzerPin =12 ;     // Buzzer
//=========   Buzzer   ========== End

//=========   Thermometr-Max6675   ========== Begin
#include <max6675.h>
const char DEGREE_SYMBOL[] = { 0xB0, '\0' };
int soPin1 = 4;// SO=Serial Out
int csPin1 = 5;// CS = chip select CS pin
int sckPin1 = 6;// SCK = Serial Clock pin
MAX6675 thermocouple1(sckPin1, csPin1, soPin1);// create instance object of MAX6675

int soPin2 = 7;// SO=Serial Out
int csPin2 = 8;// CS = chip select CS pin
int sckPin2 = 9;// SCK = Serial Clock pin
MAX6675 thermocouple2(sckPin2, csPin2, soPin2);// create instance object of MAX6675

int Temp1,Temp2;        // Thermostate Tempretures(Degree Celeciuse)
//=========   Thermometr-Max6675   ========== End

//=========   Rotary Encoder   ========== Begin
int encoder_clockP = A2;
int encoder_data = A1;
int encoder_switch=A0;

int encoder_count = 0;
int c = HIGH;
int cLast = HIGH;
int d = HIGH;
//=========   Rotary Encoder   ========== End

//-------------------------- Global Variables --------------------------------

int Digit1_Min1_Set=0,Digit2_Min1_Set=0,Digit1_Sec1_Set=0,Digit2_Sec1_Set=0;  //Timer 1 Min. and Sec. Setting for Operation
int Digit1_Min2_Set=0,Digit2_Min2_Set=0,Digit1_Sec2_Set=0,Digit2_Sec2_Set=0;  //Timer 2 Min. and Sec. Setting for Operation
int TempSet1,TempSet2;  //Temp. Setting for Operation





int CycleNo=0;


 
//-------------------------- Other Functions ---------------------------------
//===========================================================
//DisplayData
//===========================================================
void DisplayData(){
   unsigned long tik_mili=1000;
   u8g.firstPage();  
  do {
    u8g.drawFrame(1,2,126,62);
    u8g.drawLine(62,2,62,62);
    u8g.drawLine(1,25,126,25);
    u8g.setFont(u8g_font_6x10);

//-------------- temp -----------    
    u8g.drawStr( 20, 18, "Temp");
    u8g.setPrintPos(07,38);
    u8g.print(Temp1);
    //u8g.drawStr( 07, 38,char(Temp1));
    u8g.drawStr( 48, 38, DEGREE_SYMBOL);
    u8g.drawStr( 53, 38, "C");

    u8g.setPrintPos(07,58);
    u8g.print(Temp2);
    //u8g.drawStr( 07, 58,"000.00");// Temp2);
    u8g.drawStr( 48, 58, DEGREE_SYMBOL);
    u8g.drawStr( 53, 58, "C");
    
//--------------time ------------
    u8g.drawStr( 83, 18, "Time");
    
    u8g.drawStr( 70, 38, "00");
    u8g.drawStr( 91, 38, ":");
    u8g.drawStr( 102, 38, "00");

    u8g.drawStr( 70, 58, "00");
    u8g.drawStr( 91, 58, ":");
    u8g.drawStr( 102, 58, "00");

  } while( u8g.nextPage() );
  //delay(1000);
  //clearLCD();
}
//===========================================================
//ClearLCD
//===========================================================
void clearLCD(){
    u8g.firstPage();  
    do {
    } while( u8g.nextPage() );
}
//===========================================================
//------- read Termocuple function -------
//===========================================================
void ReadTemperature()
{
  Temp1=thermocouple1.readCelsius();
  Temp2=thermocouple2.readCelsius();
  delay(1000);
}

//===========================================================
//------- Get Timers Setting function -------
//===========================================================
void GetTimeSetting(){
  
  GetTimeSettingDisplay(8);
}
//===========================================================
//------- Get Timers Setting Display function -------
//===========================================================
 void GetTimeSettingDisplay(int mode){
  int x,y;  //frame around of selected digit
  int fcolor[8];
  for (int i=0;i<8;i++) {
    fcolor[i]=0;
  }
  fcolor[mode-1]=1;
  
  switch(mode){
    case 2:
    {
      x=63;
      y=29;
      break;
    }
    case 3:
    {
      x=77;
      y=29;
      break;
    }
    case 4:
    {
      x=84;
      y=29;
      break;
    }
    case 5:
    {
      x=56;
      y=49;
      break;
    }
    case 6:
    {
      x=63;
      y=49;
      break;
    }
    case 7:
    {
      x=77;
      y=49;
      break;
    }
    case 8:
    {
      x=84;
      y=49;
      break;
    }
    default:
    {
      x=56;
      y=29;
    }
  }
  u8g.firstPage();  
  do {
    u8g.drawFrame(1,2,126,62);
    u8g.drawLine(1,25,126,25);
    u8g.setFont(u8g_font_6x10);
    u8g.drawBox(x,y,9,11);

//-------------- temp -----------    
    u8g.drawStr( 7, 18, "Enter Time Settings");
    u8g.setPrintPos(07,38);
    u8g.DefaultForegroundColor(0);
    u8g.print("Time1:");
    u8g.setPrintPos( 58, 38);
    u8g.DefaultForegroundColor(fcolor[1-1]);
    u8g.print(String(Digit1_Min1_Set));
    u8g.setPrintPos( 65, 38);
    u8g.DefaultForegroundColor(fcolor[2-1]);
    u8g.print(String(Digit2_Min1_Set));
    u8g.setPrintPos( 72, 38);
    u8g.DefaultForegroundColor(0);
    u8g.print(":");
    u8g.setPrintPos( 79, 38);
    u8g.DefaultForegroundColor(fcolor[3-1]);
    u8g.print(String(Digit1_Sec1_Set));
    u8g.setPrintPos( 86, 38);
    u8g.DefaultForegroundColor(fcolor[4-1]);
    u8g.print(String(Digit2_Sec1_Set));

    u8g.setPrintPos(07,58);
    u8g.DefaultForegroundColor(0);
    u8g.print("Time2:");
    u8g.setPrintPos( 58, 58);
    u8g.DefaultForegroundColor(fcolor[5-1]);
    u8g.print(String(Digit1_Min2_Set));
    u8g.setPrintPos( 65, 58);
    u8g.DefaultForegroundColor(fcolor[6-1]);
    u8g.print(String(Digit2_Min2_Set));
    u8g.setPrintPos( 72, 58);
    u8g.DefaultForegroundColor(0);
    u8g.print(":");
    u8g.setPrintPos( 79, 58);
    u8g.DefaultForegroundColor(fcolor[7-1]);
    u8g.print(String(Digit1_Sec2_Set));
    u8g.setPrintPos( 86, 58);
    u8g.DefaultForegroundColor(fcolor[8-1]);
    u8g.print(String(Digit2_Sec2_Set));
 

  } while( u8g.nextPage() );
}
//===========================================================
//------- Get Temp. Setting function -------
//===========================================================
 void GetTempSetting(){
  
 }
//-------------------------- Main Functions ---------------------------------
//------- SETUP function -------Begin
void setup() {
  Serial.begin(9600); 
//========== LCD ST7920 ========== Begin
  // assign default color value
  if ( u8g.getMode() == U8G_MODE_R3G3B2 ) {
    u8g.setColorIndex(255);     // white
  }
  else if ( u8g.getMode() == U8G_MODE_GRAY2BIT ) {
    u8g.setColorIndex(3);         // max intensity
  }
  else if ( u8g.getMode() == U8G_MODE_BW ) {
    u8g.setColorIndex(1);         // pixel on
  }
  else if ( u8g.getMode() == U8G_MODE_HICOLOR ) {
    u8g.setHiColorByRGB(255,255,255);
  }
//========== LCD ST7920 ========== End

//========== Buzzer pin setting ========== begin
  pinMode(BuzzerPin,OUTPUT);
//========== Buzzer pin setting ==========  end

//========== Rotary Encoder ========== begin
 pinMode (encoder_clockP,INPUT_PULLUP);
 pinMode (encoder_data,INPUT_PULLUP);
 pinMode (encoder_switch,INPUT_PULLUP);
//========== Rotary Encoder ========== end

clearLCD();
CycleNo=0;
}
//------- SETUP function -------End

//-----------------------------------------------------------
//------- LOOP function -------Begin
void loop() {
  if(CycleNo<13){
    GetTimeSetting();
    GetTempSetting();
  }else 
  {
    ReadTemperature();
    DisplayData();
  }
}

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.