May 17, 2013 #1 T Todi Newbie level 1 Joined May 17, 2013 Messages 1 Helped 0 Reputation 0 Reaction score 0 Trophy points 1,281 Activity points 1,290 Hello everyone! So, I'm having lessons about computer architecture and the examples are passed using experiments with an ATMEL 8051 at 22Mhz. I'm initializing the TIMER0 in 16-bits mode and I'm trying to do the clock count 1 second after another. Knowing this, what I'm doing is: 22Mhz / 12 = 1,833333Mhz x 10^6 = 1833333Hz 1 / 1833333Hz = 0,5us And I'm stuck in here... what I have to do to know how much times I have to count to 1 second? I mean, what number I have to initiate the TH and TL? And how many times I have to count? Thank you all! PS.: I'm using Assembly!
Hello everyone! So, I'm having lessons about computer architecture and the examples are passed using experiments with an ATMEL 8051 at 22Mhz. I'm initializing the TIMER0 in 16-bits mode and I'm trying to do the clock count 1 second after another. Knowing this, what I'm doing is: 22Mhz / 12 = 1,833333Mhz x 10^6 = 1833333Hz 1 / 1833333Hz = 0,5us And I'm stuck in here... what I have to do to know how much times I have to count to 1 second? I mean, what number I have to initiate the TH and TL? And how many times I have to count? Thank you all! PS.: I'm using Assembly!
May 17, 2013 #2 js Full Member level 5 Joined Oct 9, 2005 Messages 266 Helped 38 Reputation 76 Reaction score 36 Trophy points 1,328 Activity points 2,670 Use some good free demo tool: se google for searcinhg for example......like: https://www.keil.com/c51 https://www.keil.com/c51/faq.asp And use google for searcinhg for examples......like: https://what-when-how.com/8051-microcontroller/programming-timer-interrupts/
Use some good free demo tool: se google for searcinhg for example......like: https://www.keil.com/c51 https://www.keil.com/c51/faq.asp And use google for searcinhg for examples......like: https://what-when-how.com/8051-microcontroller/programming-timer-interrupts/
May 17, 2013 #3 I IanP Advanced Member level 7 Joined Oct 5, 2004 Messages 7,929 Helped 2,311 Reputation 4,624 Reaction score 531 Trophy points 1,393 Location West Coast Activity points 66,416 With 22MHz the time unit is not 0.5us but roughly 0.545us To get 1ms delay the reload values are: 65536-1835=63701 => F8 D5 (1ms ≈ 1835 * 0.545us) Use Timer 0 of 8051 in MODE1 (16 bit timer) ... Code: DELAY: MOV TMOD,#00000001B // Sets Timer 0 to MODE1 (16 bit timer) MOV TH0,#0F8H // Loads TH0 register with F8H MOV TL0,#0D5H // LOads TL0 register with D5H SETB TR0 // Starts the Timer 0 HERE: JNB TF0,HERE // Loops here until TF0 is set (ie;until roll over) CLR TR0 // Stops Timer 0 CLR TF0 // Clears TF0 flag RET The above delay routine can be looped 1000 times in order to get a 1000mS=1s delay ... :wink: IanP
With 22MHz the time unit is not 0.5us but roughly 0.545us To get 1ms delay the reload values are: 65536-1835=63701 => F8 D5 (1ms ≈ 1835 * 0.545us) Use Timer 0 of 8051 in MODE1 (16 bit timer) ... Code: DELAY: MOV TMOD,#00000001B // Sets Timer 0 to MODE1 (16 bit timer) MOV TH0,#0F8H // Loads TH0 register with F8H MOV TL0,#0D5H // LOads TL0 register with D5H SETB TR0 // Starts the Timer 0 HERE: JNB TF0,HERE // Loops here until TF0 is set (ie;until roll over) CLR TR0 // Stops Timer 0 CLR TF0 // Clears TF0 flag RET The above delay routine can be looped 1000 times in order to get a 1000mS=1s delay ... :wink: IanP