/* Main.ino file generated by New Project wizard
*
* Created: Mon Dec 25 2023
* Processor: Arduino Uno
* Compiler: Arduino AVR (Proteus)
*/
#include "Arduino_Uno_Driver.h"
#include "I2C_Driver.h"
#include "RTC_DS1307.h"
#include <stdint.h>
#include <stdio.h>
/*
Calculation of Ten Power based on the passing int parameter
Params :
power - int value of the power
*/
int TenPower(int power)
{
if(power == 0)
return 1;
else
return (10 * TenPower(power-1));
}
/*
Passing string value to Writing it on LCD display using I2C
Param 1 : Address of starting index of char array
*/
void WriteToDisplay(uint8_t* data)
{
while(*data != '\0')
{
Write_I2C_TrasmitData(*data, LCD1602_SLA_ADDR, false);
data++;
}
}
/*
Convert int to string value and Writing to display
Param 1 : Passing display int number
*/
void WriteNumberToDisplay(int data)
{
int index = 0; char displayData[10];
int actualData = data;
while(data > 0)
{
int temp = (data % 10);
if(index > 0)
{
unsigned int length = (unsigned int)index;
while(length > 0)
{
int prevIndex = length - 1;
displayData[length] = displayData[prevIndex];
length--;
}
displayData[length] = temp + '0';
}
else
{
if(actualData < 10)
{
displayData[index] = '0';
index = index + 1;
}
displayData[index] = temp + '0';
}
data = data / 10;
index++;
}
if(actualData == 0)
{
displayData[index] = '0';
index++;
displayData[index] = '0';
index++;
}
displayData[index] = '\0';
WriteToDisplay(displayData);
}
void setup()
{
// Timer/Counter 0 Register
uint8_t *pTimer0_Reg = (uint8_t *)TIMSK0REG;
I2C_Init(I2c_PreScalar[0], 0x48);
I2C_Config_LCD(); // Setting 16x2 LCD Configuration using I2C
Set_Lcd_Cursor(0,0); // First parameter Column and Second parameter Row
while(1)
{
Set_Lcd_Cursor(0,0);
WriteToDisplay("Time - ");
WriteNumberToDisplay(readHours());
WriteToDisplay(":");
WriteNumberToDisplay(readMins());
WriteToDisplay(":");
WriteNumberToDisplay(readSecs());
Set_Lcd_Cursor(0,1);
WriteToDisplay("Date - ");
WriteNumberToDisplay(readDates());
WriteToDisplay("/");
WriteNumberToDisplay(readMonths());
WriteToDisplay("/");
WriteNumberToDisplay(readYears() % 100);
for(volatile int i=0; i<= 1000; i++);
}
}
void loop() {
// put your main code here, to run repeatedly:
}