Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

tutorial 1.2

Status
Not open for further replies.

4electros

New Member
Mr.nigel in your tutorial(tut 1.2) you wrote:
__config 0x3D18 ;sets the configuration settings (oscillator type etc.)


How can we know that the oscillator type is 0x3D18 ,i can't understand that!

At the other part of this code:
Delay movlw d'250' ;delay 250 ms (4 MHz clock)
movwf count1
d1 movlw 0xC7
movwf counta
movlw 0x01
movwf countb
Delay_0
decfsz counta, f
goto $+2
decfsz countb, f
goto Delay_0

decfsz count1 ,f
goto d1
retlw 0x00



I can't understand about the timing, i know that each instruction takes only 1us and you say that this delay loop makes a delay of 250ms ,so i can't understand ..
concerning to outer loop and inner loop i couldn't understand how it works exactly i was so confused about timing!!

what about the line (goto $+2) is that mean that we passed over to the second line follows the instruction?
Another question, when I finish these tutorials of yours,what should i learn next to be really a good programmer of PIC and use it in useful way?

Anyway thanks in advance!!
 
4electros said:
Mr.nigel in your tutorial(tut 1.2) you wrote:
__config 0x3D18 ;sets the configuration settings (oscillator type etc.)


How can we know that the oscillator type is 0x3D18 ,i can't understand that!

The fuse settings are explained in the datasheet, but i got the actual value I used from WinPicProg, by simply selecting the options I wanted, and reading the value off the screen. The values that WinPicProg produces were (of course) originally obtained from the datasheets.

At the other part of this code:
Delay movlw d'250' ;delay 250 ms (4 MHz clock)
movwf count1
d1 movlw 0xC7
movwf counta
movlw 0x01
movwf countb
Delay_0
decfsz counta, f
goto $+2
decfsz countb, f
goto Delay_0

decfsz count1 ,f
goto d1
retlw 0x00



I can't understand about the timing, i know that each instruction takes only 1us and you say that this delay loop makes a delay of 250ms ,so i can't understand ..
concerning to outer loop and inner loop i couldn't understand how it works exactly i was so confused about timing!!

what about the line (goto $+2) is that mean that we passed over to the second line follows the instruction?
Another question, when I finish these tutorials of yours,what should i learn next to be really a good programmer of PIC and use it in useful way?

'$' is an assembler directive, it means the current 'address', so 'goto $' means jump to itself (an endless loop), 'goto $+1' means jump to the next line (effectively a NOP, but it takes twice as long, so can be useful). So 'goto $+2' jump over the next line, it just saves using a label.

I didn't write the delay routine, it's generated by a page on the PICList, there seems little point bothering when you can input the required delay and get the code back :lol: However, I did write the outer loop, I used the PICList generator to give me a 1mS delay routine, I then added an extra counter round it, allowing me to get delays from 1mS to 255mS by loading 'count1' accordingly - the later tutorials use a number of different fixed entrance delays, and a variable one as well (where you preload W with the number of mS you want).

Basically it's just a number of imbedded loops, but the generator routines are always a little convoluted!.
 
4electros said:
what should i learn next to be really a good programmer of PIC and use it in useful way?

Try to figure out how many cycles the above delay routine really takes. Is it really 250ms, or is it 248.3ms, 254.88ms or whatever. Then you're pretty much half way through. Read and understand other people's code and see if you can improve on them or spot any mistake is also a very quick way to build up your knowledge.

You then apply what you've learned and program PICs to work in real life electronic applications, like LED flasher, TV game, frequency counter, multimeter, multi-function probe.....etc...

Good PIC programming is an art where one can only learn via experience and practice(funny I would say that as I have neither :oops: ). The more you write program codes, the more you know that there are things you don't know. There is no shortcut.
 
Nigel Goodwin said:
I didn't write the delay routine, it's generated by a page on the PICList, there seems little point bothering when you can input the required delay and get the code back :lol: However, I did write the outer loop, I used the PICList generator to give me a 1mS delay routine, I then added an extra counter round it, allowing me to get delays from 1mS to 255mS by loading 'count1' accordingly - the later tutorials use a number of different fixed entrance delays, and a variable one as well (where you preload W with the number of mS you want).

I haven't find that in piclist can you tell me where can i find :oops:
 
One wonder what one would get back if one search for:

"piclist delay routine" in Google.
 
4electros said:
eblc1388 said:
One wonder what one would get back if one search for:

"piclist delay routine" in Google.

I'm going to do it but... what do you mean with this reply i'm just asking not more!!

I think he means why ask questions here, when you can easily find the answer faster yourself?.
 
Nigel Goodwin said:
I think he means why ask questions here, when you can easily find the answer faster yourself?.

Ok,anyway some keywords don't bright to me to search for it,that's why i'm always ask some questions here !
Thanks a lot for your help my friends :D
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top