Codes and Code Converters Lecture L6.12 Section 6.5 Section 9.5.

29
Codes and Code Converters Lecture L6.12 Section 6.5 Section 9.5
  • date post

    20-Dec-2015
  • Category

    Documents

  • view

    224
  • download

    2

Transcript of Codes and Code Converters Lecture L6.12 Section 6.5 Section 9.5.

Page 1: Codes and Code Converters Lecture L6.12 Section 6.5 Section 9.5.

Codes andCode Converters

Lecture L6.12

Section 6.5

Section 9.5

Page 2: Codes and Code Converters Lecture L6.12 Section 6.5 Section 9.5.

Codes and Code Converters

• ASCII

• Binary-to-BCD Converters

• Gray Code

• Bar Codes

Page 3: Codes and Code Converters Lecture L6.12 Section 6.5 Section 9.5.

Standard ASCII CodesTable 9.2

Standard ASCII codesDec 0 16 32 48 64 80 96 112

Hex 0 1 2 3 4 5 6 7

0 0 NUL DLE blank 0 @ P p1 1 SOH DC1 ! 1 A Q a q2 2 STX DC2 " 2 B R b r3 3 ETX DC3 # 3 C S c s4 4 EOT DC4 $ 4 D T d t5 5 ENQ NAK % 5 E U e u6 6 ACK SYN & 6 F V f v7 7 BEL ETB ' 7 G W g w8 8 BS CAN ( 8 H X h x9 9 HT EM ) 9 I Y i y10 A LF SUB * : J Z j z11 B VT ESC + ; K [ k {12 C FF FS , < L \ l |13 D CR GS - = M ] m }14 E SO RS . > N ^ n ~15 F SI US / ? O _ o DEL

Page 4: Codes and Code Converters Lecture L6.12 Section 6.5 Section 9.5.

Dec Hx Oct Char Dec Hx Oct Html Chr Dec Hx Oct Html Chr Dec Hx Oct Html Chr 0 0 000 NUL 32 20 040 &#32; Space 64 40 100 &#64; @ 96 60 140 &#96; ` 1 1 001 SOH 33 21 041 &#33; ! 65 41 101 &#65; A 97 61 141 &#97; a 2 2 002 STX 34 22 042 &#34; “ 66 42 102 &#66; B 98 62 142 &#98; b 3 3 003 ETX 35 23 043 &#35; # 67 43 103 &#67; C 99 63 143 &#99; c 4 4 004 EOT 36 24 044 &#36; $ 68 44 104 &#68; D 100 64 144 &#100; d 5 5 005 ENQ 37 25 045 &#37; % 69 45 105 &#69; E 101 65 145 &#101; e 6 6 006 ACK 38 26 046 &#38; & 70 46 106 &#70; F 102 66 146 &#102; f 7 7 007 BEL 39 27 047 &#39; ‘ 71 47 107 &#71; G 103 67 147 &#103; g 8 8 010 BS 40 28 050 &#40; ( 72 48 110 &#72; H 104 68 150 &#104; h 9 9 011 TAB 41 29 051 &#41; ) 73 49 111 &#73; I 105 69 151 &#105; i

10 A 012 LF 42 2A 052 &#42; * 74 4A 112 &#74; J 106 6A 152 &#106; j 11 B 013 VT 43 2B 053 &#43; + 75 4B 113 &#75; K 107 6B 153 &#107; k 12 C 014 FF 44 2C 054 &#44; , 76 4C 114 &#76; L 108 6C 154 &#108; l 13 D 015 CR 45 2D 055 &#45; - 77 4D 115 &#77; M 109 6D 155 &#109; m 14 E 016 SO 46 2E 056 &#46; . 78 4E 116 &#78; N 110 6E 156 &#110; n 15 F 017 SI 47 2F 057 &#47; / 79 4F 117 &#79; O 111 6F 157 &#111; o 16 10 020 DLE 48 30 060 &#48; 0 80 50 120 &#80; P 112 70 160 &#112; p 17 11 021 DC1 49 31 061 &#49; 1 81 51 121 &#81; Q 113 71 161 &#113; q 18 12 022 DC2 50 32 062 &#50; 2 82 52 122 &#82; R 114 72 162 &#114; r 19 13 023 DC3 51 33 063 &#51; 3 83 53 123 &#83; S 115 73 163 &#115; s 20 14 024 DC4 52 34 064 &#52; 4 84 54 124 &#84; T 116 74 164 &#116; t 21 15 025 NAK 53 35 065 &#53; 5 85 55 125 &#85; U 117 75 165 &#117; u 22 16 026 SYN 54 36 066 &#54; 6 86 56 126 &#86; V 118 76 166 &#118; v 23 17 027 ETB 55 37 067 &#55; 7 87 57 127 &#87; W 119 77 167 &#119; w 24 18 030 CAN 56 38 070 &#56; 8 88 58 130 &#88; X 120 78 170 &#120; x 25 19 031 EM 57 39 071 &#57; 9 89 59 131 &#89; Y 121 79 171 &#121; y 26 1A 032 SUB 58 3A 072 &#58; : 90 5A 132 &#90; Z 122 7A 172 &#122; z 27 1B 033 ESC 59 3B 073 &#59; ; 91 5B 133 &#91; [ 123 7B 173 &#123; { 28 1C 034 FS 60 3C 074 &#60; < 92 5C 134 &#92; \ 124 7C 174 &#124; | 29 1D 035 GS 61 3D 075 &#61; = 93 5D 135 &#93; ] 125 7D 175 &#125; } 30 1E 036 RS 62 3E 076 &#62; > 94 5E 136 &#94; ^ 126 7E 176 &#126; ~ 31 1F 037 US 63 3F 077 &#63; ? 95 5F 137 &#95; _ 127 7F 177 &#127; DEL

ASCII Codes

Page 5: Codes and Code Converters Lecture L6.12 Section 6.5 Section 9.5.

Definitions of ASCIIControl Characters

NUL (null) DLE (data link escape) SOH (start of heading) DC1 (device control 1) STX (start of text) DC2 (device control 2) ETX (end of text) DC3 (device control 3) EOT (end of transmission) DC4 (device control 4) ENQ (enquiry) NAK (neg. acknowledge) ACK (acknowledge) SYN (synchronous idle) BEL (bell) ETB (end of trans. block) BS (backspace) CAN (cancel) TAB (horizontal tab) EM (end of medium) LF (line feed, new line) SUB (substitute) VT (vertical tab) ESC (escape) FF (form feed, new page) FS (file separator) CR (carriage return) GS (group separator) SO (shift out) RS (record separator) SI (shift in) US (unit separator)

Page 6: Codes and Code Converters Lecture L6.12 Section 6.5 Section 9.5.

Table 9.4Keyboard Scan/ASCII Hex Codes

Function KeysUnshifted Shifted Ctrl Alt

F1 3B/00 54/00 5E/00 68/00

F2 3C/00 55/00 5F/00 69/00

F3 3D/00 56/00 60/00 6A/00

F4 3E/00 57/00 61/00 6B/00

F5 3F/00 58/00 62/00 6C/00

F6 40/00 59/00 63/00 6D/00

F7 41/00 5A/00 64/00 6E/00

F8 42/00 5B/00 65/00 6F/00

F9 43/00 5C/00 66/00 70/00

F10 44/00 5D/00 67/00 71/00

Page 7: Codes and Code Converters Lecture L6.12 Section 6.5 Section 9.5.

Table 9.4Keyboard Scan/ASCII Hex Codes

NumericKeypad

Unshifted Shifted Ctrl Alt

Ins 0 52/00 52/30

End 1 4F/00 4F/31 75/00 00/01

2 50/00 50/32 00/02PgDn 3 51/00 51/33 76/00 00/03

4 4B/00 4B/34 73/00 00/045 4C/35 00/05

6 4D/00 4D/36 74/00 00/06Home 7 47/00 47/37 77/00 00/07

8 48/00 48/38 00/08PgUp 9 49/00 49/39 84/00 00/09

- 4A/2D 4A/2D

+ 4E/2B 4E/2B

Del . 53/00 53/2E

Page 8: Codes and Code Converters Lecture L6.12 Section 6.5 Section 9.5.

Table 9.4 (cont.)Keyboard Scan/ASCII Hex Codes

Key Unshifted Shifted Ctrl Alt

A 1E/61 1E/41 1E/01 1E/00

B 30/62 30/42 30/02 30/00

C 2E/63 2E/43 2E/03 2E/00

D 20/64 20/44 20/04 20/00

E 12/65 12/45 12/05 12/00

F 21/66 21/46 21/06 21/00

G 22/67 22/47 22/07 22/00

H 23/68 23/48 23/08 23/00

I 17/69 17/49 17/09 17/00

J 24/6A 24/4A 24/0A 24/00

K 25/6B 25/4B 25/0B 25/00

L 26/6C 26/4C 26/0C 26/00

Page 9: Codes and Code Converters Lecture L6.12 Section 6.5 Section 9.5.

M 32/6D 32/4D 32/0D 32/00N 31/6E 31/4E 31/0E 31/00

O 18/6F 18/4F 18/0F 18/00

P 19/70 19/50 19/10 19/00

Q 10/71 10/51 10/11 10/00

R 13/72 13/52 13/12 13/00

S 1F/73 1F/53 1F/13 1F/00

T 14/74 14/54 14/14 14/00

U 16/75 16/55 16/15 16/00

V 2F/76 2F/56 2F/16 2F/00

W 11/77 11/57 11/17 11/00

X 2D/78 2D/58 2D/18 2D/00

Y 15/79 15/59 15/19 15/00

Z 2C/7A 2C/5A 2C/1A 2C/00

Page 10: Codes and Code Converters Lecture L6.12 Section 6.5 Section 9.5.

Space 39/20 39/20 39/20 39/20 ESC 01/1B 01/1B 01/1B

1 ! 02/31 02/21 78/00

2 @ 03/32 03/40 03/00 79/00

3 # 04/33 04/23 7A/00

4 $ 05/34 05/24 7B/00

5 % 06/35 06/25 7C/00

6 ^ 07/36 07/5E 07/1E 7D/00

7 & 08/37 08/26 7E/00

8 * 09/38 09/2A 7F/00

9 ( 0A/39 0A/38 80/00

0 ) 0B/30 0B/29 81/00

- _ 0C/2D 0C/5F 0C/1F 82/00

= + 0D/3D 0D/2B 83/00

Page 11: Codes and Code Converters Lecture L6.12 Section 6.5 Section 9.5.

[ { 1A/5B 1A/7B 1A/1B] } 1B/5D 1B/7D 1B/1D

backspace

0E/08 0E/08 0E/7F

; : 27/3B 27/3A

' " 28/27 28/22

` ~ 29/60 29/7E

, < 33/2C 33/3C

. > 34/2E 34/3E

/ ? 35/2F 35/3F

Enter 1C/0D 1C/0D 1C/0A

Tab 0F/09 0F/00

\ | 2B/5C 2B/7C 2B/1C

Page 12: Codes and Code Converters Lecture L6.12 Section 6.5 Section 9.5.

Codes and Code Converters

• ASCII

• Binary-to-BCD Converters

• Gray Code

• Bar Codes

Page 13: Codes and Code Converters Lecture L6.12 Section 6.5 Section 9.5.

Binary-to-BCD Converter

Binary Binary Coded Decimal (BCD)HEX C3 C2 C1 C0 E D C B A BCDO 0 0 0 0 0 0 0 0 0 001 0 0 0 1 0 0 0 0 1 012 0 0 1 0 0 0 0 1 0 023 0 0 1 1 0 0 0 1 1 034 0 1 0 0 0 0 1 0 0 045 0 1 0 1 0 0 1 0 1 056 0 1 1 0 0 0 1 1 0 067 0 1 1 1 0 0 1 1 1 078 1 0 0 0 0 1 0 0 0 089 1 0 0 1 0 1 0 0 1 09A 1 0 1 0 1 0 0 0 0 10B 1 0 1 1 1 0 0 0 1 11C 1 1 0 0 1 0 0 1 0 12D 1 1 0 1 1 0 0 1 1 13E 1 1 1 0 1 0 1 0 0 14F 1 1 1 1 1 0 1 0 1 15

Page 14: Codes and Code Converters Lecture L6.12 Section 6.5 Section 9.5.

MODULE bin2bcdTITLE 'Binary to binary coded decimal' DECLARATIONS " INPUT PINS "I3..I0 PIN 11,7,6,5; " Switches S6 - 1..4I = [I3..I0]; " 4-bit input vector " OUTPUT PINS "[E,D,C,B,A] PIN 5,4,3,2,1 ISTYPE 'com'; " LEDs 12..16BCD = [E,D,C,B,A];

bin2bcd.abl

E D C B A

I = 1110

1 4

Page 15: Codes and Code Converters Lecture L6.12 Section 6.5 Section 9.5.

bin2bcd.abl (cont’d)

Binary Binary Coded Decimal (BCD)HEX C3 C2 C1 C0 E D C B A BCDO 0 0 0 0 0 0 0 0 0 001 0 0 0 1 0 0 0 0 1 012 0 0 1 0 0 0 0 1 0 023 0 0 1 1 0 0 0 1 1 034 0 1 0 0 0 0 1 0 0 045 0 1 0 1 0 0 1 0 1 056 0 1 1 0 0 0 1 1 0 067 0 1 1 1 0 0 1 1 1 078 1 0 0 0 0 1 0 0 0 089 1 0 0 1 0 1 0 0 1 09A 1 0 1 0 1 0 0 0 0 10B 1 0 1 1 1 0 0 0 1 11C 1 1 0 0 1 0 0 1 0 12D 1 1 0 1 1 0 0 1 1 13E 1 1 1 0 1 0 1 0 0 14F 1 1 1 1 1 0 1 0 1 15

EQUATIONS @radix 16; " Identify the Hex Basetruth_table ( I -> BCD ) " Binary to BCD Code Converter

0 -> 00;1 -> 01;2 -> 02;3 -> 03;4 -> 04;5 -> 05;6 -> 06;7 -> 07;8 -> 08;9 -> 09;0A -> 10;0B -> 11;0C -> 12;0D -> 13;0E -> 14;0F -> 15;

END bin2bcd

Page 16: Codes and Code Converters Lecture L6.12 Section 6.5 Section 9.5.

Shift and Add-3 Algorithm 1.      Shift the binary number left one bit.2.      If 8 shifts have taken place, the BCD number is in the

Hundreds, Tens, and Units column.3.      If the binary value in any of the BCD columns is 5 or greater,

add 3 to that value in that BCD column.4.      Go to 1. 

Operation Hundreds Tens Units Binary HEX F F Start 1 1 1 1 1 1 1 1

Page 17: Codes and Code Converters Lecture L6.12 Section 6.5 Section 9.5.

Operation Hundreds Tens Units Binary HEX F F Start 1 1 1 1 1 1 1 1

Shift 1 1 1 1 1 1 1 1 1 Shift 2 1 1 1 1 1 1 1 1 Shift 3 1 1 1 1 1 1 1 1 Add 3 1 0 1 0 1 1 1 1 1 Shift 4 1 0 1 0 1 1 1 1 1 Add 3 1 1 0 0 0 1 1 1 1 Shift 5 1 1 0 0 0 1 1 1 1 Shift 6 1 1 0 0 0 1 1 1 1 Add 3 1 0 0 1 0 0 1 1 1 1 Shift 7 1 0 0 1 0 0 1 1 1 1 Add 3 1 0 0 1 0 1 0 1 0 1 Shift 8 1 0 0 1 0 1 0 1 0 1 BCD 2 5 5

Steps to convert an 8-bit binary number to BCD

Page 18: Codes and Code Converters Lecture L6.12 Section 6.5 Section 9.5.

Example of converting hex E to BCD

Operation Tens Units Binary HEX E Start 1 1 1 0

Shift 1 1 1 1 0 Shift 2 1 1 1 0 Shift 3 1 1 1 0 Shift 4 1 1 1 0

6 0 1 1 0 Add 6 1 0 1 0 0 BCD 1 4

Page 19: Codes and Code Converters Lecture L6.12 Section 6.5 Section 9.5.

Truth table for Add-3 Module

A3 A2 A1 A0 S3 S2 S1 S0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 1 0 0 0 1 0 0 0 1 1 0 0 1 1 0 1 0 0 0 1 0 0 0 1 0 1 1 0 0 0 0 1 1 0 1 0 0 1 0 1 1 1 1 0 1 0 1 0 0 0 1 0 1 1 1 0 0 1 1 1 0 0 1 0 1 0 X X X X 1 0 1 1 X X X X 1 1 0 0 X X X X 1 1 0 1 X X X X 1 1 1 0 X X X X 1 1 1 1 X X X X

C

A3 A2 A1 A0

S3 S2 S1 S0

Page 20: Codes and Code Converters Lecture L6.12 Section 6.5 Section 9.5.

C1

C2

C3

C4C6

C5C7

B7

0

0 B6 B5 B4 B3 B2 B1 B0

P7 P6 P5 P4 P3 P2 P1 P0P9 P8

8-bit binary input

BCD output

hunds tens units

Binary-to-BCDConverter

Page 21: Codes and Code Converters Lecture L6.12 Section 6.5 Section 9.5.

C1

C2

C3

C4C6

C5C7

B7

0

0 B6 B5 B4 B3 B2 B1 B0

P7 P6 P5 P4 P3 P2 P1 P0P9 P8

8-bit binary input

BCD output

hunds tens units

1 1 1 1 1 1 1 1

1 0 1 0

1 0 0 0

1 1 0 0 0 1

1 0 0 1 0 0 1 1

1 0 0 1 0 1 0 1 0 1

1 1

2 5 5

Hex FF

Binary-to-BCDConverter

Page 22: Codes and Code Converters Lecture L6.12 Section 6.5 Section 9.5.

Other Binary Coded Decimal Representations

Decimal Digit Excess-3 2421 BCD 2-out-of-5 0 0011 0000 11000 1 0100 0001 00011 2 0101 0010 00101 3 0110 0011 00110 4 0111 0100 01001 5 1000 1011 01010 6 1001 1100 01100 7 1010 1101 10001 8 1011 1110 10010 9 1100 1111 10100

Page 23: Codes and Code Converters Lecture L6.12 Section 6.5 Section 9.5.

Codes and Code Converters

• ASCII

• Binary-to-BCD Converters

• Gray Code

• Bar Codes

Page 24: Codes and Code Converters Lecture L6.12 Section 6.5 Section 9.5.

Gray Code0 0000 1 0001 2 0011 3 0010 4 0110 5 0111 6 0101 7 0100 8 1100 9 1101

10 1111 11 1110 12 1010 13 1011 14 1001 15 1000

Note that the least significant bit that can be changed without repeating a value is the bit that is changed

Page 25: Codes and Code Converters Lecture L6.12 Section 6.5 Section 9.5.

Gray codes eliminate errors

000001

010

011

100101

110

111

0 1

2

3

45

6

7

000001

011

010

110111

101

100

0 1

2

3

45

6

7

Binary Code Gray Code

Reading Region Binary Counter Gray Code Region 3: B3B3B3 011 R3 010 R3 Transition: B3B3B4 010 R2 010 R3 Transition: B3B4B4 000 R0 010 R3 Region 4: B4B4B4 100 R4 110 R4

Page 26: Codes and Code Converters Lecture L6.12 Section 6.5 Section 9.5.

Gray Code Conversion

000 0001 1011 2010 3110 4111 5101 6100 7

Gray Code Decimal equivalent G_in = [G2..0];G_out = [B2..0];

Truth_table (G_in => G_Out)

Fill in this TRUTH_TABLECommand so as to convert the Gray code input, [G2..0], to the binary output, [B2..0]

Page 27: Codes and Code Converters Lecture L6.12 Section 6.5 Section 9.5.

Gray Code Conversion

000 0001 1011 2010 3110 4111 5101 6100 7

Gray Code Decimal equivalent G_in = [G2..0];G_out = [B2..0];

Truth_table (G_in => G_Out) 0 -> 0; 1 -> 1; 3 -> 2; 2 -> 3; 6 -> 4; 7 -> 5; 5 -> 6; 4 -> 7;

Fill in this TRUTH_TABLECommand so as to convert the Gray code input, [G2..0], to the binary output, [B2..0]

Page 28: Codes and Code Converters Lecture L6.12 Section 6.5 Section 9.5.

Codes and Code Converters

• ASCII

• Binary-to-BCD Converters

• Gray Code

• Bar Codes

Page 29: Codes and Code Converters Lecture L6.12 Section 6.5 Section 9.5.

Code 39 Bar Code

A B C D

3-of-9 bars are WIDE bars(Bars can be black or white)