Ceas cu PCF8563 si afisaj LCD

Pornind de la articolul precedent vom adauga un display LCD ceasului realizat cu ajutorul circuitului PCF8563.

Displayul este pe magistrala I2C si se conecteaza conform acestui articol.

O poza cu functionarea acestui montaj este mai jos:

Sketchul folosit pentru acest montaj este urmatorul:

#include "Wire.h"
#define PCF8563address 0x51
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);

String days[] = {"Duminica", "Luni", "Marti", 
    "Miercuri", "Joi", "Vineri", "Sambata" };
byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
String luna[] = {"Ianuarie", "Februarie", "Martie", 
    "Aprilie", "Mai", "Iunie", 
    "Iulie", "August", "Septembrie",
    "Octombrie", "Noiembrie", "Decembrie"};
    
void setup() {
  lcd.begin();
  lcd.backlight();
  lcd.setCursor(0, 0);
  lcd.print("Ceas cu PCF8563");
  delay(1500);
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("electronicstore");
  lcd.setCursor(13, 1);
  lcd.print(".ro");
  delay(2500);
  lcd.clear();
  Wire.begin();
}

void loop() {
 readPCF8563();
   
  afisare();
  lcd.setCursor(3, 1);
  lcd.print(days[dayOfWeek]);
  delay(1000);
  lcd.clear();
  afisare();
  lcd.setCursor(3, 1);
  lcd.print(dayOfMonth, DEC);
  lcd.print(" ");
  luna_mod = month -1;
  lcd.print(luna[luna_mod]);
  delay(1000);
  lcd.clear();
  afisare();
  lcd.setCursor(6, 1);
  lcd.print("20");
  lcd.print(year, DEC);
  delay(1000);
  lcd.clear();
}
  
void readPCF8563()
{
  Wire.beginTransmission(PCF8563address);
  Wire.write(0x02);
  Wire.endTransmission();
  Wire.requestFrom(PCF8563address, 7);
  second     = bcdToDec(Wire.read() & B01111111); 
  minute     = bcdToDec(Wire.read() & B01111111); 
  hour       = bcdToDec(Wire.read() & B00111111); 
  dayOfMonth = bcdToDec(Wire.read() & B00111111);
  dayOfWeek  = bcdToDec(Wire.read() & B00000111);  
  month      = bcdToDec(Wire.read() & B00011111);  
  year       = bcdToDec(Wire.read());
}

byte bcdToDec(byte value)
{
  return ((value / 16) * 10 + value % 16);
}

void afisare() {
  readPCF8563();
  lcd.setCursor(1, 0);
  lcd.print("Ora: ");
  lcd.print(hour, DEC);
  lcd.print(":");
  if (minute < 10) { lcd.print("0"); }
  lcd.print(minute, DEC);
  lcd.print(":");
  if (second < 10) { lcd.print("0"); }
  lcd.print(second, DEC);
}

Un filmulet cu montajul in functiune poate fi vazut mai jos:

Autentificare