hi,I want to design a 'event counter ' where I want to rise an interrupt flag exactly after 10 pulses and my input is continious.
I m using at89s52, counter1 is loaded with 16bit mode
with TL1=FEH AND TH1=FFH,TMOD=50H
INPUT IS FROM IR SENSOR,IF IR DETECT 10 TIMES THEN THE FLAG MUST BE HIGH,BUT IT IS NOT HAPENING WITH THE LOADED VALUE ON TH1 AND TL1....FOR INDICATION I AM USING AN LED ON P1.0,,, IT WILL GLOW IF TF1 VALUE IS 1....
the code is working properly in keil ver4 but after loading hex and IR SENSOR is connected AT P3.5....it is not giving result
IT MUST BE SUCH THAT ON COUNTING 10 TIMES FROM IR SENSOR ...IT MUST MAKE LED GLOW ....BUT ON CONTRAST ON DETECTION OF 1 TIME LED GLOWING....
what about posting
* your exact code
* your schematic
* informations like microcontroller clock frequency, supply voltage
* informations like signal minimum time between edges, signal levels
* and all other related informations.
//THIS CODE IS FOR 8051, AT89S52,CRYSTAL USED=11.0592 FREQUENCY
//IF IR DETECTS 10TIMES THEN THEN THE PIN P1.4 MUST GO LOW
ORG 00H
XC:JB P1.2,$//TO START PROGRAM
SETB P1.4 //LED ON
Vv:MOV TMOD,#01010000B//16 BIT COUNTER1 SELECTED
MOV TH1,#0FFH;LOADED ON TH1 &TL1..FFF5MOV TL1,#0F5HSETB TR1 //START COUNTER
VB:JNB tf1,vb //CHECK TF1 FLAG OVERFLOW
CLR P1.4 //LED OFF
clr TR1 //STOP TIMER
clr tf1 //CLEAR TF1 FLAG
SJMP XC
END
The LED is (almost) all the time ON.
This is what your code says.
At line 7 you set the LED ON.
then it waits for 10 IR input edges.
At line 13 it shuts LED OFF
... but a couple of microseconds later
You jump to "XC" ...and at line 7 the LED is switched ON again.
--> The LED will go OFF, but your eyes and our brain isn´t fast enough to detect this couple of microseconds until it is ON again.