Number System and BASIC Logic Gates

by mit41301 in Circuits > Electronics

4 Views, 0 Favorites, 0 Comments

Number System and BASIC Logic Gates

SI_base_Unit_2048.jpg
Morse.jpg
Braille-codes.jpg
tape_and_card.jpg

Number system is necessary in this universe. When we want to compute, measure, compare anything we need some representation which should be unique in nature. Basically we need to record or represent the magnitude or used to quantify.

There are SEVEN base units in SI. We need some mechanism to measure and quantify those units.

The representation may be sound in nature like Morse Code or Sensing with fingers like Braile Code. Or it may be light form.

Supplies

wincal.png
SCC.png

Any scientific calculator capable of performing Arithmetic and Logical operations using different base like Binary, Octal or Hexa decimal apart from normal Decimal.

To perform real operation on a 8 bit computer we can use MCS-51 based Single Chip Computer

There is a 8 bit Input/Output port available in the Single Chip Computer. We can use it as read hardware for performing Logic Gates using Switches and LEDs interfaced to PORT1 of the Single Chip Computer. We can use any of the pins for Switch and LED.

BINARY, OCTAL, DECIMAL and HEXA DECIMAL

0to15.jpeg

Humans always use decimal system in daily life. There are few exceptions like Time measurement and angle measurement uses different BASE.

For example counting from 0 to 15 in decimal system is like follows:

0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15

For the same above numbers represented in binary in following sequence

0000,0001,0010,0011,0100,0101,0110,0111,1000,1001,1010,1011,1100,1101,1110,1111

The same 0~15 in decimal represented in OCTAL(BASE 8) as

0,1,2,3,4,5,6,7,10,11,12,13,14,15,16,17

The same 0~15 in decimal represented in HEXA(BASE 16) as

0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F

We need to focus more on Decimal, Binary and Hexadecimal system. Octal systems were famous when Main Frame computer and human interaction is through Octal based.

To perform any Arithmetic operations, we need two numbers along with a operator.

Apart from this the LOGICAL input and output can be represented just as TRUE or FALSE or just 1 or 0

The logical operation can be any of AND, NAND, OR, NOR, XOR, XNOR and NOT.

The world is always filled with complements. Cold or Hot, Happy or Sorrow, Rich or poor, etc.

There are something which we can not quantify or compare which is Human Feelings like Happy, Joy, Pain, Sorrow, etc., So those human feelings falls under Logical rathen than Arithmetic.

BASIC LOGIC Gates

logicgates.png

Similar to Rainbow, Music, SI units, etc., Digital Logic circuits built upto fundamental Logic Gates.

  1. AND Gate
  2. OR Gate
  3. NOT Gate

These are primary Logic Gates. We can derive other logic gates

  1. NAND
  2. NOR
  3. XOR
  4. XNOR

When we design Logic Gates in paper or computer, we will not worry about the Logic Levels and Voltage.

Logic Input and Output can have the following values.

TRUE = 1 = HIGH

FALSE = 0 = LOW



BASIC LOGIC Gates

animation_and2.gif
animation_and2.gif
andornot.png

In this section we will see how the BASIC performs the Logic Operations. BASIC performs all the logic operation in 16 bit.

First we will see the Truth Table for each gate using minimal configuration. That is two bits for AND, OR and single bit for NOT gate.

  1. AND Gate
  2. OR Gate
  3. NOT Gate


Two Input AND GATE:

1 PRINT "AND GATE"
2 PRINT " A B Y"
10 FOR I=0 TO 3
20 READ A,B
25 PRINT A,B,
30 PRINT A.AND.B
40 NEXT I
80 DATA 0,0,0,1,1,0,1,1

The inputs are A, B and the output is Y.

All the possible input combination is represented by line 80 as DATA. For each cycle the program loads different values for A and B and performs the .AND. operation in line number 30. The output is printed as Y.

LIST
1 PRINT "AND GATE"
2 PRINT " A B Y"
10 FOR I=0 TO 3
20 READ A,B
25 PRINT A,B,
30 PRINT A.AND.B
40 NEXT I
80 DATA 0,0,0,1,1,0,1,1

READY
>RUN

AND GATE
A B Y
0 0 0
0 1 0
1 0 0
1 1 1

READY
>

The code and system output is shown above.

Two Input OR GATE:

1 PRINT " OR GATE"
2 PRINT " A B Y"
10 FOR I=0 TO 3
20 READ A,B
25 PRINT A,B,
30 PRINT A.OR.B
40 NEXT I
80 DATA 0,0,0,1,1,0,1,1

The program is same as the AND gate program except the line number 30 which performs .OR. operation here.

1 PRINT " OR GATE"
2 PRINT " A B Y"
10 FOR I=0 TO 3
20 READ A,B
25 PRINT A,B,
30 PRINT A.OR.B
40 NEXT I
80 DATA 0,0,0,1,1,0,1,1

READY
>RUN

OR GATE
A B Y
0 0 0
0 1 1
1 0 1
1 1 1

Program listing and RUN output are as above.

NOT GATE:

1 PRINT "NOT GATE"
2 PRINT " A Y"
10 FOR I=0 TO 1
20 READ A
25 PRINT A,
30 PRINT NOT(A).AND.1
40 NEXT I
80 DATA 0,1

The above is the listing of NOT gate. Compared to AND, OR gate which needs two inputs A,B for NOT gate we need only one input. The input bit can be assigned to 0 or 1 which is declared in line 80.

1 PRINT "NOT GATE"
2 PRINT " A Y"
10 FOR I=0 TO 1
20 READ A
25 PRINT A,
30 PRINT NOT(A).AND.1
40 NEXT I
80 DATA 0,1

READY
>RUN

NOT GATE
A Y
0 1
1 0

READY

When we RUN the program, we get the results for the NOT gate as shown above. The NOT gate operation is performed in line number 30. As mentioned above BASIC performs all logical operations as 16 bit data. Since we are considering only one BIT, we need to MASK all the unwanted bits by additional AND operation.

NAND, NOR, XOR, XNOR Gate

NAND GATE:

1 PRINT "NAND GATE"
2 PRINT " A B Y"
10 FOR I=0 TO 3
20 READ A,B
25 PRINT A,B,
30 PRINT NOT(A.AND.B).AND.1
40 NEXT I
80 DATA 0,0,0,1,1,0,1,1

READY
>RUN

NAND GATE
A B Y
0 0 1
0 1 1
1 0 1
1 1 0

NOR GATE:

1 PRINT "NOR GATE"
2 PRINT " A B Y"
10 FOR I=0 TO 3
20 READ A,B
25 PRINT A,B,
30 PRINT NOT(A.OR.B).AND.1
40 NEXT I
80 DATA 0,0,0,1,1,0,1,1

READY
>RUN

NOR GATE
A B Y
0 0 1
0 1 0
1 0 0
1 1 0

XOR GATE:

1 PRINT "XOR GATE"
2 PRINT " A B Y"
10 FOR I=0 TO 3
20 READ A,B
25 PRINT A,B,
30 PRINT A.XOR.B
40 NEXT I
80 DATA 0,0,0,1,1,0,1,1

READY
>RUN

XOR GATE
A B Y
0 0 0
0 1 1
1 0 1
1 1 0

The Logical XOR operation performed by line number 30 using .XOR. We can see the output.

XNOR GATE:

1 PRINT "XNOR GATE"
2 PRINT " A B Y"
10 FOR I=0 TO 3
20 READ A,B
25 PRINT A,B,
30 PRINT NOT(A.XOR.B).AND.1
40 NEXT I
80 DATA 0,0,0,1,1,0,1,1

READY
>RUN

XNOR GATE
A B Y
0 0 1
0 1 0
1 0 0
1 1 1

The Logical XNOR operation performed by line number 30 using .XOR. followed by NOT operation. We can see the output.

Conclusion

We learned the Binary, Octal, Decimal and Hexa Decimal number system along with the BASIC fundamental Logic gates operation by coding in BASIC-52 using a real 8 bit computer.

In the next Instructable we will see how to perform Logical Operations on 16 bit values using Hexa Decimal values.

All the codes used above is available from my Github