拿到一块板子,第一反应应是点亮板子上最基础的资源——LED灯。然而,CT107D扩展了很多IO口,从而使得点灯需要很多步操作。

CT107D在LED接入部分的原理图如下:
LED接入
右侧,LED的阳极各与一个阻值为300欧姆的上拉电阻相连并连接到VCC。左侧,阴极则连接到M74HC573M1R的输出引脚。

The 74HC573; 74HCT573 has octal D-type transparent latches featuring separate D-type inputs for each latch and 3-state true outputs for bus oriented applications. A latch enable (LE) input and an output enable (OE) input are common to all latches.

When LE is HIGH, data at the Dn inputs enter the latches. In this condition the latches are transparent, i.e. a latch output will change state each time its corresponding D input changes.

When LE is LOW the latches store the information that was present at the D-inputs a set-up time preceding the HIGH-to-LOW transition of LE. When OE is LOW, the contents of the 8 latches are available at the outputs. When OE is HIGH, the outputs go to the high-impedance OFF-state. Operation of the OE input does not affect the state of the latches.

由74HC_HCT573数据手册可知74HC573为一锁存器,其功能决定于LE的高低电平状态。
当LE处于高电平时,74HC573处于通透状态即输出端数据与输入端相同;当LE处于低电平时,74HC573处于锁存状态,保存上次通透时的数据。

为了使得左右数据通透,我们需要使Y4C为高电平,顺着网络标号寻找输出端为Y4C的电路。往下寻找,便可寻见74HC02,查阅芯片手册得知其为NOR门,电路中WR默认接地为低电平,若使Y4C为高电平,Y4应为低电平。
Y4C端电路
很自然地,在NOR门左侧我们可以看见74HC138,查阅芯片手册可知其为“3-to-8 Line Decoder”,即138译码器,输入3个IO口上的高低电平来扩展到右侧8个IO口。
HC138真值表
如需时IO输出端为低电平——L,则需配置左侧P2^5,P2^6,P^7的输入,Y4低电平对应输入为100。

让我们理清一下思路:P2^5,P2^6,P^7分别输入0,0,1通过138译码器拉低Y4电平。之后Y4的低电平输出通过NOR门被转换为高电平,输出到Y4C。Y4C高电平将74HC573置于通透状态,此时P0口状态直接控制LED小灯。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include<reg52.h>
typedef unsigned int uint;
typedef unsigned char uchar;
sbit HC138_A=P2^5;
sbit HC138_B=P2^6;
sbit HC138_C=P2^7;//138译码器输出端定义
void Init()
{
HC138_C=1;
HC138_B=0;
HC138_A=1;
P0=0X00;//初始化板上资源,关闭蜂鸣器与继电器
}

void Delay(uint t)
{
while(t--);//延时函数
}

void ledrunning()
{
uchar i;
for(i=0;i<3;i++)
{
HC138_C=1;
HC138_B=0;
HC138_A=0;
P0=0xff;//熄灭所有LED灯
Delay(30000000);
P0=0x00;//点亮所有LED小灯
Delay(30000000);
}
for(i=1;i<=8;i++)
{
P0=0xff<<i;//左移函数,每次循环均将已点亮小灯向左移动一位
Delay(30000000);
}
for(i=1;i<=8;i++)
{
P0=~(0xff<<i);//取反
Delay(30000000);
}

}


void main()
{
Init();
while(1)
{
ledrunning();
}
}

我们再来研究P0电平的左移与右移(左移右移空缺位补零):
初始状态下P0=0xff,LED小灯全部熄灭。当i=1时,P0左移一位变成1111 1110,LED点亮;当i=2时,P2左移两位变成1111 1100,LED1与LED2点亮;一直到i=8时,8颗LED全部点亮。

当全部点亮后,每颗LED再次进行取反,即0变为1,1变为0。最后i=1时,P0=0000 0001,只有LED1点亮。由此,达成LED流水灯。