Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Using timer 2 for clock out on P1.0 of 89C450

Status
Not open for further replies.

kahlus

New Member
I am trying to output a 500khz clock out P1.0
I am running a 89C450 at 29.491mhz.
The serial routine using timer1 works fine.

I have the following test code:

;
; ***** TEST ROUTINE FOR TIMER 2 CLOCK OUT ON P1.0 *****
;
pcon equ 87h ;address of PCON register
t2con equ 0c8h
t2mod equ 0c9h
rcap2l equ 0cah
rcap2h equ 0cbh

org 0000h
ljmp start

org 0100h ;allways start ROM program at 0100h
start: nop
mov rcap2h,#0ffh
mov rcap2l,#0f1h
mov a,t2con ;get current t2con value
anl a,0fch ;clear bits 0 and 1 to set for 16bit reload
mov t2con,a ;write back to t2con

mov a,t2mod ;get current t2mod value
orl a,#02h ;sets bit 1 to enable p1.0 output
mov t2mod,a ;write back to t2mod

mov a,t2con ;get current t2con value
orl a,#04h ;sets bit 2 to enable timer2
mov t2con,a ;write back to t2con

mov scon,#50h ;set serial port 0 to mode 1 with rec enabled
mov tmod,#20h ;set timer 1 as auto-reload 8-bit timer
mov th1,#0fch ;baud rate equals 19200b at 29.491mhz
mov ie,#80h ;do not enable serial interupt
mov tcon,#40h ;start timer 1
setb ea ;global enable interrupts
setb p3.6 ;set pull-up on WR
setb p3.7 ;set pull-up on RD
clr ri ;ensure that receive interupt flag is cleared
clr ti
mov a,#00h ;clear Acc
mov p1, a ;clear port 1

loop: jnb ri,loop
mov a,sbuf ;get serial data
clr ri
mov sbuf,a ;echo back
jnb ti,$
ljmp loop


end

P1.0 goes low, stays low, and never get clock out?
What am I doing wrong? Please help me.
 
No
Code:
setb P1.0
clr P1.0
in your code !
No ISR for T2 either !
How do you expect P1.0 to generate something ??


kahlus said:
mov a,t2con ;get current t2con value
anl a,0fch ;clear bits 0 and 1 to set for 16bit reload
mov t2con,a ;write back to t2con

mov a,t2mod ;get current t2mod value
orl a,#02h ;sets bit 1 to enable p1.0 output
mov t2mod,a ;write back to t2mod

mov a,t2con ;get current t2con value
orl a,#04h ;sets bit 2 to enable timer2
mov t2con,a ;write back to t2con

I can't read that !
Please use
Code:
MyTime_2 equ 65535-5
mov RCAP2H,#High MyTime_2
mov RCAP2L,#Low MyTime_2
clr RCLK
clr TCLK
setb TR2
and so on, that way your code will be more readable to everyone.

Give it another try and come back later :)
 
What do you mean by NO!

All the data books I read say that timer2 can be used to generate a square wave clock output on p1.0 with any int service routine. I found the mistake in my code and it works great giving me a 500khz square wave clock at P1.0. My error was enabling external interrupts. It interfered with the internal reload. Apparently you are not as experienced as I am. I have been using the 8051 core for over 10 years now and I love it. I just never used the timers for anything but the serial baud generator. I have been designing custom machine interfaces for over 20 years starting with the 8085 micro. By the way, what assembler are you using? I still use asm51.
 
help regarding getting clock out from at89c52

I want to get a clock which will operate at 1Mhz from at89c52,there is a way to get programmable clock out through P1.0 by using timer2.I have written following code .but P1.0 is not at all changing its value.
can any body tell me the bug in my programme

T2CON EQU 0c8h
T2MOD EQU 0c9h
TH2 EQU 0CDh
TL2 EQU 0CCh
TR2 EQU 0CAh
RCAP2L EQU 0CAh
RCAP2H EQU 0CBh
ET2 EQU 0ADH
TF2 equ 0CFH


org 00h
mov a,t2mod
orl a,#02h
mov t2mod,a
mov t2con,#14h
mov th2,#0ffh
mov tl2,#000H
mov RCAP2H,#0ffh
mov RCAP2L,#00h
jmp $


end
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top