Compare commits

...

30 Commits

Author SHA1 Message Date
msksbr 733eda29ab archive: homework8 test1 2025-06-30 23:01:41 +08:00
msksbr 782b0867aa init: homework8 2025-06-18 19:21:53 +08:00
msksbr e3c9129e83 use others finalterm 2025-05-29 20:03:51 +08:00
msksbr b13f90b5b4 archieve: FinalTerm 51pins moudle 2025-05-29 14:16:27 +08:00
msksbr fd0fd805b5 archieve: FinalTerm hms moudle 2025-05-27 13:26:01 +08:00
msksbr 6d58ed79d8 fix: homework7 test3 charset bugs 2025-05-25 02:14:44 +08:00
msksbr 23ea54ea6a archieve: homework7 test5 2025-05-25 02:08:11 +08:00
msksbr a3cf2cbc8e archieve: homework7 test4 2025-05-25 01:32:57 +08:00
msksbr 1cda67295c fix: homework7 test3 animation bugs 2025-05-25 01:08:58 +08:00
msksbr 420ae95641 archieve: homework7 test3 2025-05-25 00:37:27 +08:00
msksbr 3b682e993c archieve: homework7 test2 2025-05-25 00:15:42 +08:00
msksbr 1b64a5df5b archieve: homework7 test1 2025-05-24 23:29:42 +08:00
msksbr 097e654ba5 archieve: homework7 header 2025-05-24 23:15:46 +08:00
msksbr dc3cb42124 archieve: homework7 schematic 2025-05-24 22:55:46 +08:00
msksbr 436f5f224d reset: homework7 2025-05-24 22:54:15 +08:00
msksbr b5838a823c reset: homework7 2025-05-24 22:52:32 +08:00
msksbr 60f9efa1d6 archieve: homework7 header 2025-05-22 23:47:45 +08:00
msksbr c4d507bd87 reinit: homework7 2025-05-22 23:28:46 +08:00
msksbr 69137d8ec4 remove: homework7 2025-05-22 23:25:08 +08:00
msksbr 429a7b3f34 archieve: homework7 test1 2025-05-20 13:36:46 +08:00
msksbr 25333ffc84 archieve: homework7 schematic 2025-05-20 12:55:32 +08:00
msksbr 1e079c187c init: homework7 2025-05-20 12:10:08 +08:00
msksbr 8a90337479 archieve: homework6 2025-05-06 21:08:28 +08:00
msksbr 346478498d init: homework6 test4 2025-05-06 20:52:02 +08:00
msksbr b0ce746a20 archieve: homework6 test3 2025-05-06 14:20:25 +08:00
msksbr b5fcd85516 archieve: homework6 test2 2025-05-06 13:27:50 +08:00
msksbr 6f0d7b3a86 archieve: homework6 test1 2025-05-06 13:11:46 +08:00
msksbr c8709b51af archieve: homework6 header 2025-05-06 12:57:17 +08:00
msksbr 7ddc888862 archieve: homework6 Schematic 2025-05-06 12:40:34 +08:00
msksbr b3527f1fca init: homework6 2025-05-06 12:37:56 +08:00
38 changed files with 1374 additions and 4 deletions
+3
View File
@@ -54,3 +54,6 @@ dkms.conf
# proteus workspace
*.workspace
*/Project Backups/
# others
89C51_Simple_Calculator/
+3 -3
View File
@@ -20,9 +20,9 @@
"Debug": {
"excludeList": [
"src/test.c",
"src/test2.c",
"src/test3.c",
"src/test4.c"
"src/test1.c",
"src/test4.c",
"src/test3.c"
],
"toolchain": "Keil_C51",
"compileConfig": {
+38
View File
@@ -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
+84
View File
@@ -0,0 +1,84 @@
{
"name": "homework6",
"type": "C51",
"dependenceList": [],
"srcDirs": [
"src"
],
"virtualFolder": {
"name": "<virtual_root>",
"files": [],
"folders": []
},
"outDir": "build",
"deviceName": null,
"packDir": null,
"miscInfo": {
"uid": "8219e80baa2ee376f6321a1ce1b13e9c"
},
"targets": {
"Debug": {
"excludeList": [
"src/test3.c",
"src/test2.c",
"src/test4.c"
],
"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"
}
+20
View File
@@ -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: {}
+15
View File
@@ -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
+1
View File
@@ -0,0 +1 @@
{}
+40
View File
@@ -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": []
}
]
}
+45
View File
@@ -0,0 +1,45 @@
{
"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",
"REG52.H": "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"
]
}
}
Binary file not shown.
+73
View File
@@ -0,0 +1,73 @@
// homework6.h
/*
* this is the header file to
* define the
* variables:
* - 38 transistors address
* - pins for the LEDs and the segs
* - pins for the 38 transistors
* - seg chars to display to display the number
* functions:
* - set the 38 transistors.
*/
#include <REG52.H>
// variables:
// 38 transistors address
#define LEDS [6]{0, 1, 2, 3, 4, 5}
#define TO_LED 6
// pins for the LEDs and the segs
sbit BUS1A = P2 ^ 0; // Red LED and A Seg
sbit BUS2B = P2 ^ 1; // Orange LED and B Seg
sbit BUS3C = P2 ^ 2; // Yellow LED and C Seg
sbit BUS4D = P2 ^ 3; // Green LED and D Seg
sbit BUS5E = P2 ^ 4; // Aqua LED and E Seg
sbit BUS6F = P2 ^ 5; // BLUE LED and F Seg
sbit BUS7G = P2 ^ 6; // Purple LED and G Seg
sbit BUS8DP = P2 ^ 7; // White LED and DP Seg
// pins for the 38 transistors
sbit ADDR0 = P1 ^ 0; // to A(A0)
sbit ADDR1 = P1 ^ 1; // to B(A1)
sbit ADDR2 = P1 ^ 2; // to C(A2)
sbit ADDR3 = P1 ^ 3; // to E1
sbit ENLED = P1 ^ 4; // to E2 & E3
// seg chars to display to display the number
unsigned char code LedChar[] = {
0xC0,
0xF9,
0XA4,
0XB0,
0X99,
0X92,
0X82,
0XF8,
0X80,
0X90,
0X88,
0X83,
0XC6,
0XA1,
0X86,
0X8E,
};
// functions:
// 38 transistors control function
/*
* param:
* - addr: the address of the 38 transistors.
* function:
* - Convert the address to 3 binary numbers.
* - Set the 38 transistors to the address.
*/
void set38(unsigned char addr)
{
// Enable the 38 transistors.
ENLED = 0;
ADDR3 = 1;
// Set the 38 transistors to the address.
ADDR0 = addr & 0x01;
ADDR1 = (addr & 0x02) >> 1;
ADDR2 = (addr & 0x04) >> 2;
}
// low seg is the right side.
+44
View File
@@ -0,0 +1,44 @@
// test1.c
// 定时器0中断实现流水灯,设定合适的初值实现1s定时,控制LED灯依次点亮,形成流水灯效果
// Timer 0 interrupt to implement the LED light,
// set the appropriate initial value to implement 1s timing,
// control the LED light to turn on one by one, forming the light effect.
#include "homework6.h"
void test1()
{
// Set the 38 transistors to the address.
set38(TO_LED);
// init the timer 0.
TMOD = 0x01; // set the timer 0 to mode 1.
TH0 = 0xFC; // set the timer 0 to 1s.
TL0 = 0x66; // set the timer 0 to 1s.
TR0 = 1; // start the timer 0.
ET0 = 1; // enable the timer 0 interrupt.
EA = 1; // enable the interrupt.
P2 = 0xFE; // init mode: the first LED light.
while (1) {}
}
void Timer0_ISR() interrupt 1
{
static unsigned int counter = 0; // counter to count the number of interrupts.
static unsigned char led = 0xFE; // store the LED light.
// reset the timer 0.
TH0 = 0xFC; // set the timer 0 to 1s.
TL0 = 0x66; // set the timer 0 to 1s.
if (++counter >= 1000) {
counter = 0; // reset the counter.
led = (led << 1) | 0x01; // shift the LED light to the left.
if (led == 0xFF) led = 0xFE; // if the LED light is 0xFF, reset the LED light to 0xFE.
P2 = led; // set the LED light.
}
}
void main()
{
test1();
}
+39
View File
@@ -0,0 +1,39 @@
// test2.c
// 定时器1中断控制两个LED交替闪烁。设置定时器1的初值,使其每隔25ms产生一次中断。
// 在中断服务程序中,每次中断对两个LED的状态进行切换,一个LED亮时另一个LED灭,
// 从而实现交替闪烁
// Timer 1 interrupt to control two LED lights to alternate.
// Set the initial value of the timer 1 to make it produce an interrupt every 25ms.
// In the interrupt service program,
// switch the state of the two LED lights every time an interrupt occurs,
// one LED light on at a time, and the other LED light off,
// thus implementing alternating flashing.
#include "homework6.h"
void test2()
{
// Set the 38 transistors to the address.
set38(TO_LED);
// init the timer 1.
TMOD = 0x9E; // set the timer 1 to mode 1.
TH1 = 0x58; // set the timer 1 to 25ms.
TL1 = 0x66; // set the timer 1 to 25ms.
TR1 = 1; // start the timer 1.
ET1 = 1; // enable the timer 1 interrupt.
EA = 1; // enable the interrupt.
P2 = 0xFC; // init mode: the first LED light.
while (1) {}
}
void Timer1_ISR() interrupt 3
{
TH1 = 0x9E; // reset the timer 1.
TH1 = 0x58; // reset the timer 1.
P2 ^= 0x03; // switch the state of the two LED lights.
}
void main()
{
test2();
}
+50
View File
@@ -0,0 +1,50 @@
// test3.c
// 通过定时器T1中断,实现三位数秒表
// make a three-digit stopwatch by timer T1 interrupt.
#include "homework6.h"
unsigned char digits[3] = {0, 0, 0}; // store the three digits of the stopwatch.
unsigned char displayPos = 0; // store the position of the display.
void test3()
{
TMOD = 0x10; // set the timer 1 to mode 1.
TH1 = 0xFC; // set the timer 1 to 1s.
TL1 = 0x18; // set the timer 1 to 1s.
TR1 = 1; // start the timer 1.
ET1 = 1; // enable the timer 1 interrupt.
EA = 1; // enable the interrupt.
while (1);
}
void Timer1_ISR() interrupt 3
{
static unsigned int counter = 0; // counter to count the number of interrupts.
TH1 = 0xFC; // reset the timer 1.
TL1 = 0x18; // reset the timer 1.
set38(displayPos); // set the 38 transistors to the address.
P2 = LedChar[digits[2 - displayPos]]; // display the digit.
displayPos++; // switch to the next digit.
if (displayPos >= 3) displayPos = 0; // if the display position is 3, reset the display position to 0.
if (++counter >= 1000) {
counter = 0; // reset the counter.
if (++digits[2] >= 10) {
digits[2] = 0; // reset the third digit.
if (++digits[1] >= 10) {
digits[1] = 0; // reset the second digit.
if (++digits[0] >= 10) {
digits[0] = 0; // reset the first digit.
}
}
}
}
// reset the stopwatch when the stopwatch is 999.
if (digits[0] == 9 && digits[1] == 9 && digits[2] == 9) {
digits[0] = 0;
digits[1] = 0;
digits[2] = 0;
}
}
void main()
{
test3();
}
+55
View File
@@ -0,0 +1,55 @@
// test4.c
// 利用定时器T0定时10秒,并通过数码管显示秒表,到10秒后让led流水灯从左往右移动
// use timer T0 to count 10 seconds and display the stopwatch on the 7-segment display, and let the led light move from left to right after 10 seconds.
#include "homework6.h"
unsigned char digits[2] = {0, 0};
unsigned char displayPos = 0;
void test4()
{
digits[0] = 1; // set the first digit to 0.
digits[1] = 0; // set the second digit to 1.
TMOD = 0x01; // set the timer 0 to mode 1.
TH0 = 0xFC; // set the timer 0 to 1s.
TL0 = 0x18; // set the timer 0 to 1s.
TR0 = 1; // start the timer 0.
ET0 = 1; // enable the timer 0 interrupt.
EA = 1; // enable the interrupt.
while (1) {}
}
void Timer0_ISR() interrupt 1
{
static unsigned char led = 0xFE; // store the led light.
static unsigned int counter = 0; // counter to count the number of interrupts.
TH0 = 0xFC; // reset the timer 0.
TL0 = 0x18; // reset the timer 0.
if (digits[0] == 0 && digits[1] == 0) { // if the stopwatch is 00, let the led light move from left to right.
set38(TO_LED); // set the 38 transistors to the address.
if (++counter >= 1000) {
counter = 0; // reset the counter.
led = (led << 1) | 0x01; // shift the led light to the left.
if (led == 0xFF) led = 0xFE; // if the led light is 0xFF, reset the led light to 0xFE.
P2 = led; // set the led light.
}
} else {
set38(displayPos); // set the 38 transistors to the address.
P2 = LedChar[digits[1 - displayPos]]; // display the digit.
displayPos++; // switch to the next digit.
if (displayPos >= 2) displayPos = 0; // if the display position is 2, reset the display position to 0.
if (++counter >= 1000) { // if the counter is 1000, count 1 second.
counter = 0; // reset the counter.
if (digits[1]-- == 0) {
digits[1] = 9;
if (digits[0] > 0) {
digits[0]--;
}
}
}
}
}
void main()
{
test4();
}
+38
View File
@@ -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
+85
View File
@@ -0,0 +1,85 @@
{
"name": "homework7",
"type": "C51",
"dependenceList": [],
"srcDirs": [
"src"
],
"virtualFolder": {
"name": "<virtual_root>",
"files": [],
"folders": []
},
"outDir": "build",
"deviceName": null,
"packDir": null,
"miscInfo": {
"uid": "113f2f1f906f1d361f61fd9211e96f55"
},
"targets": {
"Debug": {
"excludeList": [
"src/test1.c",
"src/test2.c",
"src/test3.c",
"src/test4.c"
],
"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"
}
+20
View File
@@ -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: {}
+15
View File
@@ -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
+1
View File
@@ -0,0 +1 @@
{}
+40
View File
@@ -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": []
}
]
}
+46
View File
@@ -0,0 +1,46 @@
{
"folders": [
{
"path": "."
}
],
"settings": {
"files.autoGuessEncoding": true,
"C_Cpp.default.configurationProvider": "cl.eide",
"C_Cpp.errorSquiggles": "disabled",
"files.associations": {
"*.dbclient-js": "javascript",
".eideignore": "ignore",
"*.a51": "a51",
"*.h": "c",
"*.c": "c",
"*.hxx": "cpp",
"*.hpp": "cpp",
"*.c++": "cpp",
"*.cpp": "cpp",
"*.cxx": "cpp",
"*.cc": "cpp",
"REG52.H": "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"
]
}
}
Binary file not shown.
+77
View File
@@ -0,0 +1,77 @@
/*
* @name: homework7.h
* @author: msksbr
* @date: 2025-05-24
* @description: a header for homework7's homework tests
* @version: 1.0f: fix errors in timer
* variables:
* 1.0:
* 1. sbit DB_0 ~ sbit DB_7: pin number for led matrix cathodes
* 2. pin number for 74HC138's address pins & enable pin
* 2.1. sbit ADDR0 ~ sbit ADDR2: pin number for 74HC138's address pins
* 2.2. sbit ADDR3 & sbit ENLED: pin number for 74HC138's enable pin
* functions:
* 1.0:
* 1. void switch_138(unsigned char n): switch the 74HC138's address to n
* 2. void delay_ms(unsigned char ms): a timer by ms base on timer0 mode 1
*/
#include <REG52.H>
// variables:
// 1. sbit DB_0 ~ sbit DB_7: pin number for led matrix cathodes
sbit DB_0 = P2 ^ 0;
sbit DB_1 = P2 ^ 1;
sbit DB_2 = P2 ^ 2;
sbit DB_3 = P2 ^ 3;
sbit DB_4 = P2 ^ 4;
sbit DB_5 = P2 ^ 5;
sbit DB_6 = P2 ^ 6;
sbit DB_7 = P2 ^ 7;
// 2. pin number for 74HC138's address pins & enable pin
// 2.1. sbit ADDR0 ~ sbit ADDR2: pin number for 74HC138's address pins
sbit ADDR0 = P1 ^ 0; // @var ADDR0: to A(A0)
sbit ADDR1 = P1 ^ 1; // @var ADDR1: to B(A1)
sbit ADDR2 = P1 ^ 2; // @var ADDR2: to C(A2)
// 2.2. sbit ADDR3 & sbit ENLED: pin number for 74HC138's enable pin
sbit ADDR3 = P1 ^ 3; // @var ADDR3: to E2
sbit ENLED = P1 ^ 4; // @var ENLED: to E3
// functions:
// 1. void switch_138(unsigned char n): switch the 74HC138's address to n
void switch_138(unsigned char n)
{
bit A0, A1, A2;
// @subsection: enable the 74HC138
ENLED = 0;
ADDR3 = 0;
// @subsection: turn n to 3 bit binary number
A0 = n & 0x01;
A1 = (n >> 1) & 0x01;
A2 = (n >> 2) & 0x01;
// @subsection: switch the 74HC138's address to n
ADDR0 = A0;
ADDR1 = A1;
ADDR2 = A2;
}
// 2. void delay_ms(unsigned char ms): a timer by ms base on timer0 mode 1
void delay_ms(unsigned char ms)
{
TMOD &= 0xF0; // set the timer mode to 16-bit timer mode.
TMOD |= 0x01; // set the timer mode to 16-bit timer mode.
// 1ms timer definition:
TH0 = 0XFC;
TL0 = 0X18;
// start the timer:
TR0 = 1;
while (ms--) {
while (!TF0) {} // wait for the timer to overflow.
TF0 = 0; // clear the timer flag.
TH0 = 0XFC; // reload the timer value.
TL0 = 0X18; // reload the timer value.
}
TR0 = 0; // stop the timer.
}
+22
View File
@@ -0,0 +1,22 @@
/*
* @name: test1.c
* @author: msksbr
* @date: 2025-05-24
* @description: a test for homework7's homework tests
* @version: 1.0
* homework zh_CN: 点亮点阵左上角的那个LED小灯
* homework EN: point the left top LED of the led matrix
*/
#include "homework7.h"
void test1()
{
switch_138(0); // switch the 74HC138's address to 0
DB_0 = 0; // turn on the led matrix's left top LED
}
void main()
{
test1();
}
+36
View File
@@ -0,0 +1,36 @@
/*
* @name: test2.c
* @author: msksbr
* @date: 2025-05-24
* @description: a test for homework7's homework tests
* @version: 1.0
* homework zh_CN: 点阵显示心形图形
* homework EN: display a heart shape on the led matrix
*/
#include "homework7.h"
void test2()
{
unsigned char i; // @var i: a counter for the loop
unsigned char code heart[] = {
0x00, 0x66, 0xFF, 0xFF,
0xFF, 0x7E, 0x3C, 0x18};
// @subsection: display a heart shape on the led matrix
while (1) // @loop: display the heart shape on the led matrix
{
for (i = 8; i > 0; i--) // @loop: display the heart shape on the led matrix
{
switch_138(i); // switch the 74HC138's address to i
P2 = ~heart[i]; // display the heart shape on the led matrix
delay_ms(1);
P2 = 0xFF; // turn off the led matrix
}
i = 8;
}
}
void main()
{
test2();
}
+64
View File
@@ -0,0 +1,64 @@
/*
* @name: test1.c
* @author: msksbr
* @date: 2025-05-25
* @description: a test for homework7's homework tests
* @version: 1.0f: fix animation bugs
* homework zh_CN: 点阵显示一个 I ❤ U 的向下移动动画
* homework EN: display a animation of I ❤ U moving down on the led matrix
*/
#include "homework7.h"
unsigned char code display[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // space
0x00, 0x3C, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3C, // I
0x00, 0x66, 0xFF, 0xFF, 0xFF, 0x7E, 0x3C, 0x18, // ❤
0x00, 0x66, 0x66, 0x66, 0x66, 0x66, 0x7E, 0x3C, // U
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // space
};
void test3()
{
EA = 1;
TMOD = 0x01;
TH0 = 0xFC;
TL0 = 0x67;
ET0 = 1;
TR0 = 1;
while (1);
}
void timer0ISF() interrupt 1
{
static unsigned char i = 0;
static unsigned char tmr = 0;
static unsigned char index = 32;
TH0 = 0xFC;
TL0 = 0x67;
P2 = 0xFF;
switch_138(i);
i++;
P2 = ~display[index + i];
if (i >= 8) {
i = 0;
}
tmr++;
if (tmr >= 250) {
tmr = 0;
if (index == 0) {
index = 32;
} else {
index--;
}
}
}
void main()
{
test3();
}
+87
View File
@@ -0,0 +1,87 @@
/*
* @name: test4.c
* @author: msksbr
* @date: 2025-05-25
* @description: a test for homework7's homework tests
* @version: 1.0
* homework zh_CN: 点阵显示一个 I ❤ U 的向右移动动画
* homework EN: display a I ❤ U moving right animation on the led matrix
*/
#include "homework7.h"
unsigned char code frames[30][8] = {
{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
{0xFF, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F},
{0xFF, 0x3F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x3F},
{0xFF, 0x1F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x1F},
{0xFF, 0x0F, 0x9F, 0x9F, 0x9F, 0x9F, 0x9F, 0x0F},
{0xFF, 0x87, 0xCF, 0xCF, 0xCF, 0xCF, 0xCF, 0x87},
{0xFF, 0xC3, 0xE7, 0xE7, 0xE7, 0xE7, 0xE7, 0xC3},
{0xFF, 0xE1, 0x73, 0x73, 0x73, 0xF3, 0xF3, 0xE1},
{0xFF, 0x70, 0x39, 0x39, 0x39, 0x79, 0xF9, 0xF0},
{0xFF, 0x38, 0x1C, 0x1C, 0x1C, 0x3C, 0x7C, 0xF8},
{0xFF, 0x9C, 0x0E, 0x0E, 0x0E, 0x1E, 0x3E, 0x7C},
{0xFF, 0xCE, 0x07, 0x07, 0x07, 0x0F, 0x1F, 0x3E},
{0xFF, 0x67, 0x03, 0x03, 0x03, 0x07, 0x0F, 0x9F},
{0xFF, 0x33, 0x01, 0x01, 0x01, 0x03, 0x87, 0xCF},
{0xFF, 0x99, 0x00, 0x00, 0x00, 0x81, 0xC3, 0xE7},
{0xFF, 0xCC, 0x80, 0x80, 0x80, 0xC0, 0xE1, 0xF3},
{0xFF, 0xE6, 0xC0, 0xC0, 0xC0, 0xE0, 0xF0, 0xF9},
{0xFF, 0x73, 0x60, 0x60, 0x60, 0x70, 0x78, 0xFC},
{0xFF, 0x39, 0x30, 0x30, 0x30, 0x38, 0x3C, 0x7E},
{0xFF, 0x9C, 0x98, 0x98, 0x98, 0x9C, 0x1E, 0x3F},
{0xFF, 0xCE, 0xCC, 0xCC, 0xCC, 0xCE, 0x0F, 0x1F},
{0xFF, 0x67, 0x66, 0x66, 0x66, 0x67, 0x07, 0x0F},
{0xFF, 0x33, 0x33, 0x33, 0x33, 0x33, 0x03, 0x87},
{0xFF, 0x99, 0x99, 0x99, 0x99, 0x99, 0x81, 0xC3},
{0xFF, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xC0, 0xE1},
{0xFF, 0xE6, 0xE6, 0xE6, 0xE6, 0xE6, 0xE0, 0xF0},
{0xFF, 0xF3, 0xF3, 0xF3, 0xF3, 0xF3, 0xF0, 0xF8},
{0xFF, 0xF9, 0xF9, 0xF9, 0xF9, 0xF9, 0xF8, 0xFC},
{0xFF, 0xFC, 0xFC, 0xFC, 0xFC, 0xFC, 0xFC, 0xFE},
{0xFF, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFF}};
void test4()
{
EA = 1;
ENLED = 0;
ADDR3 = 0;
TMOD = 0x01;
TH0 = 0xFC;
TL0 = 0x67;
ET0 = 1;
TR0 = 1;
while (1);
}
void InterruptTimer0() interrupt 1
{
static unsigned char i = 0;
static unsigned char tmr = 0;
static unsigned char index = 29;
TH0 = 0xFC;
TL0 = 0x67;
P2 = 0xFF;
switch_138(i);
i++;
if (i >= 8) {
i = 0;
}
P2 = frames[index][i];
tmr++;
if (tmr >= 250) {
tmr = 0;
if (index == 0) {
index = 30;
} else {
index--;
}
}
}
void main()
{
test4();
}
+65
View File
@@ -0,0 +1,65 @@
/*
* @name: test5.c
* @author: msksbr
* @date: 2025-05-25
* @description: a test for homework7's homework tests
* @version: 1.0f: fix the bug that charset is RL reversed
* homework zh_CN: 基于点阵的 9 到 0 的倒计时秒表显示
* homework EN: display a countdown timer on the led matrix from 9 to 0
*/
#include "homework7.h"
unsigned char code number_char[10][8] = {
{0x0E, 0x1B, 0x1B, 0x1B, 0x1B, 0x1B, 0x0E, 0x00}, // 0
{0x0C, 0x0F, 0x0C, 0x0C, 0x0C, 0x0C, 0x1F, 0x00}, // 1
{0x0F, 0x1B, 0x18, 0x1C, 0x0E, 0x07, 0x1F, 0x00}, // 2
{0x0F, 0x1B, 0x18, 0x1E, 0x18, 0x1B, 0x0F, 0x00}, // 3
{0x0C, 0x0C, 0x0E, 0x0F, 0x1F, 0x0C, 0x0C, 0x00}, // 4
{0x1F, 0x03, 0x0F, 0x18, 0x18, 0x1B, 0x0F, 0x00}, // 5
{0x1E, 0x07, 0x0F, 0x1B, 0x1B, 0x1F, 0x0E, 0x00}, // 6
{0x1F, 0x18, 0x1C, 0x0C, 0x0E, 0x06, 0x06, 0x00}, // 7
{0x0E, 0x1B, 0x1F, 0x1F, 0x1B, 0x1B, 0x0E, 0x00}, // 8
{0x0E, 0x1B, 0x1B, 0x1B, 0x1E, 0x1C, 0x0F, 0x00} // 9
};
void test5()
{
TMOD = 0x10;
TH1 = 0xFC;
TL1 = 0x18;
TR1 = 1;
ET1 = 1;
EA = 1;
while (1);
}
void timer1_ISR() interrupt 3
{
static unsigned char i = 0;
static unsigned int count = 0;
static unsigned char current_num = 9;
TH1 = 0xFC;
TL1 = 0x18;
P2 = 0xFF;
switch_138(i);
P2 = ~number_char[current_num][i];
if (++i >= 8) i = 0;
if (++count >= 1000) {
count = 0;
if (current_num > 0) {
current_num--;
} else {
current_num = 9;
}
}
}
void main()
{
test5();
}
+38
View File
@@ -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
+80
View File
@@ -0,0 +1,80 @@
{
"name": "homework8",
"type": "C51",
"dependenceList": [],
"srcDirs": [
"src"
],
"virtualFolder": {
"name": "<virtual_root>",
"files": [],
"folders": []
},
"outDir": "build",
"deviceName": null,
"packDir": null,
"miscInfo": {
"uid": "4605848772e4bc90af79b39d074376ac"
},
"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"
}
+20
View File
@@ -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: {}
+15
View File
@@ -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
+1
View File
@@ -0,0 +1 @@
{}
+40
View File
@@ -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": []
}
]
}
+44
View File
@@ -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"
]
}
}
Binary file not shown.
+29
View File
@@ -0,0 +1,29 @@
#include <reg52.h>
sbit ADDR0 = P1 ^ 0;
sbit ADDR1 = P1 ^ 1;
sbit ADDR2 = P1 ^ 2;
sbit ADDR3 = P1 ^ 3;
sbit ENLED = P1 ^ 4;
sbit LED9 = P0 ^ 7;
sbit LED8 = P0 ^ 6;
sbit LED7 = P0 ^ 5;
sbit LED6 = P0 ^ 4;
sbit KEY1 = P2 ^ 4;
sbit KEY2 = P2 ^ 5;
sbit KEY3 = P2 ^ 6;
sbit KEY4 = P2 ^ 7;
void main()
{
ENLED = 0;
ADDR3 = 1;
ADDR2 = 1;
ADDR1 = 1;
ADDR0 = 0;
P2 = 0xF7;
while (1) {
LED9 = KEY1;
LED8 = KEY2;
LED7 = KEY3;
LED6 = KEY4;
}
}