Discussion in "8051 Discussion Forum" started by    Amit Kumar Das    Sep 24, 2010.
Tue Sep 28 2010, 04:33 am
Can you modify the source code for multitasking for a simple problem. The problem (question) is inside the folder.
Tue Sep 28 2010, 10:02 am
hi Amit Kumar Das
problem is seems simple but may be solution takes time
as the delay function in prototype u define it char and u passing a 5000 which is int range so delay is not generated as u want
try this delay function
// Delay mS function
void DelayMs(unsigned int count) 
{  // mSec Delay 11.0592 Mhz 
    unsigned int i;		       	
    while(count) {
        i = 115; 
0) i--;

DelayMs(5000); means 5 sec delay
but one problem is when we call a DelayMs(5000); the proecessor is buzi in looping so cannot check button is pressing or not
use of timer is better option as compare to loop
Tue Sep 28 2010, 03:24 pm
I want the solution by using FSM and not by using timer for delay or any other means. The question is related to FSM or kernel. As kernel requires more memory only FSM has the possibility. The question demands neither to use timer nor to use interrupt in either case.
Tue Sep 28 2010, 03:31 pm
as u coding above that is according to FSM but just problem is of delay in simple delay it can not check the other states i think ajay can suggest u better that what should further do
Thu Sep 30 2010, 12:30 am
well you have to use a timer
coz applications need delay.. they need a reference at least, if not the exact delay.

you can create a simple tick timer. that generates a CPU tick every 1 or 10ms as you like. so you can have a FSM like this.

//assuming there is a state named delay so
switch (state) {
    //other code
    case delay:
        currentTick = getTickCount();
        if(currentTick >
= 500) //for 10ms tick
            state = NextState;
            state = OtherState;
    //.. other code
Sun Oct 31 2010, 07:22 am
Ajay Sir,

Could you modify the source code multitasking8051.zip and post it ? I tried a lot but in vain. Please correct the source code. Please.

Sun Oct 31 2010, 10:41 am
@amit : your code in "multitasking.c" will not work coz u are calling a delay of 5 s in case of a key press. so while the corresponding led is glowing for 5 s there is no way of knowing if there is a key press on the other key's.

my suggestion : implement a delay function which will generate a delay of X ms.
determine a value of X ( considering clock speed, uC u are using, machine cycle if needed) such that u will not get a key press within that time.

roughly? consider X = 5 ms.

call the timer every time in the loop. if a key is pressed then set a variable and increment that count(global variable) in the delay function if the variable is set( u need four i think).

that way u can generate a delay of 5s w/o waiting for too long.

also check for key press in the loop after u call the delay.

hope this helps

Get Social


Powered by e107 Forum System



Sat Apr 13 2024, 12:17 pm
Sat Apr 13 2024, 05:23 am
Fri Apr 12 2024, 08:01 pm
Fri Apr 12 2024, 08:38 am
Thu Apr 11 2024, 06:07 am
Wed Apr 10 2024, 10:13 pm
Wed Apr 10 2024, 08:43 pm
Wed Apr 10 2024, 02:08 pm