[Menu]>[Guide to use the PIC]


Instructions of PIC16 series



Radix
In the software of the computer, hexadecimal is often used.
    Decimal
    In our daily life, 10 numbers from "0" to "9" are used.
    In case of the count-up, after 9, the carry is done and becomes 10. We are using properly but this is the count method of the number which the human being decided.
    This seems to depend on that the fingers of the hand of the person is 10.


    Binary
    Only two values of "0" and "1" are used to express a condition by the digital world which included a computer. These are sometimes expressed by "Low level " and "High level ", too.
    Like 0 1 10, after 1, it is 10.


    Hexadecimal
    In the condition to be handling with the computer, it is a binary number but it is difficult to understand for the person who is using the decimal.
    163(Decimal) 10100011(Binary)
    Therefore, a hexadecimal is used as the expression which it is easy for the person to understand. As for the hexadecimal, 16 numbers are used for 1 digit. It is from 0 to 9 that it is expressed by the figure. So, six of the remainder are expressed by the alphabet.
    10 A, 11 B, 12 C, 13 D, 14 E, 15 F
    The figure has begun with 0. Therefore, 10 of the figure shows the 11th and 15 shows the 16th.
    16 kinds of conditions are expressed by 4 bits in the binary. Oppositely, the hexadecimal is used because that it is possible to express 16 by 4 bits. There is the octal which is expressed by 3 bits. In case of the hexadecimal, 1 byte is expressed by 2 digits.
    Also, it puts "h" to distinguish the hexadecimal from the decimal. h is the initial of hexadecimal(16).
    It shows in 00h or H'00' or 0x00. However, an expression isn't unified.


    The correspondence of radix
    The correspondence of Binary, Decimal and Hexadecimal is as follows.
DecimalBinaryHexdecimal
DecimalBinaryHexdecimal
000h100110010064h
111h12711111117Fh
2102h1281000000080h
3113h20011001000C8h
41004h25511111111FFh
51015h256100000000100h
61106h30010010110012Ch
71117h400110010000190h
810008h5001111101001F4h
910019h5111111111111FFh
101010Ah5121000000000200h
111011Bh6001001011000258h
121100Ch70010101111002BCh
131101Dh8001100100000320h
141110Eh9001110000100384h
151111Fh100011111010003E8h
161000010h102311111111113FFh
171000111h102410000000000400h
181001012h2000111110100007D0h
191001113h2047111111111117FFh
201010014h2048100000000000800h

    The change of Binary, Decimal and Hexadecimal can make simple if you use the function electronic calculator which is attached to the Windows.
    When changing without using the calculator, it is possible to do in the following way.
    It is possible to change simply if dividing 4 bits.
    It is easier if learning a binary pattern to Fh from Ah.
    EX. 111000100100010000100 1C4884h
    It is possible to change 1 digit of the hexadecimal into the binary in the order.
    EX. 5F37Bh 1011111001101111011
    This is troublesome a little.
    First, you write a decimal value every bit like the following figure. Total the decimal value of the bit of "1".
    EX.

    512 + 256 + 128 + 8 + 4 + 1 = 909
    This is terrible a little, too.
    Subtract the maximum number of power of two(1,2,4,8,16,32,64,128,256,512,1024,...) which can be subtracted from the decimal number.
    It makes the bit which corresponds to the number of power of two which could be subtracted to "1".
    Subtract the number of power of two which could be subtracted from the remainder more.
    Hereinafter, repeat similar subtraction until the remainder passes away.
    The row of "1" and "0" by above result is a binary number.
    EX. "582"
      582 - 512 = 70
      70 - 64 = 6
      6 - 4 = 2
      2 - 2 = 0
    Change a decimal into the binary first and change a result into the hexadecimal more.
    In case of the example(D B) which was shown above, 582 = 1001000110 = 246h.

    When changing directly, there is a way of dividing by the value of 4 bits.
    582 / 256 = 2 remainder 70
    70 / 16 = 4 remainder 6
    The result is 246h.
    Change a hexadecimal into the binary first and change a result into the decimal more.
    In case of the example(B D) which was shown above, 38Dh = 1110001101 = 909

    When changing directly, there is a way of multiplying the value of 4 bits.
    3 x 256 = 768
    8 x 16 = 128
    The result is 768 + 128 + 13(Dh) = 909.

    Still, it is easy to calculate using the function electronic calculator.


    2's Complement
    The 2's complement is the one which shows negative numerical value.
    For example, "-1" of the decimal number is 11111111 when showing by the binary with byte.
    It is as follows when confirming.
    The overflow occurs but the numerical value becomes zero.
    A binary addition is done from the lower rank figure like the decimal number. When there is a carry, it calculates a higher rank figure including it.

    To use a negative value, there is a condition.
    The numerical value which it is possible to show at the byte is 256 kinds of 0 to 255. However, when using the negative value, it becomes 255 kinds of - 127 to +127. The reason why the numbers are few is because 10000000 isn't used. The row of these bits shows -0 but in the calculation, it can not use. Most significant bit 7 is used as the sign bit which shows negative or positive. The type with numerical value must be considered when processing it.
    For example, it is 10000001 when showing -127 in the binary number. It becomes 129, supposing that this is only plus numerical value.

    A change into the 2's complement is done as follows.

    I attempt to change 56 into -56 as the example.
    (1) Subtract 1 from the value56 - 1 = 55
    (2) Change this into the binary55 00110111
    (3) It makes 0 and 1 opposite00110111 11001000

    11001000 is the binary number which shows -56.

    It is as follows when confirming.

    The answer became zero.


General format for instructions
The format for instructions of PIC16 series is the following three kinds. The instructions are written in the program memory and one instruction is composed of 14 bits. These 14 bits are called a word.

Byte-oriented file register operations

The instructions of this format are the instructions which processes a byte unit.


OPECODE :The code to distinguish a instruction is written.
d (Destination select) : It specifies the register which stores the execution result of the instruction.
d=0 : It specifies working register ( W reg ).
d=1 : It specifies file register which is specified by f.
In case of the assembler language, d is written in W or F.

(EX)ADDWFCOUNT,W( d=0 when writing W )

ADDWFCOUNT,F( d=1 when writing F )
f (Register file) : It specifies the address of the register which is dealt with for the instruction.
f can specify an address from 0(00h) to 127(7Fh) because it is 7 bits.
In case of PIC16F84A, because the register memory is 80 bytes including SFR, it is possible to be specified by f if being 7 bits.
When writing by the assembler language, the label is put to the register and uses.

(EX)ADDWFCOUNT,F( COUNT is the label of the register)


Bit-oriented file register operations

The instructions of this format are the instruction which processes a bit unit.

OPECODE :The code to distinguish a instruction is written.
b (Bit address) : It specifies the bit position of the register file.
Because the register file is a byte, it can specify all bit positions with 3-bit b.
f (Register file) : It specifies the address of the register which is dealt with for the instruction.
f can specify an address from 0(00h) to 127(7Fh) because it is 7 bits.
In case of PIC16F84A, because the register memory is 80 bytes including SFR, it is possible to be specified by f if being 7 bits.
When writing by the assembler language, the label is put to the register and uses.










Literal and control operations



The instructions of this format do the processing which used the fixed number (k) which was written in the instruction.
There are two instruction types and fixed number (k) is 11 bits about GOTO and CALL instruction.




In case of GOTO and CALL instruction
OPECODE :The code to distinguish a instruction is written.
k (Literal field) : This is the fixed number to use for the calculation.
It specifies by the numerical value or the label.
Because it is a byte except JUMP and CALL instruction, it is the range of 0(00h) to 255(FFh).
Because GOTO or CALL instruction is 11 bits, it is the range of 0(00h) to 2047(7FFh).