#include <reg52.h>
/*------------------------------------------------------------------------*/
void main(void)
{
while(1)
{
unsigned char d;
for(d=0; d<20; d++)
{
TMOD &= 0xF0; // 1) TMOD = TMOD & 0xF0 ??
TMOD |= 0x01; // 2) TMOD = TMOD | 0x01 ??
ET0 = 0; // 3) ??
TH0 = 0x00;
TL0 = 0xFA;
TF0 = 0;
TR0 = 1;
while(TF0 == 0);
TR0 = 0; }
}
}
TMOD &= 0xF0; // 1) TMOD = TMOD & 0xF0 ??
TMOD |= 0x01; // 2) TMOD = TMOD | 0x01 ??
suromenggolo said:TMOD &= 0xF0; // 1) TMOD = TMOD & 0xF0 ??
it is to clear register timer0(bit3-bit0), but for register timer1(bit7-bit4) have still old setting. remember AND operation, result = 0, if x AND with 0
TMOD |= 0x01; // 2) TMOD = TMOD | 0x01 ??
it is to set register timer0, but register timer1 have still old setting.
remember OR operation, result=1, if x AND 1
If like that why we don't directly 2 in 1 just put TMOD = 0xF1;??
TMOD = 0x01; // used to make timer 0 work as 16 bit counter
to make copy and paste in any other program this technique made to save bit 4-7 as ( &0xF0) will clear just bits 0-3 then ( |0x01) to set only bit 0 so you sae value of bit 4-7 and set bit 0 and clear bits 1-3
Q3)here he deal only with timer 0 so he disable interrupt of timer 0
and it disable interrup here and use instead wait until timer over flow in command
while(TF0 == 0);
Not OK....OK ???
I am not understand this paragraph...TMOD = TMOD & 0xF0 means that you don't want to change the high nibble of TMOD.
Thus, if before get into delay loop the timer 1 would be configured to say 8 bit auto-reload, I bet you wouldn't want to change his behaviour when delay loop is finished.
That's why you performed the AND mask with 0xF0. To preseve the high nibble of TMOD.
If we leav the MSB like that wouldn't set any address, is it posible the program will indistinct occur?? Is it posible suddenly 2 timer (timer0 and timer1) is to be set??- Keep unchanged the bits 7, 6 and 5 of TMOD after leaving the delay loop
M1 M0 Mode Description
0 0 0 13-bit timer mode (8048 mode).
0 1 1 16-bit timer mode.
1 0 2 8-bit auto-reload mode
#include <reg52.h>
/*------------------------------------------------------------------------*/
unsigned char d;
void main(void)
{
while(1)
{
TMOD &= 0xF0;
TMOD |= 0x01;
EA=1; // Enable-all is enable but each interrupt source is set or clear its enable bit.
/* Q1)
Is it the EA=1 then we can set ET0/ET1=1?? If EA=0 then ET0 must set to ET0/ET1=0 am i right??
*/
ET0=1; // Enable the Timer 0 overflow interrupt.
d=0; // Q2) It should be put outside of main is it??
TH0 = 0x00;
TL0 = 0xFA;
TF0 = 0;
TR0 = 1; // Start Timer 1 Running
/* Q3)
The timer will count after the 0xFA then give 1 interrupt
*/
while(d<20); // Q4) Why put the statement here?? and why don't you put while(++d<20)
TR0=0;
ET0=0;
}
void timer0 (void) interrupt 1 using 2 // Where should i put the timer0 in main function
{
TR0 = 0;
TH0 = 0x00;
TL0 = 0xFA;
TF0 = 0;
d++;
TR0 = 1;
}
Help said:Hi..
Sorry.. I not understand the what the function doing can you explain it??
void timer0 (void) interrupt 1 using 2 // Where should i put the timer0 in main function
said:while(d<20);
become not valid, then the program will be continued.said:while(d<20);
while(d<2); // 2 easy to explain.,how can i check the d reach 2?
TR0=0;
ET0=0;
}
}
void timer0 (void) interrupt 1 using 2
{
TR0 = 0; // Why need to set again??
TH0 = 0x00; // Why need to set again??
TL0 = 0xFA; // Why need to set again??
TF0 = 0; // Why need to set again??
d++;
TR0 = 1;
}
Help said:while(d<2); // 2 easy to explain.,how can i check the d reach 2?
TR0=0;
ET0=0;
}
}
void timer0 (void) interrupt 1 using 2
{
TR0 = 0; // Why need to set again??
TH0 = 0x00; // Why need to set again??
TL0 = 0xFA; // Why need to set again??
TF0 = 0; // Why need to set again??
d++;
TR0 = 1;
}
function of timer0 will called and d will equal to 2,when return from this function now while (d<2);
not valed as d=2 !<2 ,then make
TR0=0;
ET0=0;
}
and finish the program\
Help said:hI...
1) just now program typed something wrong. I using uVision2.
2)How to use Breakpoint
3)Why i change the TH,TL value the time delay don't have any different (alway at 14uSec),
4)i use Performance Analyzer to debuge.
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?