Can anyone please send me the code for counting pulses using timer 0 as counter in 'C'language.
Really now! You configure the timer in C quite similarly to the way you would do it in assembly language. Post your assembly code and the translated C code you are having trouble with. We'll tell you where you've gone astray.
The assembly code is MOV TMOD,#25h MOV TH0,#00h MOV TL0,#00h SETB P3.4 AGAIN:SETB TR0 MOV R3,TL0 MOV R4,TH0 Back: JNB TF0,Back CLR TR0 CLR TF0 SJMP AGAIN
The c code is
void main() { unsigned int pulsecount,Fpulse_count; while(1) { TH0=0x00; TL0=0x00; P3=0xFF; TR0=1; /* Start the timer for counting pulses*/ if(TF0!=1) { Fpulse_count++; } pulsecount=TH0*256+TL0; TR0=0; TF0=0; } }
Ugh! You didn't preview that, did you?
There's this little note, two bullet items above where you posted that said how do deal with source code. How did you miss it?
Anyway, with what little time I spent reading your unformatted code, I was able to see some discrepancies between the assembly and C. Post it again using the source code formatting tags and I'll bet we see more!
The C code is void main() { unsigned int Fpulse_count; while(1) { THO=0x00; TL0=0x00; P3=0xFF; TR0=1; if(TF!=1) { Fpulse_count++; } countpulses=TH0*256+TL0; }
I have tried to arrange it in proper order but it is posting like this.
Kindly reply on this only.
"I have tried to arrange it in proper order but it is posting like this.
Kindly reply on this only."
OK then. Right there above the message box where you entered or pasted that code, there were instructions how to post code. How did you miss it yet again? It's the line that yas the note about using HTML 'pre' and '/pre' tags.
The C code is
void main() { unsigned int Fpulse_count; while(1) { THO=0x00; TL0=0x00; P3=0xFF; TR0=1; if(TF!=1) { Fpulse_count++; } countpulses=TH0*256+TL0; } }
This time i am correct. Now you can reply.
That is not equivalent to the assembly code. For starters, you are not configuring the timer. Look back at your assembly code for TMOD.
No i have configured the timer as TMOD=0x25;
I forgot to write it. In main(), my first instruction is TMOD=0x25;
Are you saying that you typed in the code when posting?
Are you one of the few who have managed to get a computer without any copy/paste function?
How will we know what other information you forgot to write when "duplicating" the code?
View all questions in Keil forum