Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[PIC] PIC16F877 Doing work for n sec

Status
Not open for further replies.

anishpsla

Member level 2
Member level 2
Joined
Dec 15, 2013
Messages
44
Helped
1
Reputation
2
Reaction score
1
Trophy points
8
Visit site
Activity points
402
PIC16F877 Doing work for n sec in MikroC

In my project, I want to do a work for 'n' sec. I am using MikroC and PIC16F877.

For example,


Code C - [expand]
1
UART1_Write_Text('String')



After executing this, I want to wait up to 'n' sec. If there no reply even after 'n' sec, function Timeout() will execute. Please help me by giving code for the same.


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
// this loop waits for the answer
    do{
       if(UART1_Data_Ready()){    
            response[x] = UART1_Read();
            x++;
            // check if the desired answer is in the response of the module
            if (strstr(response, expected_answer1) != NULL)    
            {
                answer = 1;
            }
        }
        // Waits for the asnwer with time out
    }
    while("not timeout");

 

Create a function that contains a code like this:

Code:
//...inside function
while(1)
{
  while(!UART1_Data_Ready())            //while no serial data is receive
  {
    DelayMs(1);                                  //... wait until timeout
    timer++;
    if(timer > time_out)
    {
      return ERR_TIMEOUT;
    }
  }
  response[x] = UART1_Read();         // read serial data
  x++;
  //More codes here
  // to process byte
  break;  //Exit from function
}
return OK;

then call the function like this:
Code:
result = GetSerialByte(2000);            //Get byte, wait for 2 sec
if(result == ERR_TIMEOUT)
{
    printf("Your dead");   
}
 
Thanks for your quick reply. I this will help me to implement the timeout.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top