2. By write TRISB=0b00000000; in the c language its will be output port. Because if 0 it mean we have set that port as output . but if we want to set PORTB as input , the coding is TRISB:0b11111111; .
TRISB =0x0f; //set Port B as input PORTB=0x00; //clear Port B before program start
Or
TRISB=0b00001111; //set Port B as input PORTB=0b00000000; //clear Port B before program start
2. i) this line #include <htc.h> is actually to tell the compiler to include the htc.h file which is provided by HI-TECH C compiler for the device definition. The reason we need device definition is to make sure that the compiler understand when we use the device term like PORTB, RB1, RA0, ADCON0, which we normally sees in the datasheet. This line also allow us to use some of the predefine function provided by HI-TECH C compiler.
ii) The main function is the place where the execution of a C program starts. When the program is executed, the control enters main() function and starts executing its statements. if a program does not contain main function, it can be compiled but cannot be executed.
REFLECTION:
Through this experiment, I have learned how to configure input and output port using C language, write individual bit for input and output and familiar with the HI-TECH ANSI C complier.i also able to modify the coding to do exactly in the question.