Mcu Timer Calc logo

Mcu Timer Calc

Community
L110011101c
mcu-timer-calc

计算 8051/STC89 系列单片机定时器初值。当用户询问"51 定时器初值怎么算""TH0/TL0 是多少""定时 10ms 初值是多少""12MHz 12T 方式1 的初值""给定初值能定时多久",或需要核对一段 8051 定时器初始化代码中的初值是否正确时,应使用本技能调用脚本计算,而不是自行心算。支持方式 0/1/2、12T/6T/1T 分频,输出初值、TH0/TL0 字节、实际定时时间与量化误差。

Overview

PublisherL110011101c
Repositorymcu-timer-calc
Skill namemcu-timer-calc
Stars
32
Forks
0
Bundled files
2
LicenseMIT
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • 2 bundled files

    Scripts, templates, and references the model can read while it works. Files are read-only and never executed.

  • Open source

    Published by L110011101c on GitHub. Read the source before you install it.

Installation

Install the Mcu Timer Calc AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
    https://github.com/L110011101c/mcu-timer-calc/tree/main
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/L110011101c/mcu-timer-calc.git \
  .claude/skills/mcu-timer-calc
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Mcu Timer Calc in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Mcu Timer Calc on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Mcu Timer Calc is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

MCU Timer Calc — 8051 定时器初值计算器

用途

按"机器周期 → 计数值 → 初值"的确定性公式,计算 8051 系列单片机(含 STC89 等 12T/6T/1T 兼容型号)定时器的工作初值,并给出实际定时时间与量化误差。

定时器初值涉及机器周期换算与 2^n 补码运算,且方式 0 的 13 位编码(TL0 仅低 5 位) 极易写错。不要凭记忆心算,始终调用本技能提供的脚本。

何时使用

  • 用户询问 8051 定时器初值、TH0/TL0 取值、定时时间与初值的换算
  • 用户给出晶振频率与目标定时时间,要求生成定时器初始化代码
  • 用户给出初值,要求反算实际定时时间
  • 需要核对已有代码中 TH0 = 0x..; TL0 = 0x..; 的初值是否正确

如何使用

脚本路径:scripts/timer_calc.py,仅依赖 Python 标准库,无需安装任何依赖。

bash
# 由目标定时时间计算初值
python scripts/timer_calc.py --fosc 12MHz --mode 1 --prescaler 12T --time 10ms

# 经典验证:11.0592MHz 晶振 10ms 定时,初值应为 0xDC00
python scripts/timer_calc.py --fosc 11.0592MHz --mode 1 --prescaler 12T --time 10ms

# 由初值反算定时时间
python scripts/timer_calc.py --fosc 12MHz --mode 1 --prescaler 12T --init 55536

# 机器可读输出,便于程序化处理
python scripts/timer_calc.py --fosc 12MHz --mode 1 --prescaler 12T --time 10ms --json

参数说明

参数必填说明
--fosc是晶振频率,接受 12MHz / 12M / 11059200 / 8kHz 等写法
--mode是定时器工作方式,取值 0 / 1 / 2(方式 3 不支持)
--prescaler是分频模式,取值 12T / 6T / 1T
--time二选一目标定时时间,须带单位:ns / us / ms / s
--init二选一定时器初值(反向计算模式)
--json否以 JSON 格式输出

退出码

  • 0 计算成功
  • 2 输入非法或超出所选方式的能力范围(错误信息输出到 stderr)

关键约束

  1. 分频必须显式指定。 标准 8051 为 12T,STC 系列出厂默认 12T,但可通过 STC-ISP 改写为 6T/1T。脚本不设默认值,避免整倍错误。
  2. 方式 0 是 13 位计数器。 TH0 存高 8 位,TL0 只存低 5 位,写入时勿占高 3 位。
  3. 方式 2 是 8 位自动重装。 TH0 与 TL0 必须写入同一初值。
  4. 超出能力范围会报错。 例如方式 1 在 12MHz/12T 下最大只能定时 65.536ms。
  5. 误差是客观存在的。 目标时间不是机器周期整数倍时必然产生量化误差,脚本会 如实输出误差百分比,误差超过 2% 时给出提示,不隐藏、不"凑整"。

公式依据

机器周期 T = 分频系数 / fosc
计数值   N = round(目标定时时间 / T)
初值     = 2^位数 - N
实际定时时间 = N × T
误差     = (实际 - 目标) / 目标 × 100%

测试

bash
python -m unittest discover -s tests -v

测试覆盖经典手算基准(12MHz/11.0592MHz 等)、三种方式的上边界与越界、量化误差 上报、反向计算往返一致性,以及 CLI 的文本/JSON 输出与退出码。

Bundled files

The model reads these on demand while the skill is loaded. They are exposed as readable files and are never executed.

Frequently asked questions

What does the Mcu Timer Calc AI skill do?

计算 8051/STC89 系列单片机定时器初值。当用户询问"51 定时器初值怎么算""TH0/TL0 是多少""定时 10ms 初值是多少""12MHz 12T 方式1 的初值""给定初值能定时多久",或需要核对一段 8051 定时器初始化代码中的初值是否正确时,应使用本技能调用脚本计算,而不是自行心算。支持方式 0/1/2、12T/6T/1T 分频,输出初值、TH0/TL0 字节、实际定时时间与量化误差。

Why use Mcu Timer Calc on TypingMind?

Because you install it once and use it with any model. Mcu Timer Calc is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Mcu Timer Calc in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/L110011101c/mcu-timer-calc/tree/main. TypingMind reads its SKILL.md and bundles its files and installs it as a skill you can enable per chat.

Which AI models can use Mcu Timer Calc?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Mcu Timer Calc?

As many as you like. As long as a model supports skills, you can use Mcu Timer Calc with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Mcu Timer Calc AI skill free?

Yes. It is published on GitHub by L110011101c under the MIT license. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇