All the questions you have are mostly due to the fact that you DID NOT READ THE DATASHEET for this microcontroller.
Now I can understand if you don't read it completely, because it's huge, over 300 pages, but you can jump at the chapters you want to learn more about.
GOING BACK TO THE DATASHEET I LINKED ABOVE ... OPEN IT AND BE READY TO BROWSE IT.
Problem
1.-In the tutorial they say to “the oscillator set to internal but there are two type of interna, which one you need to choose
from page 37 onwards it explains everything about external and internal oscillators. on page 43 you have internal oscillators explained. Basically there are two, one high frequency but which uses more power and one very low frequency (which can be used for example when you want your pic to use super low power sleeping).
You also have several options that allow you to expose the oscillator on the pins usually used for external oscillator (in case you want some other chip to sinchronize to your pic frequency for example) or disable that so that you can use those pins for input/output
2.-I am doing a tutorial and it says “Make portD an output – ready to drive the LEDs. Write a test pattern to portD. Make portB,0 an input, ready for the switch. That is all the code needed for initialisation in this system. “
-How to make the PortD and output?,
-how to initialise a code, for example you write PORTD equ Output? (like c programmimg)
page 117 and onwards : i/o ports
Basically you have two registers, TRIS and PORT , for each set of eight pins that can be each either input or output. Eight input/output pins are grouped into a port and you can set the individual mode of a pin in that port, by setting a particular bit in the TRIS register for that port to 1 or 0. The PORT register tells you what state that pin is.
Depending on how you connect the leds, you need to either set the pins the leds are connected to as OUTPUT (to send power to the led) or as INPUT (so that power comes into the led and the microcontroller completes the circuit). Your circuit is probably the first case.. you set the pins as output and when you say 1 on the pin, the microcontroller sends power through the pin lighting up the led.
So if you have four leds, you set four pins of you microcontroller to output but as the pins are grouped into a port of 8 pins, you need to set all those 8 pins... so you have TRISD (tris for port D) = 11110000b; <-- pins 0,1,2,3 are output, pins 4,5,6 and 7 are input... 0 is the one at the end.
Now with the PORTD you can actually set the pins on or off, but again you have to work with the set of 8 pins no matter if you have 4 leds or not ... the other 4 pins are just there with nothing connected to them.
3. in the tutorial it says a text about how does it work but did not understood it.
"In state1, we output all zeros to portD to turn all the LEDs off.”
-how they turn off all the LED?
“ In state2 we output the pattern ‘AA’ to the LEDs.”
-The AAh =10101010b, so it turn on 4 LED and turn off 4 LED? There are 8 LED?
So when PORTD = 0, it means all pins in port D are set to off, no power sent to them.
AAh is the hex value, AA in hexadecimal =10101010b ... this tells me that at least pins 1,3,5,7 were set initially to ouput mode with TRISD (TRISD = 01010101b - pins 0,2,4,6 are left as input, pins 1,3,5,7 are output).
Now PORTD = AAh, so those 4 pins are turned on, and the others are left as OFF ( if those pins were set to input with TRISD, the microcontroller ignores the 0 for those bits as it doesn't make sense)
“ After driving the LEDs with the appropriate value, there is code to check for the switch being pressed and then released (active low, Table 3.1).”
-where is the code?
i don't know, i don't have the code in front of me . I would guess since you mention it later, it's those btfsc and btfss instructions which test if a bit on the port is set (which happens when the pin is set to input and the pin receives voltage because the button is pressed) and either skip an instruction that follows them or execute it, so they're like an if then else code.
“The instruction bra $-2 effectively hold the processor at the test until it is TRUE.”
-When it is low, it skip the bra $-2? The role of the bra $-2 is to keep the counter 2 place backward?
page 347 and onwards .. instruction set
page 350 PIC18F87J11 FAMILY INSTRUCTION SET
page 359 BRA ... Branch unconditionally, with the parameter being the new value of the program counter.
$ is the current position in the program... if you say $-2, it means it jumps two instructions back
Not exactly sure how the code is in the tutorial, but I assume it's a sort of loop and the BRA command simply moves the microcontroller to the start of the loop
“When the software exits state1 it ‘drops into’ state 2 – but when exiting state2 a specific instruction is required to get back to state1."
-Confuse about this sentence
I don't know what you're trying to say.
-Is btfsc PORTB,0 and btfss PORTB,0 is a if function?
btfsc and btfss are instructions of the microcontroller
BTFSC Bit Test File, Skip if Clear
BTFSS Bit Test File, Skip if Set
Think of them as " if bit is set then do the next instruction otherwise jump it", or something like that. Useful to get out of an infinite loop, an exit condition.
Again, read the datasheet , page 350 and onwards, each instruction is explained.