module BCD7
title 'LED HEX-to-seven-segment decoder
Use GAL16V8. xiaoqi Jan.5.2002'
" a
" --- HEX-to-seven-segment decoder similar to the 7449
" f| g |b
" --- 笔段定义
" e| d |c
" ---
bcd7 device 'P16V8R';
OI2,OI1,OI0,D0,D1,D2,D3,D4 pin 7,8,9,2,3,4,5,6;
a,b,c,d,e,f,g,OOC pin 13,14,15,16,17,18,19,12 istype 'com';
bcd = [D4,D3,D2,D1,D0];
led = [a,b,c,d,e,f,g];
ON,OFF = 0,1; " 共阳结构数码管
L,H,X,Z = 0,1,.X.,.Z.;
@dcset
truth_table ( bcd -> [ a , b , c , d , e , f , g ])
0 -> [ ON, ON, ON, ON, ON, ON, OFF]; "0
1 -> [OFF, ON, ON, OFF, OFF, OFF, OFF]; "1
2 -> [ ON, ON, OFF, ON, ON, OFF, ON]; "2
3 -> [ ON, ON, ON, ON, OFF, OFF, ON]; "3
4 -> [OFF, ON, ON, OFF, OFF, ON, ON]; "4
5 -> [ ON, OFF, ON, ON, OFF, ON, ON]; "5
6 -> [ ON, OFF, ON, ON, ON, ON, ON]; "6
7 -> [ ON, ON, ON, OFF, OFF, OFF, OFF]; "7
8 -> [ ON, ON, ON, ON, ON, ON, ON]; "8
9 -> [ ON, ON, ON, ON, OFF, ON, ON]; "9
10 -> [ ON, ON, ON, OFF, ON, ON, ON]; "A
11 -> [OFF, OFF, ON, ON, ON, ON, ON]; "b
12 -> [OFF, OFF, OFF, ON, ON, OFF, ON]; "c
13 -> [OFF, ON, ON, ON, ON, OFF, ON]; "d
14 -> [ ON, OFF, OFF, ON, ON, ON, ON]; "E
15 -> [ ON, OFF, OFF, OFF, ON, ON, ON]; "F
16 -> [OFF, ON, ON, OFF, ON, ON, ON]; "H
17 -> [OFF, OFF, OFF, OFF, OFF, OFF, OFF];
18 -> [OFF, OFF, OFF, OFF, OFF, OFF, OFF];
19 -> [OFF, OFF, OFF, OFF, OFF, OFF, OFF];
20 -> [OFF, OFF, OFF, OFF, OFF, OFF, OFF];
21 -> [OFF, OFF, OFF, OFF, OFF, OFF, OFF];
22 -> [OFF, OFF, OFF, OFF, OFF, OFF, OFF];
23 -> [OFF, OFF, OFF, OFF, OFF, OFF, OFF];
24 -> [OFF, OFF, OFF, OFF, OFF, OFF, OFF];
25 -> [OFF, OFF, OFF, OFF, OFF, OFF, OFF];
26 -> [OFF, OFF, OFF, OFF, OFF, OFF, OFF];
27 -> [OFF, OFF, OFF, OFF, OFF, OFF, OFF];
28 -> [OFF, OFF, OFF, OFF, OFF, OFF, OFF];
29 -> [OFF, OFF, OFF, OFF, OFF, OFF, OFF];
30 -> [OFF, OFF, OFF, OFF, OFF, OFF, OFF];
31 -> [OFF, OFF, OFF, OFF, OFF, OFF, OFF];
truth_table ( [OI2 , OI1, OI0] -> [ OOC ]) "多余IO制作一个门电路
[ 0, 0, 0] -> [ 1 ]; "这个逻辑关系可以随意设定
[ 1, 0, 0] -> [ 0 ];
[ 0, 1, 0] -> [ 0 ];
[ 0, 0, 1] -> [ 0 ];
[ 1, 1, 0] -> [ 0 ];
[ 1, 0, 1] -> [ 0 ];
[ 0, 1, 1] -> [ 0 ];
[ 1, 1, 1] -> [ 1 ];
"校对部分
test_vectors ( bcd -> [ a , b , c , d , e , f , g ])
0 -> [ ON, ON, ON, ON, ON, ON, OFF]; "0
1 -> [OFF, ON, ON, OFF, OFF, OFF, OFF]; "1
2 -> [ ON, ON, OFF, ON, ON, OFF, ON]; "2
3 -> [ ON, ON, ON, ON, OFF, OFF, ON]; "3
4 -> [OFF, ON, ON, OFF, OFF, ON, ON]; "4
5 -> [ ON, OFF, ON, ON, OFF, ON, ON]; "5
6 -> [ ON, OFF, ON, ON, ON, ON, ON]; "6
7 -> [ ON, ON, ON, OFF, OFF, OFF, OFF]; "7
8 -> [ ON, ON, ON, ON, ON, ON, ON]; "8
9 -> [ ON, ON, ON, ON, OFF, ON, ON]; "9
10 -> [ ON, ON, ON, OFF, ON, ON, ON]; "A
11 -> [OFF, OFF, ON, ON, ON, ON, ON]; "b
12 -> [OFF, OFF, OFF, ON, ON, OFF, ON]; "c
13 -> [OFF, ON, ON, ON, ON, OFF, ON]; "d
14 -> [ ON, OFF, OFF, ON, ON, ON, ON]; "E
15 -> [ ON, OFF, OFF, OFF, ON, ON, ON]; "F
16 -> [OFF, ON, ON, OFF, ON, ON, ON]; "H
17 -> [OFF, OFF, OFF, OFF, OFF, OFF, OFF];
18 -> [OFF, OFF, OFF, OFF, OFF, OFF, OFF];
19 -> [OFF, OFF, OFF, OFF, OFF, OFF, OFF];
20 -> [OFF, OFF, OFF, OFF, OFF, OFF, OFF];
21 -> [OFF, OFF, OFF, OFF, OFF, OFF, OFF];
22 -> [OFF, OFF, OFF, OFF, OFF, OFF, OFF];
23 -> [OFF, OFF, OFF, OFF, OFF, OFF, OFF];
24 -> [OFF, OFF, OFF, OFF, OFF, OFF, OFF];
25 -> [OFF, OFF, OFF, OFF, OFF, OFF, OFF];
26 -> [OFF, OFF, OFF, OFF, OFF, OFF, OFF];
27 -> [OFF, OFF, OFF, OFF, OFF, OFF, OFF];
28 -> [OFF, OFF, OFF, OFF, OFF, OFF, OFF];
29 -> [OFF, OFF, OFF, OFF, OFF, OFF, OFF];
30 -> [OFF, OFF, OFF, OFF, OFF, OFF, OFF];
31 -> [OFF, OFF, OFF, OFF, OFF, OFF, OFF];
"附加逻辑电路校对
test_vectors ( [OI2 , OI1, OI0] -> [ OOC ])
[ 0, 0, 0] -> [ 1 ];
[ 1, 0, 0] -> [ 0 ];
[ 0, 1, 0] -> [ 0 ];
[ 0, 0, 1] -> [ 0 ];
[ 1, 1, 0] -> [ 0 ];
[ 1, 0, 1] -> [ 0 ];
[ 0, 1, 1] -> [ 0 ];
[ 1, 1, 1] -> [ 1 ];
end BCD7
以上两个例程都是用abel4编译的,GAL编程并不很复杂,作为一般应用,编编这样的电路就已经可以对付一阵子了。如果想动手的可以
到主页上下载ABEL4软件。有关这个软件的安装使用方法,请阅读解压后的READ.ME。安装ABEL4以后,软件提供了一大堆的实例演示程序,
稍作修改就可以为你解决实际需要,篡改是学习入门的捷径,试试看吧。 |