Welcome to EDAboard.com

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.

Register Log in

how to delay using 8051 timer 1 or 0?

Status
Not open for further replies.

buts101

Full Member level 3
Joined
Apr 29, 2005
Messages
168
Helped
3
Reputation
6
Reaction score
2
Trophy points
1,298
Activity points
2,867
8051 timer 1/2 second

how can i generate delay time such as 1 ms or 10 ms or 1 second ..any..using timer 0 or 1 of 8051??
plz give me the code..
thank you
 

sunish

Advanced Member level 4
Joined
Sep 4, 2005
Messages
117
Helped
10
Reputation
20
Reaction score
2
Trophy points
1,298
Activity points
2,359
how to generate time delay in 8051

sir
top:first you make the timer as 16 bit timer ie mode 1
give the the value for 50 ms ie hex of 50000
give 20 to any register
start the timer with gate
when timer overflows,decriment the register and jump back to top when the register value becomes 0,you will get a dalay of 1 sec
pls check the crystal frequency.this is for 12 mhz.


sunish
 

shiva

Junior Member level 3
Joined
Oct 18, 2005
Messages
31
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,549
8051 timer1

you can go for the book by "ayela" on microcontroler(8051),there you can get your problem solved under the topics"timer"
 

IanP

Advanced Member level 5
Joined
Oct 5, 2004
Messages
7,942
Helped
2,309
Reputation
4,620
Reaction score
531
Trophy points
1,393
Location
West Coast
Activity points
66,459
8051 long delay

Have a look at the code below ..
It shows you how to generate 1ms delay, or 1kHz square wave, if you like ..
Some other examples can be found at:
http://foe.mmu.edu.my/course/ecp2036/lecture_4_2.pdf
All this is done assuming that the crystal frequency is 12MHz; for more common crystal frequency, namely 11,059200MHz, you will need to apply correction of 1µs (12MHz) --> 1.085µs (11,0592MHz) ..

Regards,
IanP
 

vinash

Member level 2
Joined
Nov 3, 2005
Messages
45
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,999
8051 timer0

HI,
I am giving you a sample code for delay function using Timer 0 for 50ms,Hope that helps


void delay (void) // Delay function using Timer 0 for 50ms.
{
TMOD &=0xF0;
TMOD |=0x01;
ET0 =0;
TH0 =0x3C;
TL0 =0xB0;
TF0 =0;
TR0 =1;
while(TF0==0);
TR0=0;

}
 

pjyc

Junior Member level 1
Joined
May 10, 2001
Messages
17
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,283
Activity points
81
1 sec delay in 8051

Hi.
Below code can control long time delay using timer interrupt 0.

Regards,
pjyc


Code:
$EP
$NOSB
$MR ;$NOGE
$XREF
$DEBUG
$TITLE ( LEDBLKT0 )

; Delay Using Timer interrupt 0. 
; This Application is LED blinking every 1/2 second.
; System Clock : 11.0592Mhz
;
BLK_TIME        EQU     50      ; BLK_TIME/100 = Delay time ; 0.5sec
SEC             DATA    34H
STACK           EQU     40H
;
        ORG     0
        LJMP    START
;
        ORG     0BH
        LJMP    TIM_0_INT
;
        ORG     100H
START:
        CLR     A
        MOV     R0,#127         ; Clear all of RAM
CLEAR:  MOV     @R0,A
        DJNZ    R0,CLEAR
;
        MOV     SP,#STACK
        MOV     IE,#0                   ; Disable
;
        MOV     TCON,#00000101B
        MOV     TMOD,#00100001B         ; Timer1=
        MOV     SCON,#01011110B         ; 8-Bit U
;
        CLR     TR1
        MOV     TH1,#-3                 ; 11.0592
        SETB    TR1                     ; TI SET
        CLR     RI
        MOV     P1,#0FFH
        MOV     P3,#0FFH
        ;
        MOV     SEC,#BLK_TIME
        CALL    RUN_TIMER_0
        SETB    EA
        
MAIN:
        JMP     MAIN        
        
;=======================================================
;       Timer_0_Interrupt
;-------------------------------------------------------
TIM_0_INT:
        PUSH    PSW
        PUSH    ACC
        CLR     ET0
        CLR     TR0
        MOV     A,#Low(-9500)        ; 1/100 Sec
        ADD     A,TL0
        MOV     TL0,A
        MOV     A,#High(-9500)
        ADDC    A,TH0
        MOV     TH0,A
        SETB    TR0
;
        DJNZ    SEC,BLK_DLY
        CPL     P3.5                 ; Complement Port 3.5 (LED)
        MOV     SEC,#BLK_TIME
BLK_DLY:
        CLR     TF0
        SETB    ET0
        POP     ACC
        POP     PSW
        RETI     
;
;
RUN_TIMER_0:
        CLR     TR0
        CLR     TF0
        ANL     TMOD,#11110000B         ; mask T0 Mode
        ORL     TMOD,#00000001B         ; 16 bit Timer
        MOV     TH0,#High(-9500)
        MOV     TL0,#Low(-9500)
        SETB    ET0                     ; Enable t0 int
        SETB    TR0
        RET        
;
END
 

sajal1975

Full Member level 2
Joined
Mar 25, 2005
Messages
136
Helped
6
Reputation
12
Reaction score
3
Trophy points
1,298
Activity points
2,149
8051 timer 1 sec

U CAN USE A PROGEAM:
N1:MOV R1,#10
N2: MOV R2,#10
DJNZ R2,N2
DJNZ R1,N1
RET
THIS CAN BE USED AS A DELAY.VALUES OF R1,R2 UPON U.
 

silvio

Advanced Member level 3
Joined
Dec 31, 2001
Messages
716
Helped
105
Reputation
210
Reaction score
16
Trophy points
1,298
Location
Romania
Activity points
11,497
8051 timer 1 sec delay

Sajal1975

Despite the fact that buts101's request was for using timer 1 or 0, your code has not other purpose but confusing buts101.

Just because executing your code, the micro will freeze in a beautiful endless loop.

Code:
N2:MOVR2,#10
DJNZ R2,N2
Nevertheless, even if will work after adjustments you'll never get long delay as buts101 demands: 1ms or 10ms or 1 second

It's nice to help others, but.....
Hope you'll see this reply and behaves accordingly not only kick and run.
 

eng_ahmed22

Full Member level 4
Joined
Jun 7, 2005
Messages
190
Helped
20
Reputation
40
Reaction score
5
Trophy points
1,298
Activity points
2,916
timer 8051 1 sec

hi every body
the next link has a good explanation of using timers in the 8051 microcontroller.
i learn from it ow to use the timer to make accurate delays and interrupt.
i think it will be useful to u as a piginner

www.8052.com/tuttimer.phtml
also the next link contains alot of sample programs to learn. it contains samples in assembly and c
http://www.8052.com/codelib.phtml
hope to be usefull

bye
Ahmed
 

Status
Not open for further replies.
Toggle Sidebar

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top