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.

delay on PIC16F84A

Status
Not open for further replies.
5Min delay program

_how should I insert the codes you have given? I did try but its wrong... kindly help me again...



5M delay routine from
Code:
Del5M	movlw	0x54
	movwf	d1
	movlw	0xA1
	movwf	d2
	movlw	0xFD
	movwf	d3
	movlw	0x02
	movwf	d4
Delay_0
	decfsz	d1, f
	goto	$+2
	decfsz	d2, f
	goto	$+2
	decfsz	d3, f
	goto	$+2
	decfsz	d4, f
	goto	Delay_0

			;5 cycles
	goto	$+1
	goto	$+1
	nop
	return
 
Code:
	list p=16F84A  
	#include <p16F84A.inc>  

	__CONFIG _CP_OFF & _WDT_OFF & _PWRTE_ON & _RC_OSC

d1	equ	0x0D
d2	equ	0x0E
d3	equ	0x0F
d4	equ	0x10

	org	0X000
	goto	Init

	org	0X004
	retfie


Init	bsf	STATUS,RP0
	clrf	TRISB
	clrf	TRISA
	bcf	STATUS,RP0

	clrf	PORTA	
	clrf	PORTB

Main	bsf	PORTB,0
	call	Del5M
	bcf	PORTB,0
	call	Del5M
	goto	Main

Del5M	movlw	0x54
	movwf	d1
	movlw	0xA1
	movwf	d2
	movlw	0xFD
	movwf	d3
	movlw	0x02
	movwf	d4
Delay_0
	decfsz	d1, f
	goto	$+2
	decfsz	d2, f
	goto	$+2
	decfsz	d3, f
	goto	$+2
	decfsz	d4, f
	goto	Delay_0

			;5 cycles
	goto	$+1
	goto	$+1
	nop
	return

	end
 
Last edited:
how to write this delay program in "c"? can any one tell me,
for assembly codes means so many reply coming but any forum related to c means no reply,why?
 
Last edited:
how to write this delay program in "c"? can any one tell me,
for assembly codes means so many reply coming but any forum related to c means no reply,why?

There's no real concrete standard C for the 8-bit PIC's (as far as I know), and most C/C++ compilers for 8-bit PIC's cost moneys. Assembly is free, light, and very powerful, since you control everything yourself, instruction-by-instruction. A compiler may not know to do something as efficiently as you can imagine it yourself. :D
 
how to write this delay program in "c"? can any one tell me,
for assembly codes means so many reply coming but any forum related to c means no reply,why?
One way you can do the same thing is with a for loop

for(x = 0, x <= 255, x++) {
;
} ; will delay for 256 cycles



There's no real concrete standard C for the 8-bit PIC's (as far as I know), and most C/C++ compilers for 8-bit PIC's cost moneys.

How about a C compiler for 12x 16x and 18x PICs for < $75?
http://www.sourceboost.com/
Or you can try it for free, as long as your program compiles to less than 2k.

For the 18x PICs Microchips C18 can be used for free, as well.

Assembly is free, light, and very powerful, since you control everything yourself, instruction-by-instruction. A compiler may not know to do something as efficiently as you can imagine it yourself. :D

If you are really good at writing assembly, then perhaps, but the people who write compilers are very skilled, and most compilers will produce much better, more compact code than a novice working in assembler. :)
 
Last edited:
5Min delay program

-Thanks Gayan...

-The programs is running good. But I have a hard figuring it. The ones with the RPO, $+1,0x54,0xFD and the like. Its my first encounter. I am still starting trying to understand the PICmicro Flash book.

-Does this code run on simple circuit like the one described in the PICmicro Flash book?


Code:
	list p=16F84A  
	#include <p16F84A.inc>  

	__CONFIG _CP_OFF & _WDT_OFF & _PWRTE_ON & _RC_OSC

d1	equ	0x0D
d2	equ	0x0E
d3	equ	0x0F
d4	equ	0x10

	org	0X000
	goto	Init

	org	0X004
	retfie


Init	bsf	STATUS,RP0
	clrf	TRISB
	clrf	TRISA
	bcf	STATUS,RP0

	clrf	PORTA	
	clrf	PORTB

Main	bsf	PORTB,0
	call	Del5M
	bcf	PORTB,0
	call	Del5M
	goto	Main

Del5M	movlw	0x54
	movwf	d1
	movlw	0xA1
	movwf	d2
	movlw	0xFD
	movwf	d3
	movlw	0x02
	movwf	d4
Delay_0
	decfsz	d1, f
	goto	$+2
	decfsz	d2, f
	goto	$+2
	decfsz	d3, f
	goto	$+2
	decfsz	d4, f
	goto	Delay_0

			;5 cycles
	goto	$+1
	goto	$+1
	nop
	return

	end
 
i finally got my pic lighting up LEDs, but now i cant get a delay working. i tried using lots of methods, this one is from a program that generates delay loops (pic delay loop calculator).

Code:
	list P=16F84A
	#include "p16f84A.inc"
	__CONFIG   _CP_OFF & _WDT_OFF & _PWRTE_OFF & _HS_OSC
	errorlevel -302   

CounterA equ 0x0C
CounterB equ 0x0D
CounterC equ 0x0E	

	bsf		STATUS,RP0
	movlw	b'00000000'
	movwf	TRISB
	bcf		STATUS,RP0

Main
	movlw	b'10111111'
	movwf	PORTB
	call	Delay

	movlw	b'01000000'
	movwf	PORTB
	call	Delay

	goto	Main

Delay
	movlw	D'26'
	movwf	CounterC
	movlw	D'119'
	movwf	CounterB
	movlw	D'85'
	movwf	CounterA
loop	decfsz	CounterA,1
	goto	loop
	decfsz	CounterB,1
	goto	loop
	decfsz	CounterC,1
	goto	loop
	return

	end
Interesting. Did it work?
 
I would suggest a different way of going about making a 5 minute delay;

If you want to make delays in proper minutes/seconds etc there is PIC assembler (and C) code here that will generate an interrupt exactly every second, then you can just count X seconds to get your accurate 5 minute delay. The same code can also be used for all sorts of clock functions etc. See;
Zero-error 1 second timing algorithm
 
Status
Not open for further replies.

Latest threads

Back
Top