MCU crystal frequency?
Checking the output without CRO:
Duty cycle: By a DC voltmeter, the reading should be 1/2 V_high.
Frequency: By a counter to divide it by N (if 8-bit counter, N=256), and LED is added at the output (with a current limiting resistor in series)
Added:
If I am not wrong your crystal frequency is 12 MHz
This means the unit of the instruction cycle time is 12 / 12e6 = 1us (I assumed 1 cycle = 12 clocks)
As you know, TH1 and TL1 should be loaded (re-loaded) with the value 65536 - x
x (in sec) = 1/50Hz/2 (since it is half period) = 0.01 sec
x (in cu, cycle unit) = x (in sec) / cycle unit = 0.01/1e-6 = 10,000 cu
But...
But since the TH1/TL1 reloading must be preceded and followed by CLR TR1 and SETB TR1 respectively, 10,000 must be decreased a bit.
The reloading takes 4 cu and SETB TR1 takes 1 cu (CLR TR1 is not counted since the counter will stop after its execution).
We may call 4+1 = 5 cu as offset_t.
So x (final) = x (original) - offset_t = 10000 - 5 = 9995 cu
Therefore TH1 and TL1 should be loaded with:
TH1 = high (65536 - x) = high (65536 - 9995) = high (55541) = 0D8h
TL1 = low (65536 - x) = high (65536 - 9995) = high (55541) = 0F5h
see comment below.
======================================
======================================
MOV TMOD,#10H ;timer 1,mode1
CLR TR1 ;stop timer1
AGAIN:
MOV TL1,#0F9H ;low byte of timer , [2 cu]
MOV TH1,#0D8H ;high byte of timer , [2 cu]
SETB TR1 ;start timer1 , [1 cu]
BACK:
JNB TF1,BACK
CLR TR1 ;stop timer1 , [not in the offset_t because the counter will stop after it]
CPL P2.3 ;P2.3 to get high,low , [1 cu]
CLR TF1 ;clear timer flag , [1 cu]
SJMP AGAIN ;reload timer1 , [2 cu]
======================================
======================================
I think the offset_t should be recalculated... since I usually use the timer interrupt unlike here.
For the above code it should be 9.
TH1 = 0D8h
TL1 = 0F9h
Note: The entry delay time (before looping) is obviously not accurate.
Kerim
Edited:
MOV TL1,#F9H ;low byte of timer , [2 cu]
to
MOV TL1,#0F9H ;low byte of timer , [2 cu]