Radix pre-specifies to the assembler whether your literal values are in decimal (dec), hexadecimal (hex), or binary (bin). When in decimal radix, you can simply type the number without having to specify the radix (i.e. d'05', which would be decimal 5...you can just simply type "5" and the assembler will know that you mean decimal 5 or any other number you wish up to 255).
2. How do i know my processor frequency? is it 4 MHZ or what not?
When using the internal oscillator, bit 3 in the PCON register sets the internal oscillator frequency. Setting bit 3 in the PCON register sets it up for a nominal 4MHz while clearing bit 3 sets it up for a nominal 37kHz.
For 4MHZ -
Code:
banksel PCON ;switch to bank 1
bsf PCON,3 ;set internal oscillator for 4MHz
For 37kHz -
Code:
banksel PCON ;switch to bank 1
bcf PCON,3 ;set internal oscillator for 37kHz
You would place this code prior to your port configuration routine (i.e. where you set TRIS A and B for I/O).
Now this only applies when using the PIC's internal oscillator. When using a crystal, the crystal frequency dictates the oscillator frequency.
3. I read where you calculate your delay from your processor frequency, how do i do that?
You have to know how many clock cycles per instruction each instruction is as well as the instruction cycle clock. The instruction cycle clock is divide by 4...meaning that you take the oscillator frequency and divide it by 4 to get the instruction clock frequency. For a 4MHz clock this would mean that the instruction clock runs at 1MHz. At 1MHz, the PIC executes 1 instruction per microsecond.
All instructions are single cycle instructions except for instructions which modify the program counter, which take 2 cycles to complete. Call, goto, and computed goto instructions all modify the program counter. This means every time you decrement your counter registers in your delay loop, then go back to decrement it again until the register = 0, this takes 3 instructions every time you decrement the counter registers. At 1 instruction per microsecond, this takes 3 microseconds to complete.
If you're starting the decrement at the maximum value (i.e. 255), you would multiply 255 by 0.000003, or 3 microseconds to figure out how long it takes to decrement the register from 255 to 0, which would be 765 microseconds. If you make it decrement a second register every time it fully decrements the first one, you would multiply your .000765 seconds by another 255 to figure out how long it takes to complete the entire loop. This would give us a delay of 195 milliseconds, or 0.195 seconds. This is called a "nested delay loop".
If you nest in yet a 3rd register, but start it at a lower number, you can get delays in the seconds range. Here's an example code that will get you close to a 1 second delay -
Code:
Delay_1s
movlw 255 ;Pre-load delay counters with starting decriment value. Value 255 is the highest value you can
movwf Delay1 ;use on 8 bit processors. Decimal 255 can be noted as 0xFF or b'11111111'. For long delays, use
movwf Delay2 ;a nested delay loop as illustrated here.
movlw 0x05
movwf Delay3
Wait
decfsz Delay, F
goto Wait
decfsz Delay2,F
goto Wait
decfsz Delay3,F
return
At the top of your code you will need this to label the general purpose RAM locations -
Code:
Delay1 EQU 0x20
Delay2 EQU 0x21
Delay3 EQU 0x22
You can also use -
Code:
cblock 0x20
Delay1
Delay2
Delay3
endc
This allows you to label multiple registers in one shot.
Now...3 loops with those values assuming a 4MHz main clock, which would give us a 1MHz instruction clock -
.000003 x 255 = .000765 Seconds - Delay 1
.000765 x 255 = .195075 Seconds - Delay 2
.195075 x 5 = .975375 Seconds - Delay 3
Which would give us close to a 1 second delay.
4. I meant how to include my header file in the little box, it shows source file, header file, object file, library file and a few others. is the header file for p16f648a in my C drive?
Can you take a screen shot of what you're seeing here and post it? Pull up the screen on your PC, press "Print Screen", then open up Microsoft Paint and paste it in there. Finally, save the pic as a JPEG, then post it up.