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.

[51] 8051 Timer Interrupt Programming.

Status
Not open for further replies.

Titus Manoj Kumar

Junior Member level 2
Junior Member level 2
Joined
Oct 18, 2013
Messages
24
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Location
Sriperumpudur, Tamil Nadu
Visit site
Activity points
178
Dear All,

Am working on 8051 Timer Interrupt Programming.

Specs:

Timer 0 Mode 1.
Need to blink an Led for 30 seconds.
Xtal Freq: 11.0592Mhz.

I've pasted the code below. Could you please identify the errors in it. If so could you give me the complete code for it. It'l be a great help. Thanks.

code :


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include<reg51.h>
sbit led = P2^0;        //LED connected to D0 of port 1
 
void timer(void) interrupt 1        //interrupt no. 1 for Timer 0
{
int x;
for (x=0; x<600 ; x++)
{
led=~led;       //toggle LED on interrupt
TR0 = 0;
}
}
main()
{
TMOD = 0x01;        // mode1 of Timer0
TH0 = 0x4C;     // initial values loaded to timer
TL0 = 0x00;
IE = 0x82;      // enable interrupt
TR0 = 1;        //start timer
while(1);       // do nothing  
}

 
Last edited by a moderator:

It looks like you did not call the timer function in the main function.
 

Dear All,

Am working on 8051 Timer Interrupt Programming.

Specs:

Timer 0 Mode 1.
Need to blink an Led for 30 seconds.
Xtal Freq: 11.0592Mhz.

I've pasted the code below. Could you please identify the errors in it. If so could you give me the complete code for it. It'l be a great help. Thanks.

code :


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include<reg51.h>
sbit led = P2^0;        //LED connected to D0 of port 1
 
void timer(void) interrupt 1        //interrupt no. 1 for Timer 0
{
int x;
for (x=0; x<600 ; x++)
{
led=~led;       //toggle LED on interrupt
TR0 = 0;
}
}
main()
{
TMOD = 0x01;        // mode1 of Timer0
TH0 = 0x4C;     // initial values loaded to timer
TL0 = 0x00;
IE = 0x82;      // enable interrupt
TR0 = 1;        //start timer
while(1);       // do nothing  
}

tell us what are problems you are facing while dumping it on hardware. Does the leds are lit continuoulsy i.e either on/off (with no toggle)?
first of all you have not cleared the timer flag & hence the interrupt will not terminate.
another do not use
Code:
while(1);
it will again start initializing from starting & hence the timer flag will never be set.
So use something like this:
Code:
while(1)
{
//do some work here
//may be blinking leds on some other ports .
}

- - - Updated - - -

It looks like you did not call the timer function in the main function.

but, that is not timer function to blink leds it's the ISR & the controller will jump only when interrupt occurs & hence he need not to call that in the main function.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top