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.

How to call a function after a specific clock period

Status
Not open for further replies.

Micro Lover

Member level 2
Joined
Jul 22, 2009
Messages
44
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Location
pakistan
Activity points
1,614
hi
I am using 89c51. for using serial port I am using these commands
Code:
SCON  = 0x50;                  /* SCON: mode 1, 8-bit UART, enable rcvr    */
TMOD  = 0x20;                  /* TMOD: timer 1, mode 2, 8-bit reload      */
TH1   = 0xfd;                  /* TH1:  reload value for 9600 baud         */
TR1   = 1;                     /* TR1:  timer 1 run                        */
these are working correctly
------------
but in main function i am calling 2 functions

for example
---------------------
Code:
void main()
{
    while(1)
    {
        if(RI)
        {
            GetData();
        }
        if(??????????)
        {
            DisplayData();
        }
    }
}
At the location "??????????" I want to call the DisplayData() after a specific clock period, for example after every 1000 clocks. is it possible to set the timer0 of 89c51 for this purpose.
 

is it possible to set the timer0 of 89c51 for this purpose.
Answer is yes. You can use timer0 for this purpose. Set the timer0's interrupt to count for the desired delay. i.e if you want to
have an interrupt every 1000 cycles, the delay for 1000 cpu cycles will be, lets say using a crystal of 11.0592MHz, = 0.361us * 1000 = 361us.
then you can use logic like this:

Code:
unsigned char count = 0;

void timer0( void )   interrupt 1
{
     count = 1;
}

void main()
{
    while(1)
    {
        if(RI)
        {
            GetData();
        }
        if(count)
        {
            DisplayData();
            count = 0;
        }
    }
}

Regards,
Salman
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top