Hi,
In this example, instead of writing a custom GUI in B4PPC to control the
Address and Enable lines of a 74HC138, I used the 20 Custom Buttons
program written for the A81 Tablet.
The 20 Custom Buttons program allows you to assign a Text Label and
a single ASCII character value to each button.
For the 74HC138, there are 3 Address lines (A2, A1, A0) and 3 Enable
lines (1\, 2\, 3).
The Address lines (A2, A1, A0) can be set to any of the following
8 values:
000
001
010
011
100
101
110
111
The Enable lines (1\, 2\, 3) can be set either High or Low.
The 74HC138 is fully enabled when:
Enable 1\ line is Low.
Enable 2\ line is Low.
Enable 3 line is High.
In the 20 Custom Buttons program:
8 buttons will be used for Addresses (000 thru 111).
2 buttons will be used for Enable 1\ (High and Low).
2 buttons will be used for Enable 2\ (High and Low).
2 buttons will be used for Enable 3 (High and Low).
So, 14 out of the 20 available buttons will be used and
6 buttons will be left unused.
The 14 buttons were assigned the following ASCII character
values:
Address 000 assigned to ASCII character: A
Address 001 assigned to ASCII character: B
Address 010 assigned to ASCII character: C
Address 011 assigned to ASCII character: D
Address 100 assigned to ASCII character: E
Address 101 assigned to ASCII character: F
Address 110 assigned to ASCII character: G
Address 111 assigned to ASCII character: H
Enable 1\ = Hi assigned to ASCII character: I
Enable 1\ = Low assigned to ASCII character: J
Enable 2\ = Hi assigned to ASCII character: K
Enable 2\ = Low assigned to ASCII character: L
Enable 3 = Hi assigned to ASCII character: M
Enable 3 = Low assigned to ASCII character: N
The 20 Custom Buttons program is posted in the forum,
and can be downloaded from there.
I used the Firefly BP Bluetooth adapter, an RS232 to TTL
converter and a Basic Stamp to interface to the 74HC138
with a Witstech A81 7-inch Tablet running the 20 Custom
Buttons program written in B4PPC.
You can write a Custom GUI or use a customizable app
like 20 Custom Buttons to interface to your hardware
circuit designs.
Here is a listing of the Basic Stamp code to control
the 74HC138:
' {$STAMP BS2p}
' {$PBASIC 2.5}
serdata VAR Byte
Baud CON 240
INPUT 15
OUTPUT 0
OUTPUT 1
OUTPUT 2
OUTPUT 3
OUTPUT 4
OUTPUT 5
'Address line A0 of the 74HC138 is connected to Basic Stamp output line P0.
'Address line A1 of the 74HC138 is connected to Basic Stamp output line P1.
'Address line A2 of the 74HC138 is connected to Basic Stamp output line P2.
'At Power-up, Initialize Address lines A0,A1,A2 by setting them all Low.
LOW 0
LOW 1
LOW 2
'Active low Enable line 1\ of the 74HC138 is connected to Basic Stamp output line P3.
'Active low Enable line 2\ of the 74HC138 is connected to Basic Stamp output line P4.
'Active high Enable line 3 of the 74HC138 is connected to Basic Stamp output line P5.
'At Power-up, Initialize Enable lines 1\,2\,3 to their inactive states.
HIGH 3
HIGH 4
LOW 5
Main:
DO
SERIN 15,Baud,[serdata]
'Character A was received. Set lines P0,P1,P2 equal to Address: 000
IF serdata=65 THEN
LOW 0
LOW 1
LOW 2
ENDIF
'Character B was received. Set lines P0,P1,P2 equal to Address: 001
IF serdata=66 THEN
HIGH 0
LOW 1
LOW 2
ENDIF
'Character C was received. Set lines P0,P1,P2 equal to Address: 010
IF serdata=67 THEN
LOW 0
HIGH 1
LOW 2
ENDIF
'Character D was received. Set lines P0,P1,P2 equal to Address: 011
IF serdata=68 THEN
HIGH 0
HIGH 1
LOW 2
ENDIF
'Character E was received. Set lines P0,P1,P2 equal to Address: 100
IF serdata=69 THEN
LOW 0
LOW 1
HIGH 2
ENDIF
'Character F was received. Set lines P0,P1,P2 equal to Address: 101
IF serdata=70 THEN
HIGH 0
LOW 1
HIGH 2
ENDIF
'Character G was received. Set lines P0,P1,P2 equal to Address: 110
IF serdata=71 THEN
LOW 0
HIGH 1
HIGH 2
ENDIF
'Character H was received. Set lines P0,P1,P2 equal to Address: 111
IF serdata=72 THEN
HIGH 0
HIGH 1
HIGH 2
ENDIF
'Character I was received. Set P3 High, to set Enable 1\ line High.
IF serdata=73 THEN
HIGH 3
ENDIF
'Character J was received. Set P3 Low, to set Enable 1\ line Low.
IF serdata=74 THEN
LOW 3
ENDIF
'Character K was received. Set P4 High, to set Enable 2\ line High.
IF serdata=75 THEN
HIGH 4
ENDIF
'Character L was received. Set P4 Low, to set Enable 2\ line Low.
IF serdata=76 THEN
LOW 4
ENDIF
'Character M was received. Set P5 High, to set Enable 3 line High.
IF serdata=77 THEN
HIGH 5
ENDIF
'Character N was received. Set P5 Low, to set Enable 3 line Low.
IF serdata=78 THEN
LOW 5
ENDIF
LOOP ' repeat forever
END
In this example, instead of writing a custom GUI in B4PPC to control the
Address and Enable lines of a 74HC138, I used the 20 Custom Buttons
program written for the A81 Tablet.
The 20 Custom Buttons program allows you to assign a Text Label and
a single ASCII character value to each button.
For the 74HC138, there are 3 Address lines (A2, A1, A0) and 3 Enable
lines (1\, 2\, 3).
The Address lines (A2, A1, A0) can be set to any of the following
8 values:
000
001
010
011
100
101
110
111
The Enable lines (1\, 2\, 3) can be set either High or Low.
The 74HC138 is fully enabled when:
Enable 1\ line is Low.
Enable 2\ line is Low.
Enable 3 line is High.
In the 20 Custom Buttons program:
8 buttons will be used for Addresses (000 thru 111).
2 buttons will be used for Enable 1\ (High and Low).
2 buttons will be used for Enable 2\ (High and Low).
2 buttons will be used for Enable 3 (High and Low).
So, 14 out of the 20 available buttons will be used and
6 buttons will be left unused.
The 14 buttons were assigned the following ASCII character
values:
Address 000 assigned to ASCII character: A
Address 001 assigned to ASCII character: B
Address 010 assigned to ASCII character: C
Address 011 assigned to ASCII character: D
Address 100 assigned to ASCII character: E
Address 101 assigned to ASCII character: F
Address 110 assigned to ASCII character: G
Address 111 assigned to ASCII character: H
Enable 1\ = Hi assigned to ASCII character: I
Enable 1\ = Low assigned to ASCII character: J
Enable 2\ = Hi assigned to ASCII character: K
Enable 2\ = Low assigned to ASCII character: L
Enable 3 = Hi assigned to ASCII character: M
Enable 3 = Low assigned to ASCII character: N
The 20 Custom Buttons program is posted in the forum,
and can be downloaded from there.
I used the Firefly BP Bluetooth adapter, an RS232 to TTL
converter and a Basic Stamp to interface to the 74HC138
with a Witstech A81 7-inch Tablet running the 20 Custom
Buttons program written in B4PPC.
You can write a Custom GUI or use a customizable app
like 20 Custom Buttons to interface to your hardware
circuit designs.
Here is a listing of the Basic Stamp code to control
the 74HC138:
' {$STAMP BS2p}
' {$PBASIC 2.5}
serdata VAR Byte
Baud CON 240
INPUT 15
OUTPUT 0
OUTPUT 1
OUTPUT 2
OUTPUT 3
OUTPUT 4
OUTPUT 5
'Address line A0 of the 74HC138 is connected to Basic Stamp output line P0.
'Address line A1 of the 74HC138 is connected to Basic Stamp output line P1.
'Address line A2 of the 74HC138 is connected to Basic Stamp output line P2.
'At Power-up, Initialize Address lines A0,A1,A2 by setting them all Low.
LOW 0
LOW 1
LOW 2
'Active low Enable line 1\ of the 74HC138 is connected to Basic Stamp output line P3.
'Active low Enable line 2\ of the 74HC138 is connected to Basic Stamp output line P4.
'Active high Enable line 3 of the 74HC138 is connected to Basic Stamp output line P5.
'At Power-up, Initialize Enable lines 1\,2\,3 to their inactive states.
HIGH 3
HIGH 4
LOW 5
Main:
DO
SERIN 15,Baud,[serdata]
'Character A was received. Set lines P0,P1,P2 equal to Address: 000
IF serdata=65 THEN
LOW 0
LOW 1
LOW 2
ENDIF
'Character B was received. Set lines P0,P1,P2 equal to Address: 001
IF serdata=66 THEN
HIGH 0
LOW 1
LOW 2
ENDIF
'Character C was received. Set lines P0,P1,P2 equal to Address: 010
IF serdata=67 THEN
LOW 0
HIGH 1
LOW 2
ENDIF
'Character D was received. Set lines P0,P1,P2 equal to Address: 011
IF serdata=68 THEN
HIGH 0
HIGH 1
LOW 2
ENDIF
'Character E was received. Set lines P0,P1,P2 equal to Address: 100
IF serdata=69 THEN
LOW 0
LOW 1
HIGH 2
ENDIF
'Character F was received. Set lines P0,P1,P2 equal to Address: 101
IF serdata=70 THEN
HIGH 0
LOW 1
HIGH 2
ENDIF
'Character G was received. Set lines P0,P1,P2 equal to Address: 110
IF serdata=71 THEN
LOW 0
HIGH 1
HIGH 2
ENDIF
'Character H was received. Set lines P0,P1,P2 equal to Address: 111
IF serdata=72 THEN
HIGH 0
HIGH 1
HIGH 2
ENDIF
'Character I was received. Set P3 High, to set Enable 1\ line High.
IF serdata=73 THEN
HIGH 3
ENDIF
'Character J was received. Set P3 Low, to set Enable 1\ line Low.
IF serdata=74 THEN
LOW 3
ENDIF
'Character K was received. Set P4 High, to set Enable 2\ line High.
IF serdata=75 THEN
HIGH 4
ENDIF
'Character L was received. Set P4 Low, to set Enable 2\ line Low.
IF serdata=76 THEN
LOW 4
ENDIF
'Character M was received. Set P5 High, to set Enable 3 line High.
IF serdata=77 THEN
HIGH 5
ENDIF
'Character N was received. Set P5 Low, to set Enable 3 line Low.
IF serdata=78 THEN
LOW 5
ENDIF
LOOP ' repeat forever
END
Attachments
Last edited: