archieve: homework7 test1

This commit is contained in:
2025-05-24 23:29:42 +08:00
parent 097e654ba5
commit 1b64a5df5b
2 changed files with 31 additions and 8 deletions
+9 -8
View File
@@ -31,23 +31,24 @@ 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 = P2 ^ 1; // @var ADDR1: to B(A1)
sbit ADDR2 = P2 ^ 2; // @var ADDR2: to C(A2)
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 = P2 ^ 3; // @var ADDR3: to E1
sbit ENLED = P2 ^ 4; // @var ENLED: to E2 & E3
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 = 1;
ADDR3 = 0;
// @subsection: turn n to 3 bit binary number
bit A0 = n & 0x01;
bit A1 = (n >> 1) & 0x01;
bit A2 = (n >> 2) & 0x01;
A0 = n & 0x01;
A1 = (n >> 1) & 0x01;
A2 = (n >> 2) & 0x01;
// @subsection: switch the 74HC138's address to n
ADDR0 = A0;
ADDR1 = A1;
+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();
}