Representation of Characters in mikroPascal.

1. Introduction.

Characters in mikroPascal code are identified by the fact that they are enclosed in single quotes (like 'A', which is meaning "the character A").
Since everything in the computer world is represented by numbers, there is no exception for characters.

The numbers (or values) representing characters are called Ascii codes. (Do not ask for explanation of this name...).
Ascii codes are numbers ranging from 0 to 255.
The relation between characters and their ascii codes can be found in a so called "Ascii chart" like there one in the compiler's IDE: menu "Tools" -> "Ascii Chart".
Looking into this chart (see also here), one can see that the Ascii code for the character 'A' is 65 (decimal).

This means that e.g. the character 'A' is represented by the value 65, its Ascii code.

2. Character Literals.

Characters can be written down in mP as

3. Interchangability of characters and Ascii codes in statements.

One can usually, in mikroPascal statements, interchange a character (embedded in single quotes) with its Ascii code.

Examples:
The statements
Lcd_Chr(1, 1, 65);
Lcd_Chr(1, 1, 'A');
do exactly the same thing (the LCD routines work with ascii codes).
Notice that the second statement is much more self explaining than the first one.

Also
if Var1 = 65 then ...
if Var1 = 'A' then ...
are exactly the same statements.
As can be seen, mikroPascal always does an implicite (automatic) conversion between characters and their ascii codes.

So, this will also do the trick:
var CharVar: char;
    ByteVar: byte;
    ...
CharVar := ByteVar; implicitely converts an ascii value in "ByteVar" to a character in "CharVar".
ByteVar := CharVar; implicitely converts a character in "CharVar" to its ascii value in "ByteVar".

And this will also work:
CharVar := 65;
ByteVar := 'A';
In both cases the value 65 (representing 'A') is stored in the variable.

4. Explicite conversion between characters and their ascii codes.

There are some functions that can do explicite (= non automatic) conversion between characters and their Ascii codes:
var CharVar: char;
    ByteVar: byte;
    ...
CharVar = Chr (ByteVar); converts an ascii value in "ByteVar" to a character in "CharVar".
ByteVar = Ord (CharVar); converts a character in "CharVar" to its ascii value in "ByteVar".

Since however the implicite conversion always takes place where needed, you will normally not need these functions, unless you want to make clear in your code that a conversion takes place.
There is one exception to this rule however: string concatination with the '+' sign (like in "Str1 := Str2 + Str3;"). This string concatenation function can not handle ascii codes instead of characters, so, "Str1 := Str2 + 13;" is not allowed, the ascii code 13 should be explicitely casted to a character, like in "Str1 := Str2 + chr(13);" or "Str1 := Str2 + #13;"

5. Strings

A string is simply a number of characters added together to make a "word" that can be read by humans (or devices/tools meant to give output to humans). In mikroPascal, also strings are enclosed in single quotes, like characters.
An example of a string is 'This is'. As you can see this example consists of 7 characters. It is stored in pic memory as a sequence of bytes, containing the ascii codes of those 7 characters: 84, 102, 105, 115, 32, 105, 115. (Additionally there is one extra "terminating" character: the ascii code 0, see Strings in mikroPascal.htm , but here we will ignore it here).

Also '123' is a string. It has 3 characters of which the ascii codes are: 49, 50 and 51. It is human readable and can be sent to e.g. an LCD device or RS232 (UART) terminal program.
Curious is that this string represents the human readable form of a number. The number itself is binary coded inside e.g. a byte and is not human readable. So, it is obvious that sometimes non human readable numbers have to be converted into human readable strings.

MikroPascal has a number of library routines for this (mE's "Conversions" library): Also the opposite (converting a string to a number) is possible with following library routines: In some other libraries (e.g. that from Yo2Lio), more conversion routines can be found.

6. Ascii Chart of the "normal" characters.

Space
32
!
33
"
34
#
35
$
36
%
37
&
38
'
39
(
40
)
41
*
42
+
43
,
44
-
45
.
46
/
47
0
48
1
49
2
50
3
51
4
52
5
53
6
54
7
55
8
56
9
57
:
58
;
59
<
60
=
61
>
62
?
63
@
64
A
65
B
66
C
67
D
68
E
69
F
70
G
71
H
72
I
73
J
74
K
75
L
76
M
77
N
78
O
79
P
80
Q
81
R
82
S
83
T
84
U
85
V
86
W
87
X
88
Y
89
Z
90
[
91
\
92
]
93
^
94
_
95
`
96
a
97
b
98
c
99
d
100
e
101
f
102
g
103
h
104
i
105
j
106
k
107
l
108
m
109
n
110
o
111
p
112
q
113
r
114
s
115
t
116
u
117
v
118
w
119
x
120
y
121
z
122
{
123
|
124
}
125
~
126
DEL
127

-------------------------------------------