| View previous topic :: View next topic |
| Author |
Message |
storic
Joined: 04 Aug 2007 Posts: 3 Location: SA Australia
|
Posted: Sun Aug 05, 2007 12:40 am Post subject: question on "Multiple non-blocking delays with 1 timer& |
|
|
thank you for sharing this code, it was something I was going to do, started several times with similar code however was not sure about how to go about it until now.
with regards to the struct
| Code: | | void (*stop)() ; // pointer to a function to call after delay |
Is this call to a dummy function so you know when you are at the end or is there an actual function called stop within "MikroE C"
I take it | Code: | | KEY_STRUCT keys[NBKEYS] ; // struct array | refers to the number of STRUCT's with the keys[NBKEYS] =2
| Code: | | void keyStart(unsigned char i, unsigned long d) |
you have made it in ms. I would be making it in sec as I would be looking for up to several minuets/hours in some instants.
with this code. am I to understand that I can delay an output until on or off by a set count and while during this process, I can set another delay function without effecting the first delay function thus creating 2 (keys[NBKEYS] ) independent delays. More if NBKEYS is more than 2.
One addition is I would add with #define NBKEYS 2
| Code: |
#define CPU 0
#define TimeON 1
//etc to be able to ID
// keyStart(0, 2000) ; to read keyStart(CPU, 2000) ; // #0 = CPU
|
Andrew  |
|
| Back to top |
|
BrunoG Site Admin
Joined: 22 Nov 2005 Posts: 636
|
Posted: Sun Aug 05, 2007 10:18 pm Post subject: Re: question on "Multiple non-blocking delays with 1 ti |
|
|
Hi Andrew, nice to see you here
| storic wrote: | thank you for sharing this code, it was something I was going to do, started several times with similar code however was not sure about how to go about it until now.
with regards to the struct
| Code: | | void (*stop)() ; // pointer to a function to call after delay |
Is this call to a dummy function so you know when you are at the end or is there an actual function called stop within "MikroE C"
|
stop is a member of a structure : it is a pointer to a function with no parameters and no return value.
this pointer must be assigned to a valid user's function, that will be called when the corresponding delay has expired.
| Quote: | I take it | Code: | | KEY_STRUCT keys[NBKEYS] ; // struct array | refers to the number of STRUCT's with the keys[NBKEYS] =2
|
keys is an array of NBKEYS (i.e 2) elements of KEY_STRUCT type structure.
| Quote: |
| Code: | | void keyStart(unsigned char i, unsigned long d) |
you have made it in ms. I would be making it in sec as I would be looking for up to several minuets/hours in some instants.
|
since the delay in ms is an unsigned long integer, you can have delays up to 49 days approximately
| Quote: |
with this code. am I to understand that I can delay an output until on or off by a set count and while during this process, I can set another delay function without effecting the first delay function thus creating 2 (keys[NBKEYS] ) independent delays. More if NBKEYS is more than 2.
|
That's it !
| Quote: | One addition is I would add with #define NBKEYS 2
| Code: |
#define CPU 0
#define TimeON 1
//etc to be able to ID
// keyStart(0, 2000) ; to read keyStart(CPU, 2000) ; // #0 = CPU
|
Andrew  |
Yes, no problem ! _________________ BrunoG, Administrator |
|
| Back to top |
|
storic
Joined: 04 Aug 2007 Posts: 3 Location: SA Australia
|
Posted: Tue Aug 07, 2007 11:00 am Post subject: Re: question on "Multiple non-blocking delays with 1 |
|
|
| BrunoG wrote: | Hi Andrew, nice to see you here
| storic wrote: | thank you for sharing this code, it was something I was going to do, started several times with similar code however was not sure about how to go about it until now.
with regards to the struct
| Code: | | void (*stop)() ; // pointer to a function to call after delay |
Is this call to a dummy function so you know when you are at the end or is there an actual function called stop within "MikroE C"
|
stop is a member of a structure : it is a pointer to a function with no parameters and no return value.
this pointer must be assigned to a valid user's function, that will be called when the corresponding delay has expired. |
I am impress, I did not see it at first, it took some time to see how the function was part of the struct, I was looking at the code not the meaning of the code (looking at the forest untill I saw the tree) this line " keys[0].stop = toggleC ;" was when I understood it. Thanks
I have to say it would have taken me many moons to get to this stage, so my statement "with similar code" was not true. I should of said "with clunky, disjointed code"
thanks again _________________ What has been learnt if you make the same mistake?  |
|
| Back to top |
|
BrunoG Site Admin
Joined: 22 Nov 2005 Posts: 636
|
Posted: Tue Aug 07, 2007 9:54 pm Post subject: |
|
|
Hi Storic, you're welcome.
Have a great walk through the forest ! _________________ BrunoG, Administrator |
|
| Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|