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.

Can't use Timer 2 in 89s52

Status
Not open for further replies.

Sharath411

Member level 1
Member level 1
Joined
Mar 27, 2010
Messages
38
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,288
Location
Bangalore
Activity points
1,529
Hi friends,

I want to know is it possible to use timer2 in 89s52. if yes please tell me how to code it because i am getting error as
'T2CON': undefined identifier
'RCAP2H': undefined identifier
;
;
and so on......
when i use the timer 2,, please help me its urgent..........


Thank you
 

Your compiler may not them in it's set of fixed memory locations ..
Try to declare them by yourself using:
T2CON DATA 0xxh

:wink:
 

Hi Ianp,

Thanks for reply, I am not getting wt you are telling,
this is my simple code

#include<reg51.h>
sbit pulse = P1^0;
void main()
{
TCLK = 0; // TIMER 2 IN 16 BIT AUTO RELOAD MODE
RCLK = 0;
CP_RL2 = 0;
IE = 0XA0; //ENABLE INTERRUPT FOR TR2
TH2 = 0XFC;
TL2 = 0XCF;
pulse = 0;
TR2 = 1;
while(1);
}
void timer2(void) interrupt 5
{
pulse =~ pulse;
}

please solve my problem.....
 

Headerfile problem.

check the reg51.h it does not have timer2 defined.

use proper header file

---------- Post added at 13:01 ---------- Previous post was at 12:57 ----------

use At89S52.H, and see that this header file should be present in the C drive where you installed keil

---------- Post added at 13:02 ---------- Previous post was at 13:01 ----------

The file name REGX51.H. It can be used in 89S52
 
Hi ckshivaram

thanks for help

but now i have the problem of counting the pulse
i have the program as
unsigned long int count;
unsigned int lbyte,hbyte;
P1=0;
T2CON=0x02;
T2MOD=0x01;
TL2 = 0x00; // Timer 2 low byte
TH2 = 0x00; // Timer 2 high byte
RCAP2L = 0x00; // Timer 2 reload capture register, low byte
RCAP2H = 0x00; // Timer 2 reload capture register, high byte

while(1)
{
TR2 = 1;
lbyte=TL1;
hbyte=TH1;
hbyte=hbyte<<8;
count= hbyte | lbyte;
DISPLAY(count);
}

but its not counting the pulses please help..........
 

Hi shivaram

Its a pulse counter, actually i did it by using timer/counter 0, and now i want to implement the application with the help of timer 2 so that i can use timer0 and timer one for other applications, so will you please help me in this concept.

Thank you..........
 

Hi ckshivaram

thanks for help

but now i have the problem of counting the pulse
i have the program as
unsigned long int count;
unsigned int lbyte,hbyte;
P1=0;
T2CON=0x02;
T2MOD=0x01;
TL2 = 0x00; // Timer 2 low byte
TH2 = 0x00; // Timer 2 high byte
RCAP2L = 0x00; // Timer 2 reload capture register, low byte
RCAP2H = 0x00; // Timer 2 reload capture register, high byte

while(1)
{
TR2 = 1;
lbyte=TL1;
hbyte=TH1;
hbyte=hbyte<<8;
count= hbyte | lbyte;
DISPLAY(count);
}

but its not counting the pulses please help..........

load the timers
lbyte=TL2;
hbyte=TH2;
instead of lbyte=TL1;
hbyte=TH1;
 

in your program you are loading the values to the timer2 isn't?
and running the timer2
but you are copying dead data from timer1 which is not at all initialized...................

copy RCAP2H & RCAP2L registers data instead of TH1 and TL1

---------- Post added at 12:12 ---------- Previous post was at 12:09 ----------

load the registers
lbyte=RCAP2L;
hbyte=RCAP2H;
instead of
lbyte=TL1;
hbyte=TH1;

---------- Post added at 12:19 ---------- Previous post was at 12:12 ----------

whenever there is falling edge pulse in P1.1 then the RCAP2H &RCAP2L are loaded with TH2 & TL2
 

Hi friend,

I did that also but still its not working...........

This is my code........
T2CON=0x02;
T2MOD=0x01;
TL2 = 0x00; // Timer 2 low byte
TH2 = 0x00; // Timer 2 high byte
RCAP2L = 0x00; // Timer 2 reload capture register, low byte
RCAP2H = 0x00; // Timer 2 reload capture register, high byte


TR2 = 1;
lbyte=RCAP2L;
hbyte=RCAP2H;
hbyte=hbyte<<8;
count= hbyte | lbyte;
DISPLAY(count);

I am getting same as 0000 in display........

Please help..
 

use
unsigned int count;
unsigned char lbyte,hbyte;
because RCAP2L & RCAP2H registers of 8 bit
and display integer type variable instead of long int

---------- Post added at 12:59 ---------- Previous post was at 12:56 ----------

send here your display program to check
 
hi friend

Sorry for delay is my code is correct which i have given and i am connecting 555 timer o/p to the P1.0 for counting the pulses Please check my code is correct or not.............

unsigned int count;
unsigned char lbyte,hbyte;
T2CON=0x02;
T2MOD=0x01;
TL2 = 0x00; // Timer 2 low byte
TH2 = 0x00; // Timer 2 high byte
RCAP2L = 0x00; // Timer 2 reload capture register, low byte
RCAP2H = 0x00; // Timer 2 reload capture register, high byte


TR2 = 1;
lbyte=RCAP2L;
hbyte=RCAP2H;
hbyte=hbyte<<8;
count= hbyte | lbyte;
DISPLAY(count);
 

your code is correct
but you told that you want to count the no of pulses then keep while loop
that is
PulsesCount=0;
while
{

lbyte=RCAP2L;
hbyte=RCAP2H;
hbyte=hbyte<<8;
count[PulsesCount]= hbyte | lbyte;
DISPLAY(count);
PrintOnLCD(PulsesCount); //shows the no of pulses on the LCD screan
}
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top