Why is meant by statement as TRIS = 0x00 or LATB = 0x00, Why 0x00 while programming for PIC microcontroller in C.
I'm not sure exactly what you think is strange, but I'll cover both my ideas.
Why 0x00, why not 0?
0x00 is the same as
0. It's just written in hexadecimal notation. The reason for doing that is that you often initialize values using a hexadecimal notation, because it's relatively easy to see each individual bit. Good old C did not have the binary
0b00000000 notation. If you write
0x00 instead of
0, some tables may look slightly prettier:
TRISA = 0x00; TRISB = 0xC0; TRISC = 0x01;
Why initialize at all?
These hardware registers are initialized to a specific state, as described in the manual. Some are left in an unchanged state, or undefined after a reset.
Naturally, if you want them to have another value, you need to write that.
Even if they were already initialized to zero, you may want to be explicit about it:
- It helps documenting your code. You don't have to look up the defaults, it's right there in your code. Someone who is not as familiar with the particular processor does not have to assume anything.
- Some registers are initialized in a different way depending on the type of reset. This may be unwanted.
- You may want to perform a "soft restart", jumping to the start of your program without going through a hardware reset. The registers may be left in an unknown state.