Welcome to our site! EDAboard.com is an international Electronic Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.
No .. It is wrong. The two functions you wrote there for the two time delays will produce only one delay for certain amount of time which depends on your oscillator frequency. what is your oscillator frequency?
You are running a 8 bit timer according to the code . so it means that the timer will run upto FF(ie 255) ant a roll over(I hope you know what is roll over!) ie 256 cycles. At 12 Mhz , it creates a time delay of 1.085uS . so 1.085*256=277uS.Youtr timer will run for this time only. Moreover you don need to use TL in 8 bit mode. Please refer the book mazidi . Its a perfect book for begineers.
---------- Post added at 17:55 ---------- Previous post was at 17:53 ----------
You do it.. Making mistake and learning will make you stronger in that concept. I will not write the code .
I use to write in assembly so my reply may not help you completely.
If you like that one timer does the job:
(1) First, the output pin is initialized as 1 for example
(2) The timer THx and TLx are initialized as -950 (since the cycle time is 1us)
Note: -950 = 65536 - 950 (which is 2 bytes, high and low)
Note: for precise timing an offset should be added to -950 (to decrease its value, see below)
(3) ETx and TRx are finally set to 1
(4) In the interrupt subroutine of TimerX:
(4a) At its entry, the output pin is toggled
(4b) TRx=0, to halt the counter
(4c) The output pin is checked
(4c1) if 0, THx and TLx are set to -50 (also 2 bytes + its offset, see below)
(4c2) if 1, THx and TLx are set to -950 (+ its offset, see below)
(4d) TRx=1, to reactivate the counter
The time offset to be added is the time after TRx=0 up to TRx=1 in each path which may differ a bit for case 0 and case 1.
Hope it helps in a way.
Edited: I forgot to say that the timerX mode should also be set in TMOD; M1x=0 and M0x=1 (Mode 1)