Topic : KR-51 Simple delay

Forum : 8051

Original Post
Post Information Post
October 11, 2011 - 5:58am
Guest

Hi all I want to implement a simple blocking delay for init of my LCD

ie

LCD_Delay(time_period){

while(time_period != expired);

}

then I call it in my LCD when I need a "blocking delay" I have this working fine when not using KR-51

As a simple test of KR-51 I thought that I would replace this function with a delay from the kernel.

I Can't get it to work......

Here is what I have replaced it with,

void LCD_delay(unsigned char mSecs){
mui_delay = mSecs;
kr_create (_TaskWait_);
}

void TaskWait ( ) task _TaskWait_ priority 2 group MSEC_1 {
kr_create (_TaskDelay_);
kr_waitsig();
}

void TaskDelay ( ) task _TaskDelay_ priority 2 group MSEC_1 {

kr_del_abs(mui_delay);
kr_sendsig(_TaskWait_);
}

In short I want to create the task, wait until it expires and then destroy it.

I have other tasks running that are established on a while(1) loop and they tick away OK.

Any help here??
I would have thought this simple.

Regards

Marshall Brown

Replies
Post Information Post
+1
0
-1
October 11, 2011 - 3:44pm
Raisonance Support Team

Hi,

The optimizer may remove the whole code if it detects that it does not do anything.
What you can do is to insert NOP instructions as follows:

#include 

LCD_Delay(unsigned short time_period)
{
    while(time_period--)
        _nop_();
}

I hope this helps.
Best regards,

+1
0
-1
October 11, 2011 - 10:17pm
Guest

Sorry you may have misunderstood I will try to be clearer.

I would like to make a blocking timer using the KR-51 as a simple exercise to use the Kernel, this function should bock (prevent returning to the calling function) until the timer has expired.

This is what I have
void LCD_e_clk() {
LCD_E =0;
LCD_delay(1); //0.5ms delay
LCD_E=1;
LCD_delay(1); //0.5ms delay
LCD_E =0;
LCD_delay(1); //0.5ms delay
}

This is what I have changed it to

void LCD_e_clk() {
LCD_E =0;
mui_delay = 1;
kr_create (_TaskWait_);
LCD_E=1;
mui_delay = 1;
kr_create (_TaskWait_);
LCD_E =0;
mui_delay = 1;
kr_create (_TaskWait_);
}

void TaskWait ( ) task _TaskWait_ priority 2 group MSEC_1 {
kr_create (_TaskDelay_);
kr_waitsig();
}

void TaskDelay ( ) task _TaskDelay_ priority 2 group MSEC_1 {

kr_del_abs(mui_delay);
kr_sendsig(_TaskWait_);
}

I believe the issue is calling from a non RTOS function to a RTOS function, allows the calling function to return immediately without waiting my required delay.

This would be the "perfect" solution

void LCD_e_clk() {
LCD_E =0;
kr_del_abs(1); //0.5ms delay
LCD_E=1;
kr_del_abs(1); //0.5ms delay
LCD_E =0;
kr_del_abs(1); //0.5ms delay
}

of course I could write this LCD_e_clk() function to use the RTOS, but then what about the function that calls this one...and so on.

Thanks for the fast reply.

Regards

Marshall