diff --git a/FinalTerm/.clang-format b/FinalTerm/.clang-format new file mode 100644 index 0000000..ecc57c4 --- /dev/null +++ b/FinalTerm/.clang-format @@ -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 diff --git a/FinalTerm/.eide/eide.json b/FinalTerm/.eide/eide.json new file mode 100644 index 0000000..781ec5a --- /dev/null +++ b/FinalTerm/.eide/eide.json @@ -0,0 +1,80 @@ +{ + "name": "FinalTerm", + "type": "C51", + "dependenceList": [], + "srcDirs": [ + "src" + ], + "virtualFolder": { + "name": "", + "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" +} \ No newline at end of file diff --git a/FinalTerm/.eide/files.options.yml b/FinalTerm/.eide/files.options.yml new file mode 100644 index 0000000..c258721 --- /dev/null +++ b/FinalTerm/.eide/files.options.yml @@ -0,0 +1,20 @@ +########################################################################################## +# Append Compiler Options For Source Files +########################################################################################## + +# syntax: +# : +# 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: {} diff --git a/FinalTerm/.gitignore b/FinalTerm/.gitignore new file mode 100644 index 0000000..c2f4ce9 --- /dev/null +++ b/FinalTerm/.gitignore @@ -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 diff --git a/FinalTerm/.vscode/settings.json b/FinalTerm/.vscode/settings.json new file mode 100644 index 0000000..9e26dfe --- /dev/null +++ b/FinalTerm/.vscode/settings.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/FinalTerm/.vscode/tasks.json b/FinalTerm/.vscode/tasks.json new file mode 100644 index 0000000..3e192b9 --- /dev/null +++ b/FinalTerm/.vscode/tasks.json @@ -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": [] + } + ] +} \ No newline at end of file diff --git a/FinalTerm/FinalTerm.code-workspace b/FinalTerm/FinalTerm.code-workspace new file mode 100644 index 0000000..8c192af --- /dev/null +++ b/FinalTerm/FinalTerm.code-workspace @@ -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" + ] + } +} \ No newline at end of file diff --git a/FinalTerm/src/hms/hms.c b/FinalTerm/src/hms/hms.c new file mode 100644 index 0000000..da00849 --- /dev/null +++ b/FinalTerm/src/hms/hms.c @@ -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 + +// 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); +} \ No newline at end of file diff --git a/FinalTerm/src/hms/hms.h b/FinalTerm/src/hms/hms.h new file mode 100644 index 0000000..0269de2 --- /dev/null +++ b/FinalTerm/src/hms/hms.h @@ -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 \ No newline at end of file diff --git a/FinalTerm/src/main.c b/FinalTerm/src/main.c new file mode 100644 index 0000000..109a2bc --- /dev/null +++ b/FinalTerm/src/main.c @@ -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 + +void main() +{ +} \ No newline at end of file