-I ask for help in making a 5-minute delay in PIC.. someone on this site (Gayan) had posted it.. I don't really understand most of the codes and on how it runs..
If you put the code into MPLAB and use the simulator you can step through it and see what it does. When the simulation gets to the delay routine put your cursor on the nop at the end, right click and select "run to cursor" to skip the delay code.
If you put the code into MPLAB and use the simulator you can step through it and see what it does. When the simulation gets to the delay routine put your cursor on the nop at the end, right click and select "run to cursor" to skip the delay code.
You can step through your code using F7 but the delay routines will take too long to step through. A simple way to skip the delay routine would be to change the numbers that go into d1 to d4 to 1.
You can step through your code using F7 but the delay routines will take too long to step through. A simple way to skip the delay routine would be to change the numbers that go into d1 to d4 to 1.
Or just press F8 instead of F7 when in the "Main" loop. This will step over the subroutines automatically. The sub is still executed and simmed, but you just miss the joy of many nested delay loops. But the code may take long to execute even using this method because you are trying for a 5 minute delay, so Pommies temporary mod has it's uses.
-I did try what you've said,, thanks. But the matter is I don't the matter with me is that I don't really understand the codes.. especially the $+1 and those RPO.. whats that for?
-The codes were just given in this site. I don't know how it flows.. I did try to go over with it but I have a hard time.
Or just press F8 instead of F7 when in the "Main" loop. This will step over the subroutines automatically. The sub is still executed and simmed, but you just miss the joy of many nested delay loops. But the code may take long to execute even using this method because you are trying for a 5 minute delay, so Pommies temporary mod has it's uses.
-I did try what you've said,, thanks. But the matter is I don't the matter with me is that I don't really understand the codes.. especially the $+1 and those RPO.
$ means PC or program counter and is an address value. The $ changes depending on where it is located in your code. $+1 is a cheat of sorts that allows you to avoid using an address label in your program. Personally, I don't like it as it can make code harder to understand especially when people do stuff like goto $+12 which makes you count instructions to find where it jumps to. They are using goto $+1 to waste time. It wastes more time in a single instruction than a simple nop.
I see no reference to RPO in this thread so i don't know what questions you have about it.
$ means PC or program counter and is an address value. The $ changes depending on where it is located in your code. $+1 is a cheat of sorts that allows you to avoid using an address label in your program. Personally, I don't like it as it can make code harder to understand especially when people do stuff like goto $+12 which makes you count instructions to find where it jumps to. They are using goto $+1 to waste time. It wastes more time in a single instruction than a simple nop.
I see no reference to RPO in this thread so i don't know what questions you have about it.
You code looks fine except for the missing include file.
If it is working in the simulator and not in hardware then the problem could be your external oscillator. Have you got the correct resistor/capacitor combination to get a 4MHz oscillator. I'm not even sure if an RC oscillator can go that fast.
The other thing that may be wrong is you may not be waiting long enough. Isn't your delay routine 5 minutes long? I would change this to 1 second until you get something working.
You code looks fine except for the missing include file.
If it is working in the simulator and not in hardware then the problem could be your external oscillator. Have you got the correct resistor/capacitor combination to get a 4MHz oscillator. I'm not even sure if an RC oscillator can go that fast.
The other thing that may be wrong is you may not be waiting long enough. Isn't your delay routine 5 minutes long? I would change this to 1 second until you get something working.
-I have not tried to connect a clock oscillator,, I have an crystal oscillator here. Is clock oscillator the same as crystal? In the handbook the clock oscillator has 4 pins but the crystal has only two.. Do I need other things for it to work?
I have an crystal oscillator here. Is clock oscillator the same as crystal? In the handbook the clock oscillator has 4 pins but the crystal has only two.. Do I need other things for it to work?
You need to supply power (5V) and ground to your oscillator. Then feed the output of the oscillator into pin 16 of the 16F84A. Do you have a link to the datasheet for it? You'll need to change the config word to this:
__CONFIG _CP_OFF & _WDT_OFF & _PWRTE_ON & _HS_OSC
How fast is the oscillator that you have? The max speed that the PIC can be clocked at would be 20Mhz so as long as your don't exceed that you should be fine.
-I have here a handbook,, Am I right if I say that the other pin of the crystal is to be supplied with 5V, connect it with the +of the 0.1uf capacitor. Then to the 14th pin of the PIC, then ground the leg of the capacitor? And the other pin of the crystal is to pin 16 of the PIC.
You need to supply power (5V) and ground to your oscillator. Then feed the output of the oscillator into pin 16 of the 16F84A. Do you have a link to the datasheet for it? You'll need to change the config word to this:
__CONFIG _CP_OFF & _WDT_OFF & _PWRTE_ON & _HS_OSC
How fast is the oscillator that you have? The max speed that the PIC can be clocked at would be 20Mhz so as long as your don't exceed that you should be fine.