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.

simple delay for PIC16Fxx

Status
Not open for further replies.

DrOohYen

Newbie level 1
Joined
Jun 12, 2008
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,289
interrupt ใน pic16fxx คือ

Hi

Can Someone please explain me how to count a 1 ms delay for pic with 8 Mhz oscillator ? I mean what value i should put into TMRx register to acquire such a delay - and what prescaller (if needed ) should be used.

Thx in advance
 

Here's the classic Delay Code Generator on PIClist



Here's the code it generated for your question

Code:
; Delay = 0.001 seconds
; Clock frequency = 8 MHz

; Actual delay = 0.001 seconds = 2000 cycles
; Error = 0 %

	cblock
	d1
	d2
	endc

			;1998 cycles
	movlw	0x8F
	movwf	d1
	movlw	0x02
	movwf	d2
Delay_0
	decfsz	d1, f
	goto	$+2
	decfsz	d2, f
	goto	Delay_0

			;2 cycles
	goto	$+1


Edit opps you want to use a timer. I'll see if I can dig some code up.
 

reloadT1Hi equ 255
reloadT1Lo equ 6 ; trimming
count equ 0x20
org 0
goto setup
org 4
retfie
; 8 megs-->> one tick = 0.125 uSec
; prescale by 8 -->> 1 uSec / tick
setup movlw 00110000b;leave bit 0 = 0
movwf t1con
clrf count
; must preset High and Low
; must check interrupt flag(no need for interrupt)
; just the flag



loop
use bcf status,rp0 ; 1 make sure to be in the right bank
bcf pir1,tmr1if ; 1
movlw reloadT1Hi ; 1
movwf tmr1h ; 1
movlw reloadT1Lo ; 1
movwf tmr1l ; 1
bsf t1con,0 ; 1 from now on progr steps are not delays
testt1 btfss pir1,tmr1if
goto testt1
; timed out 1 usec for 8 ticks
incf count,f
goto loop

end

Just cooked this one

Note: You would need a Xtal to run at 8 megs on a 16F676
 

for any uc set the prescale register than set the register to which it should matces(like match register) and see the clock parameter that which clock the timer is using.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top