Originally Posted by
pipsiphone
My main problem is how I will do this for each month and then at the certain time of the day. I understand how to control the relay but is there a better way to do it every 10 minutes, is that what you mean by the "delay"?
I just realized I am probably shooting my mouth off since a PIC is essentially an "embedded" device which I am not familiar with.
So it could be that you will not have the luxury of the sleep() function, and may have to work something out with the kernel you are using, which kernels keep time using processor "ticks", ie, write your own delay function.
In any case, the same logic applies. If you have a loop which just does something like this (pseudo-code):
Code:
while (1) {
myinterval = 10 minutes;
time = gettime;
if (time==(lasttime + myinterval)) {
do stuff;
lasttime = now;
}
}
Your PIC's lil' CPU will be runnning maxed out the whole time, because it will constantly be asking for the time (eg, 10000 times/second) until ten minutes is up. That may not matter, except it is a waste of electrical power and could severely reduce the lifetime of the chip. You need to get your process to "sleep" (which is what the sleep function literally does). That requires some kind of communication with the kernel, because it will be the kernel that pauses and restarts the process -- there is no way to do that with user-space code directly, which is why there are functions like sleep() and nanosleep(). I could be wrong.
But the first thing you want to find out is if you can use the sleep() function in your program, because embedded devices have a restricted instruction set which may make it impossible to implement all the "standard" functions (and that's all I know about embedded programming).
Anyway, I would guess PIC programming is widespread enough, and this task basic and essential enough, that there must be an easy solution available somewhere. Now you know what you are looking for (a function to set a sleep delay), you can start googling or whatever.
There are regulars here who do a lot of embedded stuff, me thinks, and one will surely be around today or tomorrow; if you retitle your thread (or start a new one) called "sleep function for PIC programming" there's a better chance of catching their attention.