tklab - courses
[This page is CSS2 enabled. Your browser might not fully support it]
[http://www.ee.oulu.fi/research/tklab/courses/521419A/exercises/2004/]
Spring 2004 - Exercise 1: Convert Characters into Morse Code
This assignment is aimed to lower the learning curve of C language. You may
want to take a look at the work-in-progress introductory document about C before continuing
with this assignment.
Your task is to implement a program that reads user's input from the keyboard
and outputs morse code in dot-dash notation to the screen. The program must
convert input values first into PC/XT scancodes and use those to choose
which morse code to output. The needed conversion tables are provided below.
Key ASCII Scancode (PC/XT)
================================================
a 0x61 0x1E
b 0x62 0x30
c 0x63 0x2E
d 0x64 0x20
e 0x65 0x12
f 0x66 0x21
g 0x67 0x22
h 0x68 0x23
i 0x69 0x17
j 0x6A 0x24
k 0x6B 0x25
l 0x6C 0x26
m 0x6D 0x32
n 0x6E 0x31
o 0x6F 0x18
p 0x70 0x19
q 0x71 0x10
r 0x72 0x13
s 0x73 0x1F
t 0x74 0x14
u 0x75 0x16
v 0x76 0x2F
w 0x77 0x11
x 0x78 0x2D
y 0x79 0x15
z 0x7A 0x2C
0 0x30 0x0B
1 0x31 0x02
2 0x32 0x03
3 0x33 0x04
4 0x34 0x05
5 0x35 0x06
6 0x36 0x07
7 0x37 0x08
8 0x38 0x09
9 0x39 0x0A
Scancode Morse Code
============================
0x1E .-
0x30 -...
0x2E -.-.
0x20 -..
0x12 .
0x21 ..-.
0x22 --.
0x23 ....
0x17 ..
0x24 .---
0x25 -.-
0x26 .-..
0x32 --
0x31 -.
0x18 ---
0x19 .--.
0x10 --.-
0x13 .-.
0x1F ...
0x14 -
0x16 ..-
0x2F ...-
0x11 .--
0x2D -..-
0x15 -.--
0x2C --..
0x0B -----
0x02 .----
0x03 ..---
0x04 ...--
0x05 ....-
0x06 .....
0x07 -....
0x08 --...
0x09 ---..
0x0A ----.
You may use the getch() function from conio.h to read user input. Use code comments to
explain what you have done and especially why you did it your way.
NOTE: the two-phase conversion from input to scancodes to morse output is mandatory.
- HINT 1: you could use arrays to index the morse code strings and scancodes..
- HINT 2: input characters align nicely in the ASCII index
- HINT 3: to ease debugging and to reduce the assistants' workload, you might want
to output the values produced by each conversion and the input character.
As said before, the assignment must be written in ANSI C and must compile either
with Borland C version 3 (available in computer class TS134) or Borland Turbo C
2.01.
The exercise MUST be returned by sending a plain-text email to
t k t 2 - i n b o x @ e e . o u l u . f i
You may attach one text file (the properly commented C source code).
Word attachments etc. will be rejected. Remember to include your full
name, date of birth and the year you started your studies.
Deadline for returning this exercise is on wednesday 10.3.2004 at 16:00.
Solution 1
This first solution uses linear translation tables within RAM and uses less CPU per translation.
Solution 2
The second solution shows how CPU power can overcome the problem of small amount of RAM.
[http://www.ee.oulu.fi/research/tklab/courses/521419A/exercises/2004/]
[This page is CSS2 enabled. Your browser might not fully support it]
|