Compare commits
40 Commits
8d9c147092
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 733eda29ab | |||
| 782b0867aa | |||
| e3c9129e83 | |||
| b13f90b5b4 | |||
| fd0fd805b5 | |||
| 6d58ed79d8 | |||
| 23ea54ea6a | |||
| a3cf2cbc8e | |||
| 1cda67295c | |||
| 420ae95641 | |||
| 3b682e993c | |||
| 1b64a5df5b | |||
| 097e654ba5 | |||
| dc3cb42124 | |||
| 436f5f224d | |||
| b5838a823c | |||
| 60f9efa1d6 | |||
| c4d507bd87 | |||
| 69137d8ec4 | |||
| 429a7b3f34 | |||
| 25333ffc84 | |||
| 1e079c187c | |||
| 8a90337479 | |||
| 346478498d | |||
| b0ce746a20 | |||
| b5fcd85516 | |||
| 6f0d7b3a86 | |||
| c8709b51af | |||
| 7ddc888862 | |||
| b3527f1fca | |||
| 32de81b3f5 | |||
| a0e6c0945a | |||
| cd667a286e | |||
| acd7bb9ec9 | |||
| 10051c6a18 | |||
| 0e7cdd870b | |||
| 55d4cdb6b2 | |||
| 2922312726 | |||
| 6712f5bf30 | |||
| e1acc51117 |
+4
-1
@@ -53,4 +53,7 @@ dkms.conf
|
||||
|
||||
# proteus workspace
|
||||
*.workspace
|
||||
*/Project Backups/
|
||||
*/Project Backups/
|
||||
|
||||
# others
|
||||
89C51_Simple_Calculator/
|
||||
@@ -21,7 +21,8 @@
|
||||
"excludeList": [
|
||||
"src/test1.c",
|
||||
"src/test2.c",
|
||||
"src/test3.c"
|
||||
"src/test3.c",
|
||||
"src/test4.c"
|
||||
],
|
||||
"toolchain": "Keil_C51",
|
||||
"compileConfig": {
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
// test5.c
|
||||
// 数码管静态显示秒表的倒计时;
|
||||
#include "homework4.h"
|
||||
|
||||
unsigned char cnt = 0; // 定时器溢出计数
|
||||
unsigned char second = 0; // 秒计数
|
||||
|
||||
void test5()
|
||||
{
|
||||
set_38_2SEG();
|
||||
TMOD = 0x01;
|
||||
TH0 = 0x3C;
|
||||
TL0 = 0xB0;
|
||||
TR0 = 1;
|
||||
|
||||
// 初始化时立即显示9
|
||||
second = 9;
|
||||
show_number(second);
|
||||
|
||||
while (1) {
|
||||
if (TF0 == 1) {
|
||||
TF0 = 0;
|
||||
TH0 = 0x3C;
|
||||
TL0 = 0xB0;
|
||||
if (++cnt >= 20) {
|
||||
cnt = 0;
|
||||
|
||||
second = (second > 0) ? --second : 9;
|
||||
show_number(second);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
test5();
|
||||
}
|
||||
@@ -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,85 @@
|
||||
{
|
||||
"name": "homework5",
|
||||
"type": "C51",
|
||||
"dependenceList": [],
|
||||
"srcDirs": [
|
||||
"src"
|
||||
],
|
||||
"virtualFolder": {
|
||||
"name": "<virtual_root>",
|
||||
"files": [],
|
||||
"folders": []
|
||||
},
|
||||
"outDir": "build",
|
||||
"deviceName": null,
|
||||
"packDir": null,
|
||||
"miscInfo": {
|
||||
"uid": "5e3bef3a1c523fd2f57bb1fdff63f27d"
|
||||
},
|
||||
"targets": {
|
||||
"Debug": {
|
||||
"excludeList": [
|
||||
"src/test.c",
|
||||
"src/test1.c",
|
||||
"src/test4.c",
|
||||
"src/test3.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"
|
||||
}
|
||||
@@ -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,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.
@@ -0,0 +1,86 @@
|
||||
// homework5.h
|
||||
/*
|
||||
* this header defines:
|
||||
* variables:
|
||||
* 1. pin numbers to control the LED and the Seg.
|
||||
* 2. seg chars to display the number on the Seg.
|
||||
* functions:
|
||||
* 1. control the LED and the Seg.
|
||||
* 2. to display the number on the Seg.
|
||||
* 3. to set the 38 transistors.
|
||||
* 4. to display the number on the Seg.
|
||||
* 5. timer.
|
||||
*/
|
||||
|
||||
#include <REG52.H>
|
||||
|
||||
// variables:
|
||||
// pin numbers:
|
||||
sbit BUS1A = P2 ^ 0; // BUS1A: BUS for the LED1(RED) and the Seg A.
|
||||
sbit BUS2B = P2 ^ 1; // BUS2B: BUS for the LED2(ORANGE) and the Seg B.
|
||||
sbit BUS3C = P2 ^ 2; // BUS3C: BUS for the LED3(YELLOW) and the Seg C.
|
||||
sbit BUS4D = P2 ^ 3; // BUS4D: BUS for the LED4(GREEN) and the Seg D.
|
||||
sbit BUS5E = P2 ^ 4; // BUS5E: BUS for the LED5(AQUA) and the Seg E.
|
||||
sbit BUS6F = P2 ^ 5; // BUS6F: BUS for the LED6(BLUE) and the Seg F.
|
||||
sbit BUS7G = P2 ^ 6; // BUS7G: BUS for the LED7(PURPLE) and the Seg G.
|
||||
sbit BUS8DP = P2 ^ 7; // BUS8DP: BUS for the LED8(WHITE) and the Seg DP.
|
||||
// 38 transistors controller:
|
||||
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:
|
||||
unsigned char code LedChar[] = {
|
||||
0xC0,
|
||||
0xF9,
|
||||
0XA4,
|
||||
0XB0,
|
||||
0X99,
|
||||
0X92,
|
||||
0X82,
|
||||
0XF8,
|
||||
0X80,
|
||||
0X90,
|
||||
0X88,
|
||||
0X83,
|
||||
0XC6,
|
||||
0XA1,
|
||||
0X86,
|
||||
0X8E,
|
||||
};
|
||||
|
||||
// functions:
|
||||
// 38 transistors controller:
|
||||
void set38Transistors(unsigned char number) // set the 38 transistors.
|
||||
{
|
||||
// turn on the 38 transistors:
|
||||
ENLED = 0;
|
||||
ADDR3 = 1;
|
||||
// split the number into 3 binary numbers:
|
||||
ADDR2 = (number & 0x04) >> 2;
|
||||
ADDR1 = (number & 0x02) >> 1;
|
||||
ADDR0 = (number & 0x01);
|
||||
}
|
||||
// timer
|
||||
int timer(unsigned int 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.
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
// test1.c
|
||||
// 数码管动态显示自己学号后6位
|
||||
// display the last 6 digits of your student ID on the Seg.
|
||||
|
||||
#include "homework5.h"
|
||||
unsigned char LedBuff[6] = {
|
||||
0xFF, 0XFF, 0XFF, 0XFF, 0XFF, 0XFF};
|
||||
unsigned char i = 0;
|
||||
unsigned char display_id[6] = {1, 3, 0, 0, 7, 1};
|
||||
|
||||
void test1()
|
||||
{
|
||||
// display the number on the Seg.
|
||||
// 5 is high digit.
|
||||
// 0 is low digit.
|
||||
LedBuff[5] = LedChar[display_id[0]];
|
||||
LedBuff[4] = LedChar[display_id[1]];
|
||||
LedBuff[3] = LedChar[display_id[2]];
|
||||
LedBuff[2] = LedChar[display_id[3]];
|
||||
LedBuff[1] = LedChar[display_id[4]];
|
||||
LedBuff[0] = LedChar[display_id[5]];
|
||||
while (1) {
|
||||
/*
|
||||
* seg id on 38 transistors:
|
||||
* Y0: LEDS0 the latest digit.
|
||||
* Y1: LEDS1 the second digit.
|
||||
* Y2: LEDS2 the third digit.
|
||||
* Y3: LEDS3 the forth digit.
|
||||
* Y4: LEDS4 the fifth digit.
|
||||
* Y5: LEDS5 the highest digit.
|
||||
* Y6: 2LED to the LED lights.
|
||||
*/
|
||||
set38Transistors(i);
|
||||
P2 = LedBuff[i];
|
||||
i++;
|
||||
timer(1);
|
||||
// reset the i to 0 when it reaches 6.
|
||||
if (i >= 6) {
|
||||
i = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
test1();
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
// test2.c
|
||||
// 不使用中断,让数码管动态显示秒表
|
||||
// display the stopwatch on the Seg. without using interrupt.
|
||||
/*
|
||||
* seg display format:
|
||||
* 00.00.00
|
||||
* HH.MM.SS
|
||||
* HH: hour, MM: minute, SS: second
|
||||
* dot . is dp
|
||||
*/
|
||||
|
||||
/*
|
||||
* how it work?
|
||||
* 1. sleep 1s
|
||||
* 2. count the seconds, minutes, hours.
|
||||
* 3. reset the seconds, minutes when it reaches 60.
|
||||
* 4. reset all when everything overflow.
|
||||
* 5. log the number in the buffer.
|
||||
* 6. display the number on the Seg.
|
||||
*/
|
||||
#include "homework5.h"
|
||||
unsigned char LedBuff[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; // buffer to store the seg chars.
|
||||
|
||||
void test2()
|
||||
{
|
||||
unsigned char second = 0; // to count the seconds.
|
||||
unsigned char minute = 0; // to count the minutes.
|
||||
unsigned char hour = 0; // to count the hours.
|
||||
unsigned char i = 0; // to count the times.
|
||||
unsigned long time_counter = 0;
|
||||
|
||||
while (1) {
|
||||
for (i = 0; i < 6; i++) {
|
||||
// display number
|
||||
set38Transistors(i);
|
||||
P2 = LedBuff[i];
|
||||
// display dot
|
||||
if (i == 2 || i == 4) {
|
||||
// 2nd dot between the minutes and seconds.
|
||||
// 4th dot between the hours and minutes.
|
||||
BUS8DP = 0; // display the dot.
|
||||
} else {
|
||||
BUS8DP = 1; // hide the dot on other places.
|
||||
}
|
||||
|
||||
timer(1); // delay 1ms.
|
||||
time_counter++;
|
||||
|
||||
// update time when 1000ms passed.
|
||||
if (time_counter >= 1000) {
|
||||
time_counter = 0; // reset the counter.
|
||||
second++; // count the seconds.
|
||||
// solve unit overflow.
|
||||
// second overflow
|
||||
if (second >= 60) {
|
||||
second = 0; // reset the second.
|
||||
minute++; // count the minutes.
|
||||
}
|
||||
// minute overflow.
|
||||
if (minute >= 60) {
|
||||
minute = 0; // reset the minute.
|
||||
hour++; // count the hours.
|
||||
}
|
||||
// everything overflow.
|
||||
if (hour >= 99 && second >= 59 && minute >= 59) {
|
||||
hour = 0; // reset the hour.
|
||||
second = 0; // reset the second.
|
||||
minute = 0; // reset the minute.
|
||||
}
|
||||
}
|
||||
// log the number in the buffer.
|
||||
// 5 is high digit.
|
||||
// 0 is low digit.
|
||||
LedBuff[5] = LedChar[hour / 10]; // log the hour tens.
|
||||
LedBuff[4] = LedChar[hour % 10]; // log the hour units.
|
||||
LedBuff[3] = LedChar[minute / 10]; // log the minute tens.
|
||||
LedBuff[2] = LedChar[minute % 10]; // log the minute units.
|
||||
LedBuff[1] = LedChar[second / 10]; // log the second tens.
|
||||
LedBuff[0] = LedChar[second % 10]; // log the second units.
|
||||
}
|
||||
}
|
||||
}
|
||||
void main()
|
||||
{
|
||||
test2();
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
// test3.c
|
||||
// 让数码管动态显示秒表,但只显示有效位,高位的0不显示
|
||||
// display the stopwatch on the Seg. but only display the valid digits.
|
||||
|
||||
/*
|
||||
* how it work?
|
||||
* 1. based on test2.c.
|
||||
* 2. add check to the buffer.
|
||||
* 3. only this unit is not 0 OR the previous unit is not 0, log the number in the buffer.
|
||||
* 4. so this is my niubility code.
|
||||
* 5. I'm so proud of myself.
|
||||
* 6. msksbr NB!!!
|
||||
* 7. msksbr NB!!!
|
||||
* 8. msksbr NB!!!
|
||||
*/
|
||||
|
||||
#include "homework5.h"
|
||||
unsigned char LedBuff[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; // buffer to store the seg chars.
|
||||
|
||||
void test3()
|
||||
{
|
||||
unsigned char second = 0; // to count the seconds.
|
||||
unsigned char minute = 0; // to count the minutes.
|
||||
unsigned char hour = 0; // to count the hours.
|
||||
unsigned char i = 0; // to count the times.
|
||||
unsigned long time_counter = 0;
|
||||
|
||||
while (1) {
|
||||
for (i = 0; i < 6; i++) {
|
||||
// display number
|
||||
set38Transistors(i);
|
||||
P2 = LedBuff[i];
|
||||
// display dot
|
||||
if (i == 2 || i == 4) {
|
||||
// 2nd dot between the minutes and seconds.
|
||||
// 4th dot between the hours and minutes.
|
||||
BUS8DP = 0; // display the dot.
|
||||
} else {
|
||||
BUS8DP = 1; // hide the dot on other places.
|
||||
}
|
||||
|
||||
timer(1); // delay 1ms.
|
||||
time_counter++;
|
||||
|
||||
// update time when 1000ms passed.
|
||||
if (time_counter >= 1000) {
|
||||
time_counter = 0; // reset the counter.
|
||||
second++; // count the seconds.
|
||||
// solve unit overflow.
|
||||
// second overflow
|
||||
if (second >= 60) {
|
||||
second = 0; // reset the second.
|
||||
minute++; // count the minutes.
|
||||
}
|
||||
// minute overflow.
|
||||
if (minute >= 60) {
|
||||
minute = 0; // reset the minute.
|
||||
hour++; // count the hours.
|
||||
}
|
||||
// everything overflow.
|
||||
if (hour >= 99 && second >= 59 && minute >= 59) {
|
||||
hour = 0; // reset the hour.
|
||||
second = 0; // reset the second.
|
||||
minute = 0; // reset the minute.
|
||||
}
|
||||
}
|
||||
// log the number in the buffer.
|
||||
// only log the valid digits.
|
||||
// 5 is high digit.
|
||||
// 0 is low digit.
|
||||
LedBuff[5] = hour >= 10 ? LedChar[hour / 10] : 0XFF; // log the hour tens.
|
||||
LedBuff[4] = hour > 0 ? LedChar[hour % 10] : 0XFF; // log the hour units.
|
||||
LedBuff[3] = (minute >= 10 || hour > 0) ? LedChar[minute / 10] : 0XFF; // log the minute tens.
|
||||
LedBuff[2] = minute > 0 ? LedChar[minute % 10] : 0XFF; // log the minute units.
|
||||
LedBuff[1] = (second >= 10 || minute > 0) ? LedChar[second / 10] : 0XFF; // log the second tens.
|
||||
LedBuff[0] = LedChar[second % 10]; // log the second units.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
test3();
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
// test4.c
|
||||
// 写一个从999999开始倒计时的秒表。并且改用定时器T1的中断来完成
|
||||
// make a stopwatch that counts down from 999999. and use interrupt to finish it.
|
||||
|
||||
#include "homework5.h"
|
||||
unsigned char LedBuff[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; // buffer to store the seg chars.
|
||||
volatile unsigned char i = 0; // to current digit.
|
||||
volatile unsigned long display_time = 999999; // to store the time to display.
|
||||
unsigned int cnt = 0; // to count interrupt.
|
||||
|
||||
// init timer
|
||||
void initTimer(void)
|
||||
{
|
||||
TMOD &= 0x0F; // clear TMOD.
|
||||
TMOD |= 0x10; // set TMOD to mode 1.
|
||||
TH1 = 0xFC; // 1ms timer.
|
||||
TL1 = 0x18;
|
||||
ET1 = 1; // enable timer 1 interrupt.
|
||||
EA = 1; // enable global interrupt.
|
||||
TR1 = 1; // start timer 1.
|
||||
}
|
||||
|
||||
// timer1 interrupt service routine.
|
||||
void timer1ISR(void) interrupt 3
|
||||
{
|
||||
TH1 = 0xFC; // reset timer.
|
||||
TL1 = 0x18;
|
||||
|
||||
// display the number.
|
||||
set38Transistors(i);
|
||||
P2 = LedBuff[i];
|
||||
i = (i + 1) % 6; // to switch to the next digit.
|
||||
|
||||
// 1s timer.
|
||||
if (++cnt >= 1000) { // if reached 1s.
|
||||
cnt = 0;
|
||||
if (display_time > 0) {
|
||||
display_time--; // decrease the time.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void test4()
|
||||
{
|
||||
initTimer();
|
||||
while (1) {
|
||||
// split the time into 6 digits.
|
||||
unsigned char first_digit = display_time / 100000; // to get the first digit.
|
||||
unsigned char second_digit = (display_time % 100000) / 10000; // to get the second digit.
|
||||
unsigned char third_digit = (display_time % 10000) / 1000; // to get the third digit.
|
||||
unsigned char fourth_digit = (display_time % 1000) / 100; // to get the fourth digit.
|
||||
unsigned char fifth_digit = (display_time % 100) / 10; // to get the fifth digit.
|
||||
unsigned char sixth_digit = display_time % 10; // to get the sixth digit.
|
||||
|
||||
// load the number in the buffer.
|
||||
// 5 is high digit.
|
||||
// 0 is low digit.
|
||||
LedBuff[5] = LedChar[first_digit]; // to display the first digit.
|
||||
LedBuff[4] = LedChar[second_digit]; // to display the second digit.
|
||||
LedBuff[3] = LedChar[third_digit]; // to display the third digit.
|
||||
LedBuff[2] = LedChar[fourth_digit]; // to display the fourth digit.
|
||||
LedBuff[1] = LedChar[fifth_digit]; // to display the fifth digit.
|
||||
LedBuff[0] = LedChar[sixth_digit]; // to display the sixth digit.
|
||||
}
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
test4();
|
||||
}
|
||||
@@ -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,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"
|
||||
}
|
||||
@@ -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,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.
@@ -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.
|
||||
@@ -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();
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
@@ -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,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"
|
||||
}
|
||||
@@ -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,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.
@@ -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.
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
@@ -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": "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"
|
||||
}
|
||||
@@ -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"
|
||||
]
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user