archieve: FinalTerm hms moudle
This commit is contained in:
@@ -0,0 +1,38 @@
|
|||||||
|
---
|
||||||
|
BasedOnStyle: Microsoft
|
||||||
|
Language: Cpp
|
||||||
|
|
||||||
|
###################################
|
||||||
|
# indent conf
|
||||||
|
###################################
|
||||||
|
|
||||||
|
UseTab: Never
|
||||||
|
IndentWidth: 4
|
||||||
|
TabWidth: 4
|
||||||
|
ColumnLimit: 0
|
||||||
|
AccessModifierOffset: -4
|
||||||
|
NamespaceIndentation: All
|
||||||
|
FixNamespaceComments: false
|
||||||
|
BreakBeforeBraces: Linux
|
||||||
|
|
||||||
|
###################################
|
||||||
|
# other styles
|
||||||
|
###################################
|
||||||
|
|
||||||
|
#
|
||||||
|
# for more conf, you can ref: https://clang.llvm.org/docs/ClangFormatStyleOptions.html
|
||||||
|
#
|
||||||
|
|
||||||
|
AllowShortIfStatementsOnASingleLine: true
|
||||||
|
|
||||||
|
AllowShortLoopsOnASingleLine: true
|
||||||
|
|
||||||
|
AllowShortBlocksOnASingleLine: true
|
||||||
|
|
||||||
|
IndentCaseLabels: true
|
||||||
|
|
||||||
|
SortIncludes: false
|
||||||
|
|
||||||
|
AlignConsecutiveMacros: AcrossEmptyLines
|
||||||
|
|
||||||
|
AlignConsecutiveAssignments: Consecutive
|
||||||
@@ -0,0 +1,80 @@
|
|||||||
|
{
|
||||||
|
"name": "FinalTerm",
|
||||||
|
"type": "C51",
|
||||||
|
"dependenceList": [],
|
||||||
|
"srcDirs": [
|
||||||
|
"src"
|
||||||
|
],
|
||||||
|
"virtualFolder": {
|
||||||
|
"name": "<virtual_root>",
|
||||||
|
"files": [],
|
||||||
|
"folders": []
|
||||||
|
},
|
||||||
|
"outDir": "build",
|
||||||
|
"deviceName": null,
|
||||||
|
"packDir": null,
|
||||||
|
"miscInfo": {
|
||||||
|
"uid": "f8e8e5ec8af6045a09b255d06d661dfe"
|
||||||
|
},
|
||||||
|
"targets": {
|
||||||
|
"Debug": {
|
||||||
|
"excludeList": [],
|
||||||
|
"toolchain": "Keil_C51",
|
||||||
|
"compileConfig": {
|
||||||
|
"options": "null"
|
||||||
|
},
|
||||||
|
"uploader": "Custom",
|
||||||
|
"uploadConfig": {
|
||||||
|
"bin": "",
|
||||||
|
"commandLine": "",
|
||||||
|
"eraseChipCommand": ""
|
||||||
|
},
|
||||||
|
"uploadConfigMap": {},
|
||||||
|
"custom_dep": {
|
||||||
|
"name": "default",
|
||||||
|
"incList": [],
|
||||||
|
"libList": [],
|
||||||
|
"defineList": []
|
||||||
|
},
|
||||||
|
"builderOptions": {
|
||||||
|
"SDCC": {
|
||||||
|
"version": 3,
|
||||||
|
"beforeBuildTasks": [],
|
||||||
|
"afterBuildTasks": [],
|
||||||
|
"global": {
|
||||||
|
"device": "mcs51",
|
||||||
|
"optimize-type": "speed",
|
||||||
|
"use-non-free": false
|
||||||
|
},
|
||||||
|
"c/cpp-compiler": {
|
||||||
|
"language-c": "c99"
|
||||||
|
},
|
||||||
|
"asm-compiler": {},
|
||||||
|
"linker": {
|
||||||
|
"$mainFileName": "main",
|
||||||
|
"output-format": "hex"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"Keil_C51": {
|
||||||
|
"version": 2,
|
||||||
|
"beforeBuildTasks": [],
|
||||||
|
"afterBuildTasks": [],
|
||||||
|
"global": {
|
||||||
|
"ram-mode": "SMALL",
|
||||||
|
"rom-mode": "LARGE"
|
||||||
|
},
|
||||||
|
"c/cpp-compiler": {
|
||||||
|
"optimization-type": "SPEED",
|
||||||
|
"optimization-level": "level-8"
|
||||||
|
},
|
||||||
|
"asm-compiler": {},
|
||||||
|
"linker": {
|
||||||
|
"remove-unused": true,
|
||||||
|
"output-format": "elf"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"version": "3.5"
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
##########################################################################################
|
||||||
|
# Append Compiler Options For Source Files
|
||||||
|
##########################################################################################
|
||||||
|
|
||||||
|
# syntax:
|
||||||
|
# <your pattern>: <compiler options>
|
||||||
|
# For get pattern syntax, please refer to: https://www.npmjs.com/package/micromatch
|
||||||
|
#
|
||||||
|
# examples:
|
||||||
|
# 'main.cpp': --cpp11 -Og ...
|
||||||
|
# 'src/*.c': -gnu -O2 ...
|
||||||
|
# 'src/lib/**/*.cpp': --cpp11 -Os ...
|
||||||
|
# '!Application/*.c': -O0
|
||||||
|
# '**/*.c': -O2 -gnu ...
|
||||||
|
|
||||||
|
version: "2.0"
|
||||||
|
options:
|
||||||
|
Debug:
|
||||||
|
files: {}
|
||||||
|
virtualPathFiles: {}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
# dot files
|
||||||
|
/.vscode/launch.json
|
||||||
|
/.settings
|
||||||
|
/.eide/log
|
||||||
|
/.eide.usr.ctx.json
|
||||||
|
|
||||||
|
# project out
|
||||||
|
/build
|
||||||
|
/bin
|
||||||
|
/obj
|
||||||
|
/out
|
||||||
|
|
||||||
|
# eide template
|
||||||
|
*.ept
|
||||||
|
*.eide-template
|
||||||
Vendored
+1
@@ -0,0 +1 @@
|
|||||||
|
{}
|
||||||
Vendored
+40
@@ -0,0 +1,40 @@
|
|||||||
|
{
|
||||||
|
"version": "2.0.0",
|
||||||
|
"tasks": [
|
||||||
|
{
|
||||||
|
"label": "build",
|
||||||
|
"type": "shell",
|
||||||
|
"command": "${command:eide.project.build}",
|
||||||
|
"group": "build",
|
||||||
|
"problemMatcher": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "flash",
|
||||||
|
"type": "shell",
|
||||||
|
"command": "${command:eide.project.uploadToDevice}",
|
||||||
|
"group": "build",
|
||||||
|
"problemMatcher": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "build and flash",
|
||||||
|
"type": "shell",
|
||||||
|
"command": "${command:eide.project.buildAndFlash}",
|
||||||
|
"group": "build",
|
||||||
|
"problemMatcher": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "rebuild",
|
||||||
|
"type": "shell",
|
||||||
|
"command": "${command:eide.project.rebuild}",
|
||||||
|
"group": "build",
|
||||||
|
"problemMatcher": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "clean",
|
||||||
|
"type": "shell",
|
||||||
|
"command": "${command:eide.project.clean}",
|
||||||
|
"group": "build",
|
||||||
|
"problemMatcher": []
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
{
|
||||||
|
"folders": [
|
||||||
|
{
|
||||||
|
"path": "."
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"settings": {
|
||||||
|
"files.autoGuessEncoding": true,
|
||||||
|
"C_Cpp.default.configurationProvider": "cl.eide",
|
||||||
|
"C_Cpp.errorSquiggles": "disabled",
|
||||||
|
"files.associations": {
|
||||||
|
".eideignore": "ignore",
|
||||||
|
"*.a51": "a51",
|
||||||
|
"*.h": "c",
|
||||||
|
"*.c": "c",
|
||||||
|
"*.hxx": "cpp",
|
||||||
|
"*.hpp": "cpp",
|
||||||
|
"*.c++": "cpp",
|
||||||
|
"*.cpp": "cpp",
|
||||||
|
"*.cxx": "cpp",
|
||||||
|
"*.cc": "cpp"
|
||||||
|
},
|
||||||
|
"[yaml]": {
|
||||||
|
"editor.insertSpaces": true,
|
||||||
|
"editor.tabSize": 4,
|
||||||
|
"editor.autoIndent": "advanced"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"extensions": {
|
||||||
|
"recommendations": [
|
||||||
|
"cl.eide",
|
||||||
|
"keroc.hex-fmt",
|
||||||
|
"xiaoyongdong.srecord",
|
||||||
|
"hars.cppsnippets",
|
||||||
|
"zixuanwang.linkerscript",
|
||||||
|
"redhat.vscode-yaml",
|
||||||
|
"IBM.output-colorizer",
|
||||||
|
"cschlosser.doxdocgen",
|
||||||
|
"ms-vscode.vscode-serial-monitor",
|
||||||
|
"alefragnani.project-manager",
|
||||||
|
"cl.stm8-debug"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,95 @@
|
|||||||
|
/*
|
||||||
|
* @name: hms.c
|
||||||
|
* @author: msksbr
|
||||||
|
* @date: 2025-05-27
|
||||||
|
* @description: implement functions for the hms.h header file.
|
||||||
|
* @usage: #include "hms.h"
|
||||||
|
* @example: HMS *hms = newHMS(); // create a new HMS object.
|
||||||
|
* @example: hms->setHMS(hms, 12, 34, 56); // set the time to 12:34:56.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "hms.h" // include the header file.
|
||||||
|
#include <STDLIB.H>
|
||||||
|
|
||||||
|
// setters
|
||||||
|
static void setHour(HMS *this, unsigned char hour)
|
||||||
|
{
|
||||||
|
if (hour <= 99 && hour >= 0) {
|
||||||
|
this->hour = hour;
|
||||||
|
} else {
|
||||||
|
this->hour = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
static void setMinute(HMS *this, unsigned char minute)
|
||||||
|
{
|
||||||
|
if (minute <= 59 && minute >= 0) {
|
||||||
|
this->minute = minute;
|
||||||
|
} else {
|
||||||
|
this->minute = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void setSecond(HMS *this, unsigned char second)
|
||||||
|
{
|
||||||
|
if (second <= 59 && second >= 0) {
|
||||||
|
this->second = second;
|
||||||
|
} else {
|
||||||
|
this->second = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// getters
|
||||||
|
static unsigned char getHour(HMS *this)
|
||||||
|
{
|
||||||
|
return this->hour;
|
||||||
|
}
|
||||||
|
static unsigned char getMinute(HMS *this)
|
||||||
|
{
|
||||||
|
return this->minute;
|
||||||
|
}
|
||||||
|
static unsigned char getSecond(HMS *this)
|
||||||
|
{
|
||||||
|
return this->second;
|
||||||
|
}
|
||||||
|
// tikTok: aka. second + 1. and solve the overflow problem.
|
||||||
|
static void tikTok(HMS *this)
|
||||||
|
{
|
||||||
|
this->second++; // second + 1.
|
||||||
|
if (this->second == 60) { // if second is 60, then minute + 1.
|
||||||
|
this->second = 0; // second = 0.
|
||||||
|
this->minute++; // minute + 1.
|
||||||
|
if (this->minute == 60) { // if minute is 60, then hour + 1.
|
||||||
|
this->minute = 0; // minute = 0.
|
||||||
|
this->hour++; // hour + 1.
|
||||||
|
if (this->hour == 100) { // if hour is 100, then hour = 0.
|
||||||
|
this->hour = 0; // hour = 0.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// constructor with values.
|
||||||
|
HMS *newHMSWithValues(unsigned char hour, unsigned char minute, unsigned char second)
|
||||||
|
{
|
||||||
|
HMS *obj = (HMS *)malloc(sizeof(HMS));
|
||||||
|
if (obj) {
|
||||||
|
// bind methods to the object.
|
||||||
|
obj->setHour = setHour;
|
||||||
|
obj->setMinute = setMinute;
|
||||||
|
obj->setSecond = setSecond;
|
||||||
|
obj->getHour = getHour;
|
||||||
|
obj->getMinute = getMinute;
|
||||||
|
obj->getSecond = getSecond;
|
||||||
|
obj->tikTok = NULL; // not implemented yet.
|
||||||
|
// set the values.
|
||||||
|
obj->setHour(obj, hour);
|
||||||
|
obj->setMinute(obj, minute);
|
||||||
|
obj->setSecond(obj, second);
|
||||||
|
}
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
// constructor
|
||||||
|
HMS *newHMS(void)
|
||||||
|
{
|
||||||
|
return newHMSWithValues(0, 0, 0);
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
/*
|
||||||
|
* @name: hms.h
|
||||||
|
* @author: msksbr
|
||||||
|
* @date: 2025-05-27
|
||||||
|
* @description: define Hours, Minutes and Seconds.
|
||||||
|
*/
|
||||||
|
#ifndef HMS_H_
|
||||||
|
#define HMS_H_
|
||||||
|
|
||||||
|
typedef struct HMS HMS;
|
||||||
|
|
||||||
|
struct HMS {
|
||||||
|
unsigned char hour; // 0-99
|
||||||
|
unsigned char minute; // 0-59
|
||||||
|
unsigned char second; // 0-59
|
||||||
|
// getters and setters
|
||||||
|
void (*setHour)(HMS *, unsigned char);
|
||||||
|
void (*setMinute)(HMS *, unsigned char);
|
||||||
|
void (*setSecond)(HMS *, unsigned char);
|
||||||
|
unsigned char (*getHour)(HMS *);
|
||||||
|
unsigned char (*getMinute)(HMS *);
|
||||||
|
unsigned char (*getSecond)(HMS *);
|
||||||
|
void (*tikTok)(HMS *); // aka. second + 1
|
||||||
|
};
|
||||||
|
|
||||||
|
// constructors
|
||||||
|
HMS *newHMS(void);
|
||||||
|
HMS *newHMSWithValues(unsigned char hour, unsigned char minute, unsigned char second);
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
/*
|
||||||
|
* @name: main.c
|
||||||
|
* @author: msksbr
|
||||||
|
* @date: 2025-05-27
|
||||||
|
* @description: This is the main file for the project. It contains the main function and the main loop.
|
||||||
|
* @project: A simple Timer project for 80C51 micro controller.
|
||||||
|
* @attention: This project implements the OOP in C !!!
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <reg52.h>
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user