I use Keil sometimes and while using a timer in autoload mode, the TH0 is loaded with the calculated value but TL0 starts incrementing from 00 instead of the calculated value F0.Am I missing something while using or configuring the keil simulator?
The program below is for generating square wave of some delay. I have taken F0 as eg to
check for small duration. When I run the program in step mode, the TL0 increments directly
to F3 and then the timer stops in autoload mode.The same set of instructions function in mode 1 I use keil Uvision 2.
#include <reg51.h>
void delay(); sbit mybit = P1^5; main(); { while(1) { mybit = mybit^1; delay(); } }
void delay() { TMOD = 0x02; TH0 = 0xF0; TL0 = 0xF0; TRO = 1 while(TF0==) TR0 = 0; TF0 = 0; }
"The program below"
that's a great piece of code.
keep up the good work!
This is one of the better lines:
while(TF0==)
I have to assume that the while loop should run until TFD becomes NULL.
I am simply amazed how many people who are supposed to be savvy at least with computers, fail to grasp the advantage of using "copy-paste" (but they apparently use it with success in their homework!) and re-type their "code". Stunning.
"Stunning."
as they say, stupidity is without limit.
/*Program for generating sqwave on pin 7 of port 2*/
#include <REG51.h>
sbit mybit = P2^7; void delay();
main() { while(1) { mybit = mybit^1; /*Invert mybit to toggle between 0 and 1*/ delay (); } }
void delay() { TMOD = 0X20; /*Timer 1 operation in mode 2*/ TH1 = -184; TR1 = 1; while(TF1==0);/*Polling mode is used instead of interupt mode*/ TR1 = 0; TF1 = 0; }
It works in autoload mode and the TL1 starts intially from 00 and later gets
loaded by the value in TH1 register.The problem is that it doesnt leave the delay routine
to go back to main program again where "mybit" is inverted to generate square wave of
50%duty cycle. The timer starts again after overflow and step mode execution is stuck at
while(TF1==0). But when it runs in mode 1, everything functions smoothly and the delay
routine returns to the main program.
'The problem is that it doesnt leave the delay routine'
you just cannot help killing yourself, can you?
Ashley,
Why don't you just help the poor chap?! Come on, the guy suffered enough (I would if I could!)
"Why don't you just help the poor chap?! Come on, the guy suffered enough (I would if I could!)"
tammy: for the same reason that I have given up on you.
at some point, a person is deemed beyond help.
<QUOTE>tammy: for the same reason that I have given up on you.</QUOTE>
i remember tapeer as a stewdent. to teech him i used code like this
while ( still_breathing ) { send_message( to_tapeer, "read abi, page x, section y" ); receive_message( from_tapeer, msg ); if ( is_response_an_insult ( msg ) ) { // msg prob from tapeer if (! is_response_like ( msg, "you are wrong, r0 is not preserved") ) { // tapeer might at finally be listening if ( is_response_like ( msg, "im very good, you dont know anything") ) { // tapeer found information but too stubborn to admit help was good break; } } } } do_some_real_work ( ); }
always yo're freind.
Zeusti
View all questions in Keil forum