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.

[SOLVED] Help! timer0 programming for PIC16F84A

Status
Not open for further replies.

papunblg

Advanced Member level 3
Advanced Member level 3
Joined
Oct 22, 2010
Messages
716
Helped
172
Reputation
344
Reaction score
165
Trophy points
1,343
Location
Kolkata India
Activity points
6,421
With due respect, help requested to write assembly code (to write time delay routine) for timer0 programming for PIC16F84A only. I have seen a few books(mijidi) but they all contain examples using recent pic18 mcs which have different bit names for timer0 register and T0CON register is also different.
My requirment is -- for 16F84A micro. 5 milli Sec time delay without interrupt(RA4 pin should not go high). No C code please.
Thanks,
 

Hi,

Ok , your request is clear but you have left out the most important factor - what is your oscillator frequency ?


Your can create a 5ms delay with a Timer as you mention but you can also easily do it with a program code delay loop.

The differences are that a Timer based delay allows you to do other things while it is running where as the delay loop is dedicated to doing just that.

Here is the delay loop code based on a 4 mhz oscillator.

Code:
delay5		movlw	0xE7				;delay 5ms  - 4998 cycles  using a 4mhz osc
			movwf	d1
			movlw	0x04
			movwf	d2
dly5_1
			decfsz	d1, f
			goto	dly5_2
			decfsz	d2, f
dly5_2		goto	dly5_1
			retlw	0x00
 

Sir,
Thanks very much for your reply.
I want a timer based delay code for Pic16F84A.
 

Hi,

But you have not said what oscillator frequency / crystal you are using ? - all timings depend on it.
 

I would recommend the following tutorials:

**broken link removed**

Specifically:



And



These tutorial lessons should get you started using the Timer0 rather quickly.

BigDog
 
Darn, Deputy Dog beat me to it !! :lol: - was about to recommend the same.
 

Thanks but need more help!
Now I just want to know two things - OPTION_REG<5> is set to enter timer mode. But which bit is set to start the timer?
 

Thanks but need more help!
Now I just want to know two things - OPTION_REG<5> is set to enter timer mode. But which bit is set to start the timer?

Hi,

Refering to the 84A datasheet Timer0 block diagram fig 5.1

You will see that there are two possible inputs to Timer0 - with Pin RA4 connected to an external signal source Timer0 will act as a Counter of the incoming signals.

The other signal source is Fosc/4, this is the main operating clock / frequency for the chip, derived from the crystal in your case 4Mhz / 4 = 1Mhz , so you can calculate your timings from this figure.

When the bit OPTION REG 5 is set to 0 it selects Fosc/4 and Timer0 acts as a Timer; RA4 is free to be used as a standard i/o pin.
When bit 5 set to 1 it selects RA4 as the Counter input source.


When you set up TMR0 with the Option Reg it then starts TMR0 free running.
When you go to do a delay routine using TMR0, the first instructiom you do is CLRF TMR0 which clears any value in the Timer0, ready for you delay sequence.
 
Sir wp100,
Thank you very much. After reading your above reply, I think , I will not face any problem to program timer of any kind of pic micro. I have not found such a clear answer even in books. Thanks again.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top