How To Read The Timer Value Of 89c51 When Program Running
Ok this very difficult to find the Timer values of Microcontroller when a program is running but no problem im here ......
first of all i use Timer 1 in mode 2 for serial data transmission ( Means Read the timer value to serial port )
Now i use the Timer 0 in mode 1 and Start the initial value from 00H .In my given code the Port 1 is reserved for starting and stopping the Timer 0 .As in given code
#include <reg51.h>
#include <stdio.h>
extern void MSDelay(unsigned int);
extern void SerialTx(signed int);
void main (void)
{
int x;
SerialTx(-3);
TMOD=0xA1; //use Timer 1 in mode 2 and Timer 0 in mode 1 both are start and stop from externally
TH0=0x00;
TL0=0x00;
while(1)
{
if( P1==0)
{
TR0=1;
TI=1;
x=TH0;
x=x<<8;
x=x+TL0;
printf("The Timer 0 is ON. And The Value Is : ");
printf("%x, \n",x);
MSDelay(60);
}
else
{
TI=1;
printf("The Timer 0 is OFF. \n");
MSDelay(60);
}
}
}
#include <stdio.h>
extern void MSDelay(unsigned int);
extern void SerialTx(signed int);
void main (void)
{
int x;
SerialTx(-3);
TMOD=0xA1; //use Timer 1 in mode 2 and Timer 0 in mode 1 both are start and stop from externally
TH0=0x00;
TL0=0x00;
while(1)
{
if( P1==0)
{
TR0=1;
TI=1;
x=TH0;
x=x<<8;
x=x+TL0;
printf("The Timer 0 is ON. And The Value Is : ");
printf("%x, \n",x);
MSDelay(60);
}
else
{
TI=1;
printf("The Timer 0 is OFF. \n");
MSDelay(60);
}
}
}
As you see the blue colored code is my main code but in the main code there are two external Functions
extern void MSDelay(unsigned int);
extern void SerialTx(signed int);
extern void SerialTx(signed int);
the First Function is Delay Function And This is given below
#include <reg51.h>
#include <stdio.h>
void MsDelay( unsigned int);
void MsDelay( unsigned int itime)
{
unsigned int i , j ;
for (i=0;i<itime;i++)
{
for (j=0;j<1275;j++);
}
}
#include <stdio.h>
void MsDelay( unsigned int);
void MsDelay( unsigned int itime)
{
unsigned int i , j ;
for (i=0;i<itime;i++)
{
for (j=0;j<1275;j++);
}
}
And another Function is Serial Data Transmit Function which is also given Below
#include <reg51.h>
#include <stdio.h>
void SerialTx(signed int );
void SerialTx(signed int a)
{
TMOD=0xA0;
TH1=a; //9600 baud rate FD = -3
SCON=0x50;
TR1=1;
}
#include <stdio.h>
void SerialTx(signed int );
void SerialTx(signed int a)
{
TMOD=0xA0;
TH1=a; //9600 baud rate FD = -3
SCON=0x50;
TR1=1;
}
Now Proteuos Work
When The Project is stopped
When Project is On But Button is Off no data received from Timer 0
When Button is On and data received from Timer 0 ........
Thanks for watching you know my english is week but i think you understand my code ....but if any problem so Inform me