Programming Techniques:Numerical Types

Numerical Types

Literal values given in PIC source code can be written using different number systems. The default is hexadecimal, that is, if the type is not specified, the assembler will assume it is hex. However, it is very important to note that the assembler will still get confused between numbers and labels if the hex number starts with a letter (i.e. A, B, C, D, E or F). The literal must start with a number, so use a leading zero at all times. Therefore, 8-bit literals should be written as three hex digits, including the leading zero (000e0FF).

The numerical types supported by the MPASM assembler are:

• Hexadecimal

• Decimal

• Binary

• Octal

• ASCII.

If necessary, refer to Appendix A for more details on hex and binary number systems. Octal is a base 8 number system, which has limited use as far as we are concerned here. ASCII is described below. To specify a type, the initial letter of the type can be used with quotes, such as:

PIC Microcontrollers-1217

The numerical type prefix is not case sensitive. Hex has an alternative form that is used in C programming (e.g. 0xFA). Binary is useful for specifying register values that are bit oriented, especially when setting up control registers; the state of each bit is then explicit.

ASCII code represents text characters. The codes are listed in Table 6.2; the high bits and low bits for each character code must be combined together to form a 7-bit code. Notice that most of the characters on a standard keyboard are available, including upper and lower case, numbers, punctuation and other symbols.

PIC Microcontrollers-1218

If an ASCII character is specified in the program source code, the corresponding code in the range 00e7F will be generated. This option is used in sending data to alphanumeric displays or serial ports, for example:

PIC Microcontrollers-1219

Note that the A for ASCII can be left out in the operand, and the character will still be correctly recognized by the assembler.

Leave a comment

Your email address will not be published. Required fields are marked *