[go: up one dir, main page]

0% found this document useful (0 votes)
46 views2 pages

Dong - Ho - LCD Code

This C++ program prints the current date and time in DD/MM/YY HH:MM:SS format. It uses functions to print 2-digit values, increment values, and delay for 1 second. The main function contains a loop that continuously prints and increments the date/time values, rolling over at the maximum for each unit (seconds to minutes to hours etc.), and delays for 1 second between each iteration.

Uploaded by

Putin Vladimir
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views2 pages

Dong - Ho - LCD Code

This C++ program prints the current date and time in DD/MM/YY HH:MM:SS format. It uses functions to print 2-digit values, increment values, and delay for 1 second. The main function contains a loop that continuously prints and increments the date/time values, rolling over at the maximum for each unit (seconds to minutes to hours etc.), and delays for 1 second between each iteration.

Uploaded by

Putin Vladimir
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include <iostream>

using namespace std;


void print_2_digit(int v, char e) {
cout << (v < 10 ? '0' : '\0') << v << e;
}

int increase(int& v, int max) {


v++;
if (v == max) {
v = 0;
return 1;
}
return 0;
}

#define MICROS_CYCLE_LENGTH 100


void one_micros() {
for (int i =0; i < MICROS_CYCLE_LENGTH; i++){}
}
void one_millisecond(){
for (int i = 0; i < 100; i++) {
one_micros();
}
}
void delay(int ms) {
while (ms--) {
one_millisecond();
}
}

int main()
{
int year, month, day, hour, minute, second;
year = month = day = 0;
hour = minute = second = 0;

while(true) {
print_2_digit(day + 1, '/');
print_2_digit(month + 1, '/');
print_2_digit((year + 1) / 100, '\0');
print_2_digit((year + 1) % 100, ' ');

print_2_digit(hour, ':');
print_2_digit(minute, ':');
print_2_digit(second, '\n');

if (increase(second, 60)) {
if (increase(minute, 60))
if (increase(hour, 24))
if (increase(day,31))
if (increase(month, 12))
increase(year, 10000);
}

delay(1000);

}
}

You might also like