A microcontroller is a binary device, and therefore it works with two values at the base level 1 and 0. The "meaning" of the binary value changes depending on where and how its used.
Although there are other number types such as integer
1 and 0 form the base 2 numbering system and the highest value which can be held by a single, 8 BIT register is 255 or 11111111. When used in code,
ie in the compiler, that number can be represented in a number of ways: example OxFF or 'b11111111. Although, the developer may want to represent a number in any of the following ways,
it ultimately comes back to the same when the value is compiled however, it functions in 1's and 0's.
If a number of larger value is required, then two or more registers can be joined together.
In an electronic context 1 is HIGH and 0 LOW. This can be inverted depending on the application. When configuring a register, a 1 sets the register high and 0 clears the register setting it low.
Even though technically 1 is high and 0 is low, ensure that you read the datasheet thuroughly to ensure what the affect of changing the value.
When configuing the PIC Ports, there are three registers that need to be configured. The direction is controlled by the TRIS registers, 1 = input and 0 is Otuput. However, when setting a pin high, it gets set to 1 and 0 clears the pin.
TRISB = 0x00; // All outputs configured for output
PORTB = 0xff; // All outputs set high
When using numbers in code, they must be written in a way that the compiler understands and can use.
Some examples are shown below.
|Numbers and Representation
|1 or 0
||'Binary representation of a 1 or zero given a high or low value for positive logic, whereas in negative logic their meaning is inverted.
||An 8 bt register can be represented as shown left. Each position however has a set value and designation. This designation is used to correspond to specific attributes of a register
||This is the maximum value of an 8 Bit register. This is a decimal representatio of the binary equivalent.
||This is the maximum value of an 8 Bit register. This is a HEX representatio of the binary equivalent.
In the next section, we will look at different number types and how they are used in code.