Help me Fixing this code :S i give up

Status
Not open for further replies.

Eng.Remon

New Member
ORG 00H
LJMP MAIN
ORG 1BH ;COUNTER 1
JB TF1,REACH
RETI
REACH: CLR TF1
CLR TR1
SETB P0.1
RETI


ORG 30H
MAIN: MOV P0,00H
MOV P2,00H
MOV P3,0FFH ;INPUT
MOV P1,#0ffH; input

MOV IE,#10001000B ; 1000 1000
MOV TMOD,#60H ;COUNTER1 MODE 2 0110 0000
MOV TL0,#0FAH ;1111 1000
MOV TH0,#0FAH
MOV IP,#00001000B
SETB P0.5
SETB TR1 ;START COUNTING

AGAIN: CPL P1.3
LJMP AGAIN

END
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
All i need to do here is to make an ir sensor program which counts how many times it is cut ,but with limits so i make it 8 counts here, but there is other things so i cant keep watching the pin for it, So i thought about making it connected to T1 (P3.5) and works as a counter. but what i cant find the problem in this code :S any help
 
Last edited:
Why are you loading both TL0 AND TH0 with 0xFA? If you have an eight bit conter you should not be loading both halves of the timer register. If you have a sixteen bit counter then it will be a long time until it overflows. Maybe TH0 should get the value 0xFF -- eh?
 
Too many errors to be good

Why testing TF1 in your ISR? If the ISR is trigged TF1 will be high so no need of testing. So at 01Bh you should only have
Code:
jmp Reach
with no reti command.

Why clearing TF1 in your "Reach" routine? TF1 is set by hardware on Timer/Counter overflow and cleared by hardware when processor vectors to ISR. So no need to clear in software!

What's the point of setting P0.1 when you never reset it?

You wrote
Code:
MOV P3,0FFH ;INPUT
MOV P1,#0ffH; input
Do you know the meaning of "#" ??
You need to be accurate with µC's. They do what you tell them to do even if it's meaningless... ...
So what will it be, with or without the "#" ??

Please don't mov 8 bits into IE. Use the predifined symbols ET0, EX1, EA and so on, that will be much easier to read. Thanks for that.

Why loading TL0 and TH0 when using Timer/Counter 1 ISR and control bits??

Why changing IP when you have only 1 interrupt??

What's the point of setting P0.5 when you never reset it?

What is it exactly what you want to do?
When we know that we can help you further...
 
Well you certainly devoted more effort to this post than I would have. People like Eng.Remon, the OP, need to struggle a bit at the beginning. If you hand them everything on a silver platter with sprinkles on top how will they ever learn. I know your heart is in the right place but Eng.Remon needs to learn how to peel the onion just like the rest of us.
 
Well, I pointed all the errors like he asked

When he come up with a corrected version I will help him further, but I will never actually write the code for him; he got to do it, I will only point out the errors and sometimes (like the TF1 thing) explain why it's working that way.

Long time ago I read all the "MCS 51" related chapters from the "8bit embedded controller handbook" by Intel, now a day people don't read datasheets and they don't know why it's not working

Waiting for Eng.Remon's replay... ...

Sincerely yours...



PS: I never mixed up cooking and programming
 
Thnx mcs51mc , you helped me alot .
btw this bits i set is just for testing . this code gona connected with more subprocedure but i only had to check the counter first , thats what i think easier for me to build codes. I ll Fix it and Then come back again wid more codes wait me.joking
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…