archieve: homework7 test2
This commit is contained in:
@@ -18,7 +18,9 @@
|
|||||||
},
|
},
|
||||||
"targets": {
|
"targets": {
|
||||||
"Debug": {
|
"Debug": {
|
||||||
"excludeList": [],
|
"excludeList": [
|
||||||
|
"src/test1.c"
|
||||||
|
],
|
||||||
"toolchain": "Keil_C51",
|
"toolchain": "Keil_C51",
|
||||||
"compileConfig": {
|
"compileConfig": {
|
||||||
"options": "null"
|
"options": "null"
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
"C_Cpp.default.configurationProvider": "cl.eide",
|
"C_Cpp.default.configurationProvider": "cl.eide",
|
||||||
"C_Cpp.errorSquiggles": "disabled",
|
"C_Cpp.errorSquiggles": "disabled",
|
||||||
"files.associations": {
|
"files.associations": {
|
||||||
|
"*.dbclient-js": "javascript",
|
||||||
".eideignore": "ignore",
|
".eideignore": "ignore",
|
||||||
"*.a51": "a51",
|
"*.a51": "a51",
|
||||||
"*.h": "c",
|
"*.h": "c",
|
||||||
@@ -18,7 +19,8 @@
|
|||||||
"*.c++": "cpp",
|
"*.c++": "cpp",
|
||||||
"*.cpp": "cpp",
|
"*.cpp": "cpp",
|
||||||
"*.cxx": "cpp",
|
"*.cxx": "cpp",
|
||||||
"*.cc": "cpp"
|
"*.cc": "cpp",
|
||||||
|
"REG52.H": "cpp"
|
||||||
},
|
},
|
||||||
"[yaml]": {
|
"[yaml]": {
|
||||||
"editor.insertSpaces": true,
|
"editor.insertSpaces": true,
|
||||||
|
|||||||
@@ -57,15 +57,21 @@ void switch_138(unsigned char n)
|
|||||||
// 2. void delay_ms(unsigned char ms): a timer by ms base on timer0 mode 1
|
// 2. void delay_ms(unsigned char ms): a timer by ms base on timer0 mode 1
|
||||||
void delay_ms(unsigned char ms)
|
void delay_ms(unsigned char ms)
|
||||||
{
|
{
|
||||||
unsigned char i;
|
TMOD &= 0xF0; // set the timer mode to 16-bit timer mode.
|
||||||
TMOD &= 0xF0;
|
TMOD |= 0x01; // set the timer mode to 16-bit timer mode.
|
||||||
TMOD |= 0x01;
|
|
||||||
for (i = 0; i < ms; i++) {
|
// 1ms timer definition:
|
||||||
TH0 = 0xFC;
|
TH0 = 0XFC;
|
||||||
TL0 = 0x18;
|
TL0 = 0X18;
|
||||||
|
|
||||||
|
// start the timer:
|
||||||
TR0 = 1;
|
TR0 = 1;
|
||||||
while (!TF0);
|
|
||||||
TR0 = 0;
|
while (ms--) {
|
||||||
TF0 = 0;
|
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,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();
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user