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 to make a timer to count 1 miniute

Status
Not open for further replies.

eugenehhk

Member level 1
Joined
Sep 6, 2006
Messages
34
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,529
I want to count 1 miniute or few miniute in the µc(8051) without using interrupt, how can I do?

THX~
 

Setup this subroutine:
Code:
POFDel  equ     250                          ;Desired delay in milliseconds
POFDel1:
        mov  R5,#((Crystal*POFDel)/6180000) ;Work out the djnz delay value
POFDel2:
;       mov     R4,#0
POFDel3:
        djnz    R4,POFDel3      ;This inside loop takes 515 cycles
        djnz    R5,POFDel2      ;This loop happens the correct number of times
                                ;  to get closest to the desired delay in ms
        ret                     ;Return when delay is complete
for 250 ms then run it 240 times and you will have a delay of ≈ 1s ..

Regards
IanP
 

Thx:)
But I want to use hardware to count time, it is because the 8051 is doing another job at the same time!
 

But I want to use hardware to count time, it is because the 8051 is doing another job at the same time!
8051 has build in timer hardware to count time while doing another job! Thats why you have to use interrupt!

the µc(8051) without using interrupt
If you want to use interrupt, i'll write sample code for you.
 

Hi,
get the number by dividing the 1min time to time period of the clock of the processor. after getting the number, u put in the loop and increment the number until it reaches that number. now the time will be one min...

Rgeards,
Tumma.
 

if you want to use hardware, you need to 555... choose correct resistor and capacitor... but i prefer you to use 8051 timer interrupt...:D
 
1 minute = (timer interrupt interval) * (count of some_value)

Load 2's complement of some_value in a counter,
when counter generate interrupt you got one minute delay.

reload it and start timer over again.
 

;delay of one minute without using interrupt but using timer
;--------------------------------------------

mov dptr,#0000h
orl tmod,#01h
l1:
mov tl0,#0fdh ;50ms
mov th0,#04h
setb tr0
here:
jnb tf0,here
clr tf0
inc dptr
cjne dph,#04h,l1 ;1200<--->04b0h
cjne dpl,#0b1h,l1
ret
 

init. for ex. using Timer/Counter 0 in mode 1

Clock 12MHZ msc 1usec ~0.97 sec Delay


MOV R2,#16
MOV TMOD,#01H
MOV TH0,#00H
MOV TL0,#00H
back:SETB TR0
again: JNB TF0,again
CLRTR0
CLR TF0
DJNZ R2,back


Total Delay in sec = instruction cycle * (65536 - initial timer value ( here is 0000 ) * ( value in R2 (here 16 ))
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top