Home > other >  C51 programming language, the wrong in where
C51 programming language, the wrong in where

Time:09-16

In T0 timer interrupt control P1 mouth only 8 led lights shining with period 2 second cycle, fosc12MHZ.
#include
Sbit led=P2 ^ 0;//define P2.0 mouth light
Void main ()
{
TMOD=0 x01;//set the timer works
TH0=(65536-50000)/256;//set the timer initial
TL0=(65536-50000) % 256;
EA=1;//always interrupt
ET0=1;//T0 timer overflow interrupt
TR0=1;//start T0
While (1);//wait for interrupt
}
Void Timer0 () interrupt 1//T0 timer interrupt handling subroutine
{
Int I;
for(i=0; I<40; I++)
{
TH0=(65536-50000)/256;//heavy initialise
TL0=(65536-50000) % 256;
}
Led=~ led;//control indicator lights flashing
}

CodePudding user response:

To change the you,
#include
Sbit led=P2 ^ 0;//define P2.0 mouth light
Void main ()
{
TMOD=0 x01;//set the timer works
TH0=(65536-50000)/256;//set the timer initial
TL0=(65536-50000) % 256;
EA=1;//always interrupt
ET0=1;//T0 timer overflow interrupt
TR0=1;//start T0
While (1);//wait for interrupt
}
Void Timer0 () interrupt 1//T0 timer interrupt handling subroutine
{
int i;
for(i=0; I<40; I++)
{
TH0=(65536-50000)/256;//heavy initialise
TL0=(65536-50000) % 256;
}
Led=~ led;//control indicator lights flashing
}

CodePudding user response:

reference 1st floor xuyaqi029 response:
give you changed it,
#include
Sbit led=P2 ^ 0;//define P2.0 mouth light
Void main ()
{
TMOD=0 x01;//set the timer works
TH0=(65536-50000)/256;//set the timer initial
TL0=(65536-50000) % 256;
EA=1;//always interrupt
ET0=1;//T0 timer overflow interrupt
TR0=1;//start T0
While (1);//wait for interrupt
}
Void Timer0 () interrupt 1//T0 timer interrupt handling subroutine
{
int i;
for(i=0; I<40; I++)
{
TH0=(65536-50000)/256;//heavy initialise
TL0=(65536-50000) % 256;
}
Led=~ led;//control indicator lights flashing
}

Where is the change? Did not see the changes

CodePudding user response:

Why do you want to add a loop to the timer interrupt

CodePudding user response:

Instead & lt; Reg51. H>
Int to Int

CodePudding user response:

The
reference 3 floor dceacho response:
why do you want to add a loop to the timer interrupt

2 seconds a cycle, isn't it, how to change

CodePudding user response:

reference 5 floor qq_45744378 reply:
Quote: refer to the third floor dceacho response:
why do you want to add a loop to the timer interrupt

A cycle, not 2 seconds can change


Change is not interrupt the cycle:
#include //& lt; Reg51. C>

Sbit led=P2 ^ 0;//define P2.0 mouth light

Unsigned char Tim;

Void main ()
{
TMOD=0 x01;//set the timer works
TH0=(65536-50000)/256;//set the timer initial
TL0=(65536-50000) % 256;
EA=1;//always interrupt
ET0=1;//T0 timer overflow interrupt
TR0=1;//start T0
While (1)
{
If (tim> 20)
{
Tim=0;
Led=~ led;//control indicator lights flashing
}
}
}
Void Timer0 () interrupt 1//T0 timer interrupt handling subroutine
{
Tim++;
TH0=(65536-50000)/256;//heavy initialise
TL0=(65536-50000) % 256;
TR0=1;//start T0

}

CodePudding user response:

You send what is the purpose of this post? In order to post to post?

CodePudding user response:

Oid Timer0 () interrupt 1//T0 timer interrupt handling subroutine
{
Int I;
for (I=0; I<40; I++)
{
[color=# FF0000] TH0=(65536-50000)/256;//heavy initialise
TL0=(65536-50000) % 256;

} [/color]
Led=~ led;//control indicator lights flashing
}
The code red do you want to do?

The interrupt function in general is
1, close the interrupt
2, do a little things (as far as possible avoid the use of loop)

CodePudding user response:

refer to 6th floor xuyaqi029 response:
Quote: refer to the fifth floor qq_45744378 reply:

Quote: refer to the third floor dceacho response:
why do you want to add a loop to the timer interrupt

A cycle, not 2 seconds can change


Change is not interrupt the cycle:
#include //& lt; Reg51. C>

Sbit led=P2 ^ 0;//define P2.0 mouth light

Unsigned char Tim;

Void main ()
{
TMOD=0 x01;//set the timer works
TH0=(65536-50000)/256;//set the timer initial
TL0=(65536-50000) % 256;
EA=1;//always interrupt
ET0=1;//T0 timer overflow interrupt
TR0=1;//start T0
While (1)
{
If (tim> 20)
{
Tim=0;
Led=~ led;//control indicator lights flashing
}
}
}
Void Timer0 () interrupt 1//T0 timer interrupt handling subroutine
{
Tim++;
TH0=(65536-50000)/256;//heavy initialise
TL0=(65536-50000) % 256;
TR0=1;//start T0

}

Here in the interrupt service routine, TR0 did not need to assignment 1 again, because in front of the program and no timer will turn off

CodePudding user response:

Beginners are easy to make mistakes, flashing light is 2 seconds, they want to configuring the timer time to 2 seconds, but did not find out 2 seconds timer timer,

Mainly in all aspects of the lack of knowledge, mainly because write interrupt service program is not clear, the main points of the write interrupt service program is as follows: the main points of the

1, the interrupt service routine must fast forward quickly, must not be time-consuming code in the interrupt service routine,
2, as for the flashing light is 2 seconds to complete can design a 20 milliseconds timer (timer is configured to automatically reassembled, prevent error)
3, define a counter, timer interrupt a counter accumulative 1
4, identified in the main program, when the counter & gt; 100, and he said to 2 seconds, flip the lights

If the counter & gt; 100
{
Close the interrupt
Counter=0
Open the interrupt
Turn lights
}


CodePudding user response:

Understand, used to interrupt and counting,
Good experience in

CodePudding user response:

Learned, is superior
  • Related