HElP DS3231 12 Hour mode

Hello

i am using ds3231 module ,very fast i use d1307 ,1307 is time proble so i decide to go for ds3231 ,its works with ds1307 code , I need to 12 hour mode how to do this ,help me please !!

this is my code

#include <Wire.h>
#include<EEPROM.h>
#include <RTClib.h>
RTC_DS1307 RTC;


bool Century=false;
bool h12;
bool PM;
byte ADay, AHour, AMinute, ASecond, ABits;
bool ADy, A12h, Apm;
int temp, inc, hours1, minut, add = 11;
int HOUR, MINUT, SECOND;
int latchPin = 3; //pin 12 on the 595 o3 3
int dataPin = 4; //pin 14 on the 595 or 4
int clockPin = 2; //pin 11 on the 595 or 2
int shift = 256;
int units, tens, hundreds, thousands;
int x;
int y;


void setup() {
Serial.begin(9600);
pinMode(latchPin, OUTPUT);
pinMode(dataPin, OUTPUT);
pinMode(clockPin, OUTPUT);

Wire.begin();
RTC.begin();
if (!RTC.isrunning())
{
  RTC.adjust(DateTime(__DATE__, __TIME__));
}
}

void loop() {
int temp = 0, val = 1, temp4;
DateTime now = RTC.now();
HOUR = now.hour();
MINUT = now.minute();
//Serial.println(MINUT);



if (now.hour() > 12 )
{
hourNow = now.hour() - 12;
}
else
{
hourNow = now.hour();
}
if (HOUR < 10)
{
  hundreds = HOUR;
  thousands  = HOUR/10;
}
else if (HOUR >=  10 && HOUR < 24)
{
  hundreds = HOUR % 10;
  thousands = HOUR / 10;
}
if (MINUT <= 9)
{
  units = MINUT;
  tens = MINUT/10;
}

else if (MINUT > 9 && MINUT <= 60)
{
  units = MINUT % 10;
  tens = MINUT / 10;
}

switch (units)
{
  case 0:
    //0
    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, MSBFIRST, shift * 8  >> 8 );
    shiftOut(dataPin, clockPin, MSBFIRST, shift * 8 + 192 );
    digitalWrite(latchPin, HIGH);
    break;
  case 1:
    //1
    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, MSBFIRST, shift * 8  >> 8 );
    shiftOut(dataPin, clockPin, MSBFIRST, shift * 8 + 249);
    digitalWrite(latchPin, HIGH);
    break;
  case 2:
    //2
    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, MSBFIRST, shift * 8  >> 8 );
    shiftOut(dataPin, clockPin, MSBFIRST, shift * 8 + 164);
    digitalWrite(latchPin, HIGH);
    break;
  case 3:
    //3
    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, MSBFIRST, shift * 8 >> 8 );
    shiftOut(dataPin, clockPin, MSBFIRST, shift * 8 + 176);
    digitalWrite(latchPin, HIGH);
    break;
  case 4:
    //4
    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, MSBFIRST, shift * 8 >> 8 );
    shiftOut(dataPin, clockPin, MSBFIRST, shift * 8 + 153);
    digitalWrite(latchPin, HIGH);
    break;
  case 5:
    //5
    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, MSBFIRST, shift * 8 >> 8 );
    shiftOut(dataPin, clockPin, MSBFIRST, shift * 8 + 146);
    digitalWrite(latchPin, HIGH);
    break;
  case 6:
    //6
    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, MSBFIRST, shift * 8   >> 8 );
    shiftOut(dataPin, clockPin, MSBFIRST, shift * 8 + 130);
    digitalWrite(latchPin, HIGH);
    break;
  case 7:
    //7
    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, MSBFIRST, shift * 8  >> 8 );
    shiftOut(dataPin, clockPin, MSBFIRST, shift * 8 + 248);
    digitalWrite(latchPin, HIGH);
    break;
  case 8:
    //8
    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, MSBFIRST, shift * 8  >> 8 );
    shiftOut(dataPin, clockPin, MSBFIRST, shift * 8 + 128);
    digitalWrite(latchPin, HIGH);
    break;
  case 9:
    //9
    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, MSBFIRST, shift * 8  >> 8 );
    shiftOut(dataPin, clockPin, MSBFIRST, shift * 8 + 144);
    digitalWrite(latchPin, HIGH);
    break;
}
delay(1);


switch (tens)
{
  case 0:
    //0
    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, MSBFIRST, shift * 4  >> 8 );
    shiftOut(dataPin, clockPin, MSBFIRST, shift * 4 + 192 );
    digitalWrite(latchPin, HIGH);
    break;
  case 1:
    //1
    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, MSBFIRST, shift * 4   >> 8 );
    shiftOut(dataPin, clockPin, MSBFIRST, shift * 4 + 249);
    digitalWrite(latchPin, HIGH);
    break;
  case 2:
    //2
    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, MSBFIRST, shift * 4   >> 8 );
    shiftOut(dataPin, clockPin, MSBFIRST, shift * 4 + 164);
    digitalWrite(latchPin, HIGH);
    break;
  case 3:
    //3
    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, MSBFIRST, shift * 4   >> 8 );
    shiftOut(dataPin, clockPin, MSBFIRST, shift * 4 + 176);
    digitalWrite(latchPin, HIGH);
    break;
  case 4:
    //4
    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, MSBFIRST, shift * 4 >> 8 );
    shiftOut(dataPin, clockPin, MSBFIRST, shift * 4 + 153);
    digitalWrite(latchPin, HIGH);
    break;
  case 5:
    //5
    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, MSBFIRST, shift * 4   >> 8 );
    shiftOut(dataPin, clockPin, MSBFIRST, shift * 4 + 146);
    digitalWrite(latchPin, HIGH);
    break;
  
}
delay(1);

switch (hundreds)
{
  case 0:
    //0
    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, MSBFIRST, shift * 2  >> 8 );
    shiftOut(dataPin, clockPin, MSBFIRST, shift * 2 + 64 );
    digitalWrite(latchPin, HIGH);
    break;
  case 1:
    //1
    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, MSBFIRST, shift * 2  >> 8 );
    shiftOut(dataPin, clockPin, MSBFIRST, shift * 2 + 121);
    digitalWrite(latchPin, HIGH);

    break;
  case 2:
    //2
    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, MSBFIRST, shift * 2  >> 8 );
    shiftOut(dataPin, clockPin, MSBFIRST, shift * 2 + 36);
    digitalWrite(latchPin, HIGH);
    break;
  case 3:
    //3
    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, MSBFIRST, shift * 2 >> 8 );
    shiftOut(dataPin, clockPin, MSBFIRST, shift * 2 + 48);
    digitalWrite(latchPin, HIGH);
    break;
  case 4:
    //4
    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, MSBFIRST, shift * 2 >> 8 );
    shiftOut(dataPin, clockPin, MSBFIRST, shift * 2 + 25);
    digitalWrite(latchPin, HIGH);
    break;
  case 5:
    //5
    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, MSBFIRST, shift * 2   >> 8 );
    shiftOut(dataPin, clockPin, MSBFIRST, shift * 2 + 18);
    digitalWrite(latchPin, HIGH);
    break;
  case 6:
    //6
    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, MSBFIRST, shift * 2   >> 8 );
    shiftOut(dataPin, clockPin, MSBFIRST, shift * 2 + 2);
    digitalWrite(latchPin, HIGH);
    break;
  case 7:
    //7
    digitalWrite(latchPin, LOW);

delay(1);


}

Moderator edit:
</mark> <mark>[code]</mark> <mark>

</mark> <mark>[/code]</mark> <mark>
tags added.

I am using ds3231 its work my previous ds1307 code , i need to modify this code for 12 hour format how to do this please help :confused: :confused:

#include <Wire.h>



#include<EEPROM.h>
#include <RTClib.h>
RTC_DS1307 RTC;


bool Century=false;
bool h12;
bool PM;
byte ADay, AHour, AMinute, ASecond, ABits;
bool ADy, A12h, Apm;
int temp, inc, hours1, minut, add = 11;
int HOUR, MINUT, SECOND;
int latchPin = 3; //pin 12 on the 595 o3 3
int dataPin = 4; //pin 14 on the 595 or 4
int clockPin = 2; //pin 11 on the 595 or 2
int shift = 256;
int units, tens, hundreds, thousands;
int x;
int y;


void setup() {
  Serial.begin(9600);
  pinMode(latchPin, OUTPUT);
  pinMode(dataPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
 
  Wire.begin();
  RTC.begin();
  if (!RTC.isrunning())
  {
    RTC.adjust(DateTime(__DATE__, __TIME__));
  }
}

void loop() {
  int temp = 0, val = 1, temp4;
  DateTime now = RTC.now();
  HOUR = now.hour();
  MINUT = now.minute();
  //Serial.println(MINUT);



  

  if (HOUR < 10)
  {
    hundreds = HOUR;
    thousands  = HOUR/10;
  }
  else if (HOUR >=  10 && HOUR < 24)
  {
    hundreds = HOUR % 10;
    thousands = HOUR / 10;
  }
  if (MINUT <= 9)
  {
    units = MINUT;
    tens = MINUT/10;
  }

  else if (MINUT > 9 && MINUT <= 60)
  {
    units = MINUT % 10;
    tens = MINUT / 10;
  }

  switch (units)
  {
    case 0:
      //0
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 8  >> 8 );
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 8 + 192 );
      digitalWrite(latchPin, HIGH);
      break;
    case 1:
      //1
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 8  >> 8 );
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 8 + 249);
      digitalWrite(latchPin, HIGH);
      break;
    case 2:
      //2
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 8  >> 8 );
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 8 + 164);
      digitalWrite(latchPin, HIGH);
      break;
    case 3:
      //3
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 8 >> 8 );
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 8 + 176);
      digitalWrite(latchPin, HIGH);
      break;
    case 4:
      //4
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 8 >> 8 );
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 8 + 153);
      digitalWrite(latchPin, HIGH);
      break;
    case 5:
      //5
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 8 >> 8 );
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 8 + 146);
      digitalWrite(latchPin, HIGH);
      break;
    case 6:
      //6
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 8   >> 8 );
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 8 + 130);
      digitalWrite(latchPin, HIGH);
      break;
    case 7:
      //7
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 8  >> 8 );
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 8 + 248);
      digitalWrite(latchPin, HIGH);
      break;
    case 8:
      //8
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 8  >> 8 );
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 8 + 128);
      digitalWrite(latchPin, HIGH);
      break;
    case 9:
      //9
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 8  >> 8 );
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 8 + 144);
      digitalWrite(latchPin, HIGH);
      break;
  }
  delay(1);


  switch (tens)
  {
    case 0:
      //0
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 4  >> 8 );
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 4 + 192 );
      digitalWrite(latchPin, HIGH);
      break;
    case 1:
      //1
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 4   >> 8 );
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 4 + 249);
      digitalWrite(latchPin, HIGH);
      break;
    case 2:
      //2
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 4   >> 8 );
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 4 + 164);
      digitalWrite(latchPin, HIGH);
      break;
    case 3:
      //3
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 4   >> 8 );
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 4 + 176);
      digitalWrite(latchPin, HIGH);
      break;
    case 4:
      //4
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 4 >> 8 );
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 4 + 153);
      digitalWrite(latchPin, HIGH);
      break;
    case 5:
      //5
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 4   >> 8 );
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 4 + 146);
      digitalWrite(latchPin, HIGH);
      break;
    
  }
  delay(1);

  switch (hundreds)
  {
    case 0:
      //0
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 2  >> 8 );
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 2 + 64 );
      digitalWrite(latchPin, HIGH);
      break;
    case 1:
      //1
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 2  >> 8 );
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 2 + 121);
      digitalWrite(latchPin, HIGH);

      break;
    case 2:
      //2
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 2  >> 8 );
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 2 + 36);
      digitalWrite(latchPin, HIGH);
      break;
    case 3:
      //3
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 2 >> 8 );
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 2 + 48);
      digitalWrite(latchPin, HIGH);
      break;
    case 4:
      //4
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 2 >> 8 );
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 2 + 25);
      digitalWrite(latchPin, HIGH);
      break;
    case 5:
      //5
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 2   >> 8 );
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 2 + 18);
      digitalWrite(latchPin, HIGH);
      break;
    case 6:
      //6
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 2   >> 8 );
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 2 + 2);
      digitalWrite(latchPin, HIGH);
      break;
    case 7:
      //7
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 2  >> 8 );
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 2 + 120);
      digitalWrite(latchPin, HIGH);
      break;
    case 8:
      //8
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 2  >> 8 );
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 2 + 0);
      digitalWrite(latchPin, HIGH);
      break;
    case 9:
      //9
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 2  >> 8 );
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 2 + 16);
      digitalWrite(latchPin, HIGH);
      break;

  }
  delay(1);
 
  switch (thousands)
  {
    case 0:
      //0
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, shift   >> 8 );
      shiftOut(dataPin, clockPin, MSBFIRST, shift  + 192 );
      digitalWrite(latchPin, HIGH);
      //delay(500);
      break;

  }
  delay(1);
 

}

Moderator edit:
</mark> <mark>[code]</mark> <mark>

</mark> <mark>[/code]</mark> <mark>
tags added.

i am using ds3231 module

But you are using the RTClib library, and creating an instance of the RTC_DS1307 class in the code that you FAILED to post properly.

Why?

http://hasib.cf/2017/03/16/ds3231-12hour-mode-clock-with-code/

here is code
:

#include <Wire.h>
#include<EEPROM.h>
#include <RTClib.h>

#include <TimeLib.h>
RTC_DS1307 RTC;

bool Century=false;
bool h12;
bool PM;
byte ADay, AHour, AMinute, ASecond, ABits;
bool ADy, A12h, Apm;
int temp, inc, hours1, minut, add = 11;
int HOUR, MINUT, SECOND;
int latchPin = 3; //pin 12 on the 595 o3 3
int dataPin = 4; //pin 14 on the 595 or 4
int clockPin = 2; //pin 11 on the 595 or 2
int shift = 256;
int units, tens, hundreds, thousands;
int x;
int y;


void setup() {
  Serial.begin(9600);
  pinMode(latchPin, OUTPUT);
  pinMode(dataPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
 
  Wire.begin();
  RTC.begin();
  if (!RTC.isrunning())
  {
    RTC.adjust(DateTime(__DATE__, __TIME__));
  }
}

void loop() {
  int temp = 0, val = 1, temp4;
  DateTime now = RTC.now();
  HOUR = now.hour();
  MINUT = now.minute();
  //Serial.println(MINUT);


if (now.hour() > 12 )
{
HOUR  = now.hour() - 12;
}
else
{
HOUR  = now.hour();
}
  

  if (HOUR < 10)
  {
    hundreds = HOUR;
    thousands  = HOUR/10;
  }
  else if (HOUR >=  10 && HOUR < 24)
  {
    hundreds = HOUR % 10;
    thousands = HOUR / 10;
  }
  if (MINUT <= 9)
  {
    units = MINUT;
    tens = MINUT/10;
  }

  else if (MINUT > 9 && MINUT <= 60)
  {
    units = MINUT % 10;
    tens = MINUT / 10;
  }

  switch (units)
  {
    case 0:
      //0
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 8  >> 8 );
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 8 + 192 );
      digitalWrite(latchPin, HIGH);
      break;
    case 1:
      //1
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 8  >> 8 );
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 8 + 249);
      digitalWrite(latchPin, HIGH);
      break;
    case 2:
      //2
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 8  >> 8 );
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 8 + 164);
      digitalWrite(latchPin, HIGH);
      break;
    case 3:
      //3
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 8 >> 8 );
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 8 + 176);
      digitalWrite(latchPin, HIGH);
      break;
    case 4:
      //4
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 8 >> 8 );
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 8 + 153);
      digitalWrite(latchPin, HIGH);
      break;
    case 5:
      //5
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 8 >> 8 );
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 8 + 146);
      digitalWrite(latchPin, HIGH);
      break;
    case 6:
      //6
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 8   >> 8 );
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 8 + 130);
      digitalWrite(latchPin, HIGH);
      break;
    case 7:
      //7
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 8  >> 8 );
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 8 + 248);
      digitalWrite(latchPin, HIGH);
      break;
    case 8:
      //8
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 8  >> 8 );
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 8 + 128);
      digitalWrite(latchPin, HIGH);
      break;
    case 9:
      //9
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 8  >> 8 );
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 8 + 144);
      digitalWrite(latchPin, HIGH);
      break;
  }
  delay(1);


  switch (tens)
  {
    case 0:
      //0
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 4  >> 8 );
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 4 + 192 );
      digitalWrite(latchPin, HIGH);
      break;
    case 1:
      //1
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 4   >> 8 );
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 4 + 249);
      digitalWrite(latchPin, HIGH);
      break;
    case 2:
      //2
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 4   >> 8 );
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 4 + 164);
      digitalWrite(latchPin, HIGH);
      break;
    case 3:
      //3
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 4   >> 8 );
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 4 + 176);
      digitalWrite(latchPin, HIGH);
      break;
    case 4:
      //4
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 4 >> 8 );
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 4 + 153);
      digitalWrite(latchPin, HIGH);
      break;
    case 5:
      //5
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 4   >> 8 );
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 4 + 146);
      digitalWrite(latchPin, HIGH);
      break;
    
  }
  delay(1);

  switch (hundreds)
  {
    case 0:
      //0
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 2  >> 8 );
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 2 + 64 );
      digitalWrite(latchPin, HIGH);
      break;
    case 1:
      //1
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 2  >> 8 );
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 2 + 121);
      digitalWrite(latchPin, HIGH);

      break;
    case 2:
      //2
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 2  >> 8 );
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 2 + 36);
      digitalWrite(latchPin, HIGH);
      break;
    case 3:
      //3
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 2 >> 8 );
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 2 + 48);
      digitalWrite(latchPin, HIGH);
      break;
    case 4:
      //4
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 2 >> 8 );
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 2 + 25);
      digitalWrite(latchPin, HIGH);
      break;
    case 5:
      //5
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 2   >> 8 );
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 2 + 18);
      digitalWrite(latchPin, HIGH);
      break;
    case 6:
      //6
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 2   >> 8 );
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 2 + 2);
      digitalWrite(latchPin, HIGH);
      break;
    case 7:
      //7
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 2  >> 8 );
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 2 + 120);
      digitalWrite(latchPin, HIGH);
      break;
    case 8:
      //8
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 2  >> 8 );
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 2 + 0);
      digitalWrite(latchPin, HIGH);
      break;
    case 9:
      //9
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 2  >> 8 );
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 2 + 16);
      digitalWrite(latchPin, HIGH);
      break;

  }
  delay(1);
 
  switch (thousands)
  
  delay(1);
 

}

Moderator edit:
</mark> <mark>[code]</mark> <mark>

</mark> <mark>[/code]</mark> <mark>
tags added.

You could try something as crude as after the following statement:
HOUR = now.hour();
adding this:

if (  HOUR > 12 ) HOUR = HOUR - 12 ;

A couple of comments about your code:

There is a huge amount of repetition.
Have you thought about putting the numbers which represent the digit patterns ( 192, 249. 164 etc.) in an array ? You could probably shorten the whole repeating sections to a few lines of code.

When you post code here, you should also use code tags so it displays nicely.

Details with scematics: http://hasib.cf/2017/03/16/ds3231-12hour-mode-clock-with-code/
here is code
:

#include <Wire.h>
#include<EEPROM.h>
#include <RTClib.h>

#include <TimeLib.h>
RTC_DS1307 RTC;

bool Century=false;
bool h12;
bool PM;
byte ADay, AHour, AMinute, ASecond, ABits;
bool ADy, A12h, Apm;
int temp, inc, hours1, minut, add = 11;
int HOUR, MINUT, SECOND;
int latchPin = 3; //pin 12 on the 595 o3 3
int dataPin = 4; //pin 14 on the 595 or 4
int clockPin = 2; //pin 11 on the 595 or 2
int shift = 256;
int units, tens, hundreds, thousands;
int x;
int y;


void setup() {
Serial.begin(9600);
pinMode(latchPin, OUTPUT);
pinMode(dataPin, OUTPUT);
pinMode(clockPin, OUTPUT);

Wire.begin();
RTC.begin();
if (!RTC.isrunning())
{
 RTC.adjust(DateTime(__DATE__, __TIME__));
}
}

void loop() {
int temp = 0, val = 1, temp4;
DateTime now = RTC.now();
HOUR = now.hour();
MINUT = now.minute();
//Serial.println(MINUT);


if (now.hour() > 12 )
{
HOUR  = now.hour() - 12;
}
else
{
HOUR  = now.hour();
}


if (HOUR < 10)
{
 hundreds = HOUR;
 thousands  = HOUR/10;
}
else if (HOUR >=  10 && HOUR < 24)
{
 hundreds = HOUR % 10;
 thousands = HOUR / 10;
}
if (MINUT <= 9)
{
 units = MINUT;
 tens = MINUT/10;
}

else if (MINUT > 9 && MINUT <= 60)
{
 units = MINUT % 10;
 tens = MINUT / 10;
}

switch (units)
{
 case 0:
   //0
   digitalWrite(latchPin, LOW);
   shiftOut(dataPin, clockPin, MSBFIRST, shift * 8  >> 8 );
   shiftOut(dataPin, clockPin, MSBFIRST, shift * 8 + 192 );
   digitalWrite(latchPin, HIGH);
   break;
 case 1:
   //1
   digitalWrite(latchPin, LOW);
   shiftOut(dataPin, clockPin, MSBFIRST, shift * 8  >> 8 );
   shiftOut(dataPin, clockPin, MSBFIRST, shift * 8 + 249);
   digitalWrite(latchPin, HIGH);
   break;
 case 2:
   //2
   digitalWrite(latchPin, LOW);
   shiftOut(dataPin, clockPin, MSBFIRST, shift * 8  >> 8 );
   shiftOut(dataPin, clockPin, MSBFIRST, shift * 8 + 164);
   digitalWrite(latchPin, HIGH);
   break;
 case 3:
   //3
   digitalWrite(latchPin, LOW);
   shiftOut(dataPin, clockPin, MSBFIRST, shift * 8 >> 8 );
   shiftOut(dataPin, clockPin, MSBFIRST, shift * 8 + 176);
   digitalWrite(latchPin, HIGH);
   break;
 case 4:
   //4
   digitalWrite(latchPin, LOW);
   shiftOut(dataPin, clockPin, MSBFIRST, shift * 8 >> 8 );
   shiftOut(dataPin, clockPin, MSBFIRST, shift * 8 + 153);
   digitalWrite(latchPin, HIGH);
   break;
 case 5:
   //5
   digitalWrite(latchPin, LOW);
   shiftOut(dataPin, clockPin, MSBFIRST, shift * 8 >> 8 );
   shiftOut(dataPin, clockPin, MSBFIRST, shift * 8 + 146);
   digitalWrite(latchPin, HIGH);
   break;
 case 6:
   //6
   digitalWrite(latchPin, LOW);
   shiftOut(dataPin, clockPin, MSBFIRST, shift * 8   >> 8 );
   shiftOut(dataPin, clockPin, MSBFIRST, shift * 8 + 130);
   digitalWrite(latchPin, HIGH);
   break;
 case 7:
   //7
   digitalWrite(latchPin, LOW);
   shiftOut(dataPin, clockPin, MSBFIRST, shift * 8  >> 8 );
   shiftOut(dataPin, clockPin, MSBFIRST, shift * 8 + 248);
   digitalWrite(latchPin, HIGH);
   break;
 case 8:
   //8
   digitalWrite(latchPin, LOW);
   shiftOut(dataPin, clockPin, MSBFIRST, shift * 8  >> 8 );
   shiftOut(dataPin, clockPin, MSBFIRST, shift * 8 + 128);
   digitalWrite(latchPin, HIGH);
   break;
 case 9:
   //9
   digitalWrite(latchPin, LOW);
   shiftOut(dataPin, clockPin, MSBFIRST, shift * 8  >> 8 );
   shiftOut(dataPin, clockPin, MSBFIRST, shift * 8 + 144);
   digitalWrite(latchPin, HIGH);
   break;
}
delay(1);


switch (tens)
{
 case 0:
   //0
   digitalWrite(latchPin, LOW);
   shiftOut(dataPin, clockPin, MSBFIRST, shift * 4  >> 8 );
   shiftOut(dataPin, clockPin, MSBFIRST, shift * 4 + 192 );
   digitalWrite(latchPin, HIGH);
   break;
 case 1:
   //1
   digitalWrite(latchPin, LOW);
   shiftOut(dataPin, clockPin, MSBFIRST, shift * 4   >> 8 );
   shiftOut(dataPin, clockPin, MSBFIRST, shift * 4 + 249);
   digitalWrite(latchPin, HIGH);
   break;
 case 2:
   //2
   digitalWrite(latchPin, LOW);
   shiftOut(dataPin, clockPin, MSBFIRST, shift * 4   >> 8 );
   shiftOut(dataPin, clockPin, MSBFIRST, shift * 4 + 164);
   digitalWrite(latchPin, HIGH);
   break;
 case 3:
   //3
   digitalWrite(latchPin, LOW);
   shiftOut(dataPin, clockPin, MSBFIRST, shift * 4   >> 8 );
   shiftOut(dataPin, clockPin, MSBFIRST, shift * 4 + 176);
   digitalWrite(latchPin, HIGH);
   break;
 case 4:
   //4
   digitalWrite(latchPin, LOW);
   shiftOut(dataPin, clockPin, MSBFIRST, shift * 4 >> 8 );
   shiftOut(dataPin, clockPin, MSBFIRST, shift * 4 + 153);
   digitalWrite(latchPin, HIGH);
   break;
 case 5:
   //5
   digitalWrite(latchPin, LOW);
   shiftOut(dataPin, clockPin, MSBFIRST, shift * 4   >> 8 );
   shiftOut(dataPin, clockPin, MSBFIRST, shift * 4 + 146);
   digitalWrite(latchPin, HIGH);
   break;
 
}
delay(1);

switch (hundreds)
{
 case 0:
   //0
   digitalWrite(latchPin, LOW);
   shiftOut(dataPin, clockPin, MSBFIRST, shift * 2  >> 8 );
   shiftOut(dataPin, clockPin, MSBFIRST, shift * 2 + 64 );
   digitalWrite(latchPin, HIGH);
   break;
 case 1:
   //1
   digitalWrite(latchPin, LOW);
   shiftOut(dataPin, clockPin, MSBFIRST, shift * 2  >> 8 );
   shiftOut(dataPin, clockPin, MSBFIRST, shift * 2 + 121);
   digitalWrite(latchPin, HIGH);

   break;
 case 2:
   //2
   digitalWrite(latchPin, LOW);
   shiftOut(dataPin, clockPin, MSBFIRST, shift * 2  >> 8 );
   shiftOut(dataPin, clockPin, MSBFIRST, shift * 2 + 36);
   digitalWrite(latchPin, HIGH);
   break;
 case 3:
   //3
   digitalWrite(latchPin, LOW);
   shiftOut(dataPin, clockPin, MSBFIRST, shift * 2 >> 8 );
   shiftOut(dataPin, clockPin, MSBFIRST, shift * 2 + 48);
   digitalWrite(latchPin, HIGH);
   break;
 case 4:
   //4
   digitalWrite(latchPin, LOW);
   shiftOut(dataPin, clockPin, MSBFIRST, shift * 2 >> 8 );
   shiftOut(dataPin, clockPin, MSBFIRST, shift * 2 + 25);
   digitalWrite(latchPin, HIGH);
   break;
 case 5:
   //5
   digitalWrite(latchPin, LOW);
   shiftOut(dataPin, clockPin, MSBFIRST, shift * 2   >> 8 );
   shiftOut(dataPin, clockPin, MSBFIRST, shift * 2 + 18);
   digitalWrite(latchPin, HIGH);
   break;
 case 6:
   //6
   digitalWrite(latchPin, LOW);
   shiftOut(dataPin, clockPin, MSBFIRST, shift * 2   >> 8 );
   shiftOut(dataPin, clockPin, MSBFIRST, shift * 2 + 2);
   digitalWrite(latchPin, HIGH);
   break;
 case 7:
   //7
   digitalWrite(latchPin, LOW);
   shiftOut(dataPin, clockPin, MSBFIRST, shift * 2  >> 8 );
   shiftOut(dataPin, clockPin, MSBFIRST, shift * 2 + 120);
   digitalWrite(latchPin, HIGH);
   break;
 case 8:
   //8
   digitalWrite(latchPin, LOW);
   shiftOut(dataPin, clockPin, MSBFIRST, shift * 2  >> 8 );
   shiftOut(dataPin, clockPin, MSBFIRST, shift * 2 + 0);
   digitalWrite(latchPin, HIGH);
   break;
 case 9:
   //9
   digitalWrite(latchPin, LOW);
   shiftOut(dataPin, clockPin, MSBFIRST, shift * 2  >> 8 );
   shiftOut(dataPin, clockPin, MSBFIRST, shift * 2 + 16);
   digitalWrite(latchPin, HIGH);
   break;

}
delay(1);

switch (thousands)

delay(1);


}

Moderator edit:
</mark> <mark>[code]</mark> <mark>

</mark> <mark>[/code]</mark> <mark>
tags added.

6v6gt: When you post code here, you should ......

..... not post the same question all over the forum.

DON'T CROSS-POST!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! http://forum.arduino.cc/index.php?topic=463088

DON'T CROSS-POST!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! http://forum.arduino.cc/index.php?topic=463088

DON'T CROSS-POST!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! http://forum.arduino.cc/index.php?topic=463088

pert: DON'T CROSS-POST!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! http://forum.arduino.cc/index.php?topic=463088

You didn't find the other 3? 5 posts, in 5 different parts of the forum, with the same code without code tags. We need a timeout from this dude.

It seems like there has been a major increase from the already high normal level of cross posting in the last couple weeks. I'm really sick of spending time trying to help someone only to notice when I browse the next section of the forum that someone else did the same answer or request for more information an hour earlier and I wasted my time.

Details with schematics:

Kindly, upload the schematics. It is missing!

pert: It seems like there has been a major increase from the already high normal level of cross posting in the last couple weeks. I'm really sick of spending time trying to help someone only to notice when I browse the next section of the forum that someone else did the same answer or request for more information an hour earlier and I wasted my time.

When I see a cross-post, I don't waste my time berating the crossposter, I just click report to moderator, type crosspost, hit submit and move on. Pretty quickly, usually, the posts are merged or deleted.

And learn How to post code properly

The moderators do respond amazingly quickly but there's inevitably some delay. I think it's helpful to reply so that other forum users coming across the post before the merge don't end up wasting their time.

GolamMostafa: Kindly, upload the schematics. It is missing!

Kindly be more selective in what you quote.

Many threads merged.