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.

1Hz pulse generator using AT89C51

Status
Not open for further replies.

semiconductor

Full Member level 4
Joined
Apr 4, 2003
Messages
236
Helped
4
Reputation
8
Reaction score
0
Trophy points
1,296
Activity points
2,735
best 1 hz generator -555

I’m new to 89AT51 and programming it. I’m now trying to write a program in assembly to output a 1Hz pulse at P1.0 using Timer 0 (16-bit counter mode)
Can some one help me!

Thank you in advance!
 

asm counter down at89c51

Assume fosc = 12 MHz, 1 machine cycle = 1 us
=> 1s = 1.000.000us = 50000us x 20
Here is source:
MOV TMOD, #01H ; timer 0 mode 1
LOOP:
MOV TH0, #HIGH(-50000) ; count down 50000
MOV TL0, #LOW(-50000)
SETB TR0 ; timer 0 run
JNB TF0, $ ; wait timer 0 overflow
CLR TR0 ; stop timer 0
CLR TF0 ; clear timer 0 flag
CPL P1.0 ; pulse
JMP LOOP
 

timer 0 1hz

If you really want to be a fanatic for accuracy, then remember that the actual on time (and off time) in the code suggested by vkchau will be 50,000 us + the time it takes to execute the interrupt! For a 1 second pulse, this may be trivial but would be a problem if you needed, say a 1 ms pulse.

You can adjust the reload values (for example 50,007 in stead of 50,000 in this case) by knowing the ISR time.

Ajay
 

timer 0 1hz

First of all, I would like to send my best thank to all of you who have helped me!

Yeah, I do not want an accurate 1 Hz pulse. So the program vkchau posted here is to what extent useful to me. But exactly, your program just output a 10Hz pulse instead of 1 Hz pulse as indicated before (50.000 * 2, not 50.000 *20) so I have to modify a little bit, as follow:

(I use ASM51 to assembly this file)

$mod51
ORG 0000H
AJMP Start
Init:
MOV TMOD,#01H
CLR RS0
CLR RS1
Ret
Delay:
MOV R0,#20 ; count number
LOOP:
MOV TH0,#3CH ; High byte of -50.000
MOV TL0,#0B0H ; Low byte of -50.000
SETB TR0 ; Start timer
WAIT: JNB TF0,WAIT ; delay 50.000 us
CLR TR0 ;Stop Timer
CLR TF0 ;clear timer flag
DEC R0 ; decrease the count number by 1
CJNE R0,#0,Loop; if the content of register R0 is not equal to 0 then
; repeat Loop
Ret
Start:
acall Init
repeat:
CPL P1.0
Acall Delay
Ajmp Repeat
End

Of course, this program does not produce the accurate 1Hz, but is nearly 1Hz.

Lastly, Thank you to all!
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top