Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics 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.

How can I count 1 second using an 8051 at 22Mhz??

Status
Not open for further replies.

Todi

Newbie level 1
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!
 

  • Like
Reactions: IanP

    IanP

    Points: 2
    Helpful Answer Positive Rating
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
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top