16F84 calling delay

Status
Not open for further replies.

uaefame

New Member
I am trying to send high and low signal using 16F84 microchip.

My plan is to send 30min delay low in port B,0
Then 58second low in port B,0 then 2 second high in portB,0. The 58second low and 2second high i want it to repeat for 53 times after the delay of 30minutes.

I have the codes here I am confused about calling portB,0 and setting it to low and then using loop for 53times for same instruction.
Code:
LIST	P=PIC16F84
	#INCLUDE "P16F84.INC"
	__CONFIG _CP_OFF & _WDT_OFF & _PWRTE_ON & _LP_OSC
	errorlevel -302

	cblock	0x0c
	d1,d2,d3
	endc

	org	0
init
	banksel	TRISA		;bank 1
	clrf	TRISA
	clrf	TRISB
	banksel	PORTB		;bank 0
	clrf	PORTB
main	bsf	PORTB,0
	call	delay30min
	bcf	PORTB,0
	nop			;slight delay for possible RMW problem
	bsf	PORTB,1
	call	delay2sec
	bcf	PORTB,1
	nop			;slight delay for possible RMW problem
	bsf	PORTB,2
	call	delay5sec
	bcf	PORTB,2
	goto	main

delay30min			;30minutes delay
	movlw	0xB6
	movwf	d1
	movlw	0x64
	movwf	d2
	movlw	0x20
	movwf	d3
Delay30min_0
	decfsz	d1, f
	goto	$+2
	decfsz	d2, f
	goto	$+2
	decfsz	d3, f
	goto	Delay30min_0
	nop
	return

delay6min59sec				;6minutes 59seconds delay
	movlw	0x87
	movwf	d1
	movlw	0x4F
	movwf	d2
	movlw	0x08
	movwf	d3
delay6min59sec_0
	decfsz	d1, f
	goto	$+2
	decfsz	d2, f
	goto	$+2
	decfsz	d3, f
	goto	delay6min59sec_0
	goto	$+1
	goto	$+1
	goto	$+1
	return

delay9min59sec      		;9minutes 59seconds delay
	movlw	0x1A
	movwf	d1
	movlw	0x73
	movwf	d2
	movlw	0x0B
	movwf	d3
delay9min59sec_0
	decfsz	d1, f
	goto	$+2
	decfsz	d2, f
	goto	$+2
	decfsz	d3, f
	goto	delay9min59sec_0
	nop
	return

delay58sec			;58seconds delay
	movlw	0xED
	movwf	d1
	movlw	0x03
	movwf	d2
	movlw	0x02
	movwf	d3
Delay58sec_0
	decfsz	d1, f
	goto	$+2
	decfsz	d2, f
	goto	$+2
	decfsz	d3, f
	goto	Delay58sec_0
	return

delay56sec			;56seconds delay
	movlw	0xFE
	movwf	d1
	movlw	0xFA
	movwf	d2
	movlw	0x01
	movwf	d3
Delay56sec_0
	decfsz	d1, f
	goto	$+2
	decfsz	d2, f
	goto	$+2
	decfsz	d3, f
	goto	Delay56sec_0
	goto	$+1
	goto	$+1
	nop
	return

delay49sec 			;49seconds delay
	movlw	0xBE
	movwf	d1
	movlw	0xDB
	movwf	d2
	movlw	0x01
	movwf	d3
delay49sec_0
	decfsz	d1, f
	goto	$+2
	decfsz	d2, f
	goto	$+2
	decfsz	d3, f
	goto	delay49sec_0
	goto	$+1
	goto	$+1
	nop
	return

delay11sec			;11secons delay
	movlw	0xBE
	movwf	d1
	movlw	0x45
	movwf	d2
delay11sec_0
	decfsz	d1, f
	goto	$+2
	decfsz	d2, f
	goto	delay11sec_0
	goto	$+1
	nop
	return


delay5sec			;5seconds delay
	movlw	0x3F
	movwf	d1
	movlw	0x20
	movwf	d2
Delay5sec_0
	decfsz	d1, f
	goto	$+2
	decfsz	d2, f
	goto	Delay5sec_0
	return


delay4sec			;4seconds delay	
	movlw	0xFF
	movwf	d1
	movlw	0x19
	movwf	d2
Delay4sec_0
	decfsz	d1, f
	goto	$+2
	decfsz	d2, f
	goto	Delay4sec_0		
	goto	$+1
	return
			
delay2sec			;2seconds delay
	movlw	0x7F
	movwf	d1
	movlw	0x0D
	movwf	d2
Delay2sec_0
	decfsz	d1, f
	goto	$+2
	decfsz	d2, f
	goto	Delay2sec_0
	return

delay1sec			;1second delay
	movlw	0x3E
	movwf	d1
	movlw	0x07
	movwf	d2
delay1sec_0
	decfsz	d1, f
	goto	$+2
	decfsz	d2, f
	goto	delay1sec_0
	goto	$+1
	nop
	return


	end
 
I guess everyone lost lets make my question even simpler, I want to repeat 52 times these command i am using 16F84.
Code:
	bsf	PORTB,0
	call	delay2sec
	bcf	PORTB,0
	call	delay58sec
 
Something simple like,
Code:
		movlw	.52
		movwf	RepeatCount
RepeatLoop	bsf	PORTB,0
		call	delay2sec
		bcf	PORTB,0
		call	delay58sec
		decfsz	RepeatCount,F
		goto	RepeatLoop

Mike.
 
I tried using this method but it gives me several error. Here is the codes
Code:
LIST	P=PIC16F84
	#INCLUDE "P16F84.INC"
	__CONFIG _CP_OFF & _WDT_OFF & _PWRTE_ON & _LP_OSC
	errorlevel -302

	cblock	0x0c
	d1,d2,d3
	endc

	org	0
init
	banksel	TRISA		;bank 1
	clrf	TRISA
	clrf	TRISB
	banksel	PORTB		;bank 0
	clrf	PORTB
main	bcf	PORTB,0         ;Turn off B0
	call	delay30min	
;53 times repeating 
		movlw	.53
		movwf	RepeatCount
RepeatLoop	bcf	PORTB,0
		call	delay58sec
		bsf	PORTB,0
		call	delay2sec
		decfsz	RepeatCount,F
		goto	RepeatLoop
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
	bcf	PORTB,0
	call	delay6min59sec
	bsf	PORTB,0
	call	delay1sec
;51 times repeating 
		movlw	.51
		movwf	RepeatCount1
RepeatLoop1	bcf	PORTB,0
		call	delay56sec
		bsf	PORTB,0
		call	delay4sec
		decfsz	RepeatCount1,F
		goto	RepeatLoop1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
	bcf	PORTB,0
	call	delay9min59sec
	bsf	PORTB,0
	call	delay1sec
;59 times repeating 
		movlw	.59
		movwf	RepeatCount2
RepeatLoop2	bcf	PORTB,0
		call	delay49sec
		bsf	PORTB,0
		call	delay11sec
		decfsz	RepeatCount2,F
		goto	RepeatLoop2
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
	bcf	PORTB,0
	call	delay2sec
	call	delay58sec
;59 times repeating 
		movlw	.59
		movwf	RepeatCount3
RepeatLoop3	bcf	PORTB,0
		call	delay49sec
		bsf	PORTB,0
		call	delay11sec
		decfsz	RepeatCount3,F
		goto	RepeatLoop3
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
	bcf	PORTB,0
	call	delay2sec
	call	delay58sec
;51 times repeating 
		movlw	.51
		movwf	RepeatCount4
RepeatLoop4	bcf	PORTB,0
		call	delay56sec
		bsf	PORTB,0
		call	delay4sec
		decfsz	RepeatCount4,F
		goto	RepeatLoop4
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
	bcf	PORTB,0
	call	delay9min59sec
	bsf	PORTB,0
	call	delay1sec
;53 times repeating 
		movlw	.53
		movwf	RepeatCount5
RepeatLoop5	bcf	PORTB,0
		call	delay58sec
		bsf	PORTB,0
		call	delay2sec
		decfsz	RepeatCount5,F
		goto	RepeatLoop5
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
	bcf	PORTB,0
	call	delay6min59sec
	bsf	PORTB,0
	call	delay1sec
	call	delay9min59sec

;8 times repeating 
		movlw	.8
		movwf	RepeatCount6
RepeatLoop6	bcf	PORTB,0
		call	delay30min
		decfsz	RepeatCount6,F
		goto	RepeatLoop6
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
	goto	main
	 
delay30min			;30minutes delay
	movlw	0xB6
	movwf	d1
	movlw	0x64
	movwf	d2
	movlw	0x20
	movwf	d3
Delay30min_0
	decfsz	d1, f
	goto	$+2
	decfsz	d2, f
	goto	$+2
	decfsz	d3, f
	goto	Delay30min_0
	nop
	return

delay6min59sec				;6minutes 59seconds delay
	movlw	0x87
	movwf	d1
	movlw	0x4F
	movwf	d2
	movlw	0x08
	movwf	d3
delay6min59sec_0
	decfsz	d1, f
	goto	$+2
	decfsz	d2, f
	goto	$+2
	decfsz	d3, f
	goto	delay6min59sec_0
	goto	$+1
	goto	$+1
	goto	$+1
	return

delay9min59sec      		;9minutes 59seconds delay
	movlw	0x1A
	movwf	d1
	movlw	0x73
	movwf	d2
	movlw	0x0B
	movwf	d3
delay9min59sec_0
	decfsz	d1, f
	goto	$+2
	decfsz	d2, f
	goto	$+2
	decfsz	d3, f
	goto	delay9min59sec_0
	nop
	return

delay58sec			;58seconds delay
	movlw	0xED
	movwf	d1
	movlw	0x03
	movwf	d2
	movlw	0x02
	movwf	d3
Delay58sec_0
	decfsz	d1, f
	goto	$+2
	decfsz	d2, f
	goto	$+2
	decfsz	d3, f
	goto	Delay58sec_0
	return

delay56sec			;56seconds delay
	movlw	0xFE
	movwf	d1
	movlw	0xFA
	movwf	d2
	movlw	0x01
	movwf	d3
Delay56sec_0
	decfsz	d1, f
	goto	$+2
	decfsz	d2, f
	goto	$+2
	decfsz	d3, f
	goto	Delay56sec_0
	goto	$+1
	goto	$+1
	nop
	return

delay49sec 			;49seconds delay
	movlw	0xBE
	movwf	d1
	movlw	0xDB
	movwf	d2
	movlw	0x01
	movwf	d3
delay49sec_0
	decfsz	d1, f
	goto	$+2
	decfsz	d2, f
	goto	$+2
	decfsz	d3, f
	goto	delay49sec_0
	goto	$+1
	goto	$+1
	nop
	return

delay11sec			;11secons delay
	movlw	0xBE
	movwf	d1
	movlw	0x45
	movwf	d2
delay11sec_0
	decfsz	d1, f
	goto	$+2
	decfsz	d2, f
	goto	delay11sec_0
	goto	$+1
	nop
	return

delay4sec			;4seconds delay	
	movlw	0xFF
	movwf	d1
	movlw	0x19
	movwf	d2
Delay4sec_0
	decfsz	d1, f
	goto	$+2
	decfsz	d2, f
	goto	Delay4sec_0		
	goto	$+1
	return
			
delay2sec			;2seconds delay
	movlw	0x7F
	movwf	d1
	movlw	0x0D
	movwf	d2
Delay2sec_0
	decfsz	d1, f
	goto	$+2
	decfsz	d2, f
	goto	Delay2sec_0
	return

delay1sec			;1second delay
	movlw	0x3E
	movwf	d1
	movlw	0x07
	movwf	d2
delay1sec_0
	decfsz	d1, f
	goto	$+2
	decfsz	d2, f
	goto	delay1sec_0
	goto	$+1
	nop
	return
	
	end
 
Hi,
RepeatCount should be predefined before being used. Put it in
Code:
	cblock	0x0c
	d1,d2,d3
	RepeatCount
	endc
 
Thanks alot the error reduce from 15 till 1! still one error i am trying my best to understand this error but still can't figure a way to solve it.
Code:
Debug build of project `D:\Openloop\Open loop 1\april.mcp' started.
Preprocessor symbol `__DEBUG' is defined.
Sat Apr 26 16:12:44 2008
----------------------------------------------------------------------
Clean: Deleting intermediary and output files.
Clean: Done.
Executing: "C:\Program Files\Microchip\MPASM Suite\MPAsmWin.exe" /q /p16F84 "16F84TMPO.ASM" /l"16F84TMPO.lst" /e"16F84TMPO.err" /d__DEBUG=1
Warning[205] C:\PROGRAM FILES\MICROCHIP\MPASM SUITE\TEMPLATE\OBJECT\16F84TMPO.ASM 1 : Found directive in column 1. (LIST)
Error[173]   C:\PROGRAM FILES\MICROCHIP\MPASM SUITE\TEMPLATE\OBJECT\16F84TMPO.ASM 281 : Source file path exceeds 62 characters (C:\PROGRAM FILES\MICROCHIP\MPASM SUITE\TEMPLATE\OBJECT\16F84TMPO.ASM)
Halting build on first failure as requested.
----------------------------------------------------------------------
Debug build of project `D:\Openloop\Open loop 1\april.mcp' failed.
Preprocessor symbol `__DEBUG' is defined.
Sat Apr 26 16:12:46 2008
FAILED

My codes are here
Code:
LIST	P=PIC16F84
	#INCLUDE "P16F84.INC"
	__CONFIG _CP_OFF & _WDT_OFF & _PWRTE_ON & _LP_OSC
	errorlevel -302

	cblock	0x0c
	d1,d2,d3
	RepeatCount
	RepeatCount1
	RepeatCount2
	RepeatCount3
	RepeatCount4
	RepeatCount5
	RepeatCount6
	endc

	org	0
init
	banksel	TRISA		;bank 1
	clrf	TRISA
	clrf	TRISB
	banksel	PORTB		;bank 0
	clrf	PORTB
main	bcf	PORTB,0         ;Turn off B0
	call	delay30min	
;53 times repeating 
		movlw	.53
		movwf	RepeatCount
RepeatLoop	bcf	PORTB,0
		call	delay58sec
		bsf	PORTB,0
		call	delay2sec
		decfsz	RepeatCount,F
		goto	RepeatLoop
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
	bcf	PORTB,0
	call	delay6min59sec
	bsf	PORTB,0
	call	delay1sec
;51 times repeating 
		movlw	.51
		movwf	RepeatCount1
RepeatLoop1	bcf	PORTB,0
		call	delay56sec
		bsf	PORTB,0
		call	delay4sec
		decfsz	RepeatCount1,F
		goto	RepeatLoop1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
	bcf	PORTB,0
	call	delay9min59sec
	bsf	PORTB,0
	call	delay1sec
;59 times repeating 
		movlw	.59
		movwf	RepeatCount2
RepeatLoop2	bcf	PORTB,0
		call	delay49sec
		bsf	PORTB,0
		call	delay11sec
		decfsz	RepeatCount2,F
		goto	RepeatLoop2
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
	bcf	PORTB,0
	call	delay2sec
	call	delay58sec
;59 times repeating 
		movlw	.59
		movwf	RepeatCount3
RepeatLoop3	bcf	PORTB,0
		call	delay49sec
		bsf	PORTB,0
		call	delay11sec
		decfsz	RepeatCount3,F
		goto	RepeatLoop3
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
	bcf	PORTB,0
	call	delay2sec
	call	delay58sec
;51 times repeating 
		movlw	.51
		movwf	RepeatCount4
RepeatLoop4	bcf	PORTB,0
		call	delay56sec
		bsf	PORTB,0
		call	delay4sec
		decfsz	RepeatCount4,F
		goto	RepeatLoop4
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
	bcf	PORTB,0
	call	delay9min59sec
	bsf	PORTB,0
	call	delay1sec
;53 times repeating 
		movlw	.53
		movwf	RepeatCount5
RepeatLoop5	bcf	PORTB,0
		call	delay58sec
		bsf	PORTB,0
		call	delay2sec
		decfsz	RepeatCount5,F
		goto	RepeatLoop5
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
	bcf	PORTB,0
	call	delay6min59sec
	bsf	PORTB,0
	call	delay1sec
	call	delay9min59sec

;8 times repeating 
		movlw	.8
		movwf	RepeatCount6
RepeatLoop6	bcf	PORTB,0
		call	delay30min
		decfsz	RepeatCount6,F
		goto	RepeatLoop6
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
	goto	main
	 
delay30min			;30minutes delay
	movlw	0xB6
	movwf	d1
	movlw	0x64
	movwf	d2
	movlw	0x20
	movwf	d3
Delay30min_0
	decfsz	d1, f
	goto	$+2
	decfsz	d2, f
	goto	$+2
	decfsz	d3, f
	goto	Delay30min_0
	nop
	return

delay6min59sec				;6minutes 59seconds delay
	movlw	0x87
	movwf	d1
	movlw	0x4F
	movwf	d2
	movlw	0x08
	movwf	d3
delay6min59sec_0
	decfsz	d1, f
	goto	$+2
	decfsz	d2, f
	goto	$+2
	decfsz	d3, f
	goto	delay6min59sec_0
	goto	$+1
	goto	$+1
	goto	$+1
	return

delay9min59sec      		;9minutes 59seconds delay
	movlw	0x1A
	movwf	d1
	movlw	0x73
	movwf	d2
	movlw	0x0B
	movwf	d3
delay9min59sec_0
	decfsz	d1, f
	goto	$+2
	decfsz	d2, f
	goto	$+2
	decfsz	d3, f
	goto	delay9min59sec_0
	nop
	return

delay58sec			;58seconds delay
	movlw	0xED
	movwf	d1
	movlw	0x03
	movwf	d2
	movlw	0x02
	movwf	d3
Delay58sec_0
	decfsz	d1, f
	goto	$+2
	decfsz	d2, f
	goto	$+2
	decfsz	d3, f
	goto	Delay58sec_0
	return

delay56sec			;56seconds delay
	movlw	0xFE
	movwf	d1
	movlw	0xFA
	movwf	d2
	movlw	0x01
	movwf	d3
Delay56sec_0
	decfsz	d1, f
	goto	$+2
	decfsz	d2, f
	goto	$+2
	decfsz	d3, f
	goto	Delay56sec_0
	goto	$+1
	goto	$+1
	nop
	return

delay49sec 			;49seconds delay
	movlw	0xBE
	movwf	d1
	movlw	0xDB
	movwf	d2
	movlw	0x01
	movwf	d3
delay49sec_0
	decfsz	d1, f
	goto	$+2
	decfsz	d2, f
	goto	$+2
	decfsz	d3, f
	goto	delay49sec_0
	goto	$+1
	goto	$+1
	nop
	return

delay11sec			;11secons delay
	movlw	0xBE
	movwf	d1
	movlw	0x45
	movwf	d2
delay11sec_0
	decfsz	d1, f
	goto	$+2
	decfsz	d2, f
	goto	delay11sec_0
	goto	$+1
	nop
	return

delay4sec			;4seconds delay	
	movlw	0xFF
	movwf	d1
	movlw	0x19
	movwf	d2
Delay4sec_0
	decfsz	d1, f
	goto	$+2
	decfsz	d2, f
	goto	Delay4sec_0		
	goto	$+1
	return
			
delay2sec			;2seconds delay
	movlw	0x7F
	movwf	d1
	movlw	0x0D
	movwf	d2
Delay2sec_0
	decfsz	d1, f
	goto	$+2
	decfsz	d2, f
	goto	Delay2sec_0
	return

delay1sec			;1second delay
	movlw	0x3E
	movwf	d1
	movlw	0x07
	movwf	d2
delay1sec_0
	decfsz	d1, f
	goto	$+2
	decfsz	d2, f
	goto	delay1sec_0
	goto	$+1
	nop
	return
	
	end
 
What is the maxium number off looping i can do for one iteration.
Code:
;53 times repeating 
		movlw	.53
		movwf	RepeatCount
RepeatLoop	bcf	PORTB,0
		call	delay58sec
		bsf	PORTB,0
		call	delay2sec
		decfsz	RepeatCount,F
		goto	RepeatLoop



I meant in this example i used 53 times to loop what is the maxium i can use can i used for example
Code:
;582 times repeating 
		movlw	.582
		movwf	RepeatCount
RepeatLoop	bcf	PORTB,0
		call	delay58sec
		bsf	PORTB,0
		call	delay2sec
		decfsz	RepeatCount,F
		goto	RepeatLoop

Is it possible or not?

Thanks in advance for any reply
 
Hi,
One register is 8-bit, which is 255 maximum. With 582, since it is 0x246. Only the lower 8-bit is taken. So you get only 0x46 or 70.
 
In eight bit register you can write upto 255 ( D'255').To write 582 you need more registers.

You told you send 30min delay low in port B,0 but your code is setting that bit for 30 mins.

Can you tell step by step?
 
Last edited:
Hi again,
Thanks Gayan Soyza and bananasiong for answering

I have another question:
I want to send signal in port B0,B1 at the same time
Code:
bsf	PORTB,0
This code is only used for sending signal to port B0 only i want to send to B0 and B1 at the same time.
 
Would a delay subsystem that allows you to specify delays as shown below be practical in your application?

Code:
;
;  must specify clock in MHz
;
clock   equ     8               ; 8 MHz clock
;
        DelayMS(1)              ; delay 1 msec
        DelayUS(1000)           ; delay 1 msec
        DelayCy(1*msecs)        ; delay 1 msec
        DelayCy(1000*usecs)     ; delay 1 msec
        DelayCy(1*msecs-3)      ; delay 1 msec minus 3 cycles
;
If so, then you're welcome to study the subsystem I developed (below) for 16F' devices with a clock frequency of 4, 8, 12, 16 or 20 MHz. It's based on a small 12 word subroutine which uses a one byte RAM variable and a set of macro "front ends".

Enjoy. Mike

Code:
;******************************************************************
;                                                                 *
;  DelayMS(), DelayUS(), DelayCy()    Mike McLaren, K8LH, Jun'07  *
;                                                                 *
;  a small 16-bit delay subroutine with macro "front ends" which  *
;  allow you to specify delays in msecs, usecs, or cycles.        *
;                                                                 *
;  requires the use of constant operands known at assembly time!  *
;                                                                 *
;  each delay macro call generates 4 instructions (for delays in  *
;  the ranges shown below).  longer delays up to several seconds  *
;  are possible but the macro produces 4 additional instructions  *
;  for every 262016 cycles in the delay.                          *
;                                                                 *
;     4 MHz, 1 cycles/usec, 16..262144 usecs, 1..262 msecs        *
;     8 MHz, 2 cycles/usec,  8..131072 usecs, 1..131 msecs        *
;    12 MHz, 3 cycles/usec,  6...87381 usecs, 1...87 msecs        *
;    16 MHz, 4 cycles/usec,  4...65536 usecs, 1...65 msecs        *
;    20 MHz, 5 cycles/usec,  4...52428 usecs, 1...52 msecs        *
;                                                                 *
;  here are some of the ways to generate a 1 millisecond delay;   *                                                               *
;                                                                 *
;       DelayMS(1)              ; delay 1 msec                    *
;       DelayUS(1000)           ; delay 1 msec                    *
;       DelayCy(1*msecs-2)      ; delay 1 msec minus 2 cycles     *
;       DelayCy(1000*usecs)     ; delay 1 msec                    *
;                                                                 *
;  use the DelayCy macro with the 'msecs' or 'usecs' multipliers  *
;  in the operand plus or minus some number of cycles to produce  *
;  precise clock independent isochronous timing.                  *
;                                                                 *
;******************************************************************
        radix   dec

clock   equ     8               ; user clock frequency in MHz
;
;  DelayCy() operand multipliers
;
usecs   equ     clock/4         ; cycles/microsecond multiplier
msecs   equ     usecs*1000      ; cycles/millisecond multiplier
;                                                                 *
;  DelayMS(), DelayUS(), and DelayCy() macros                     *
;                                                                 *
DelayMS macro   pDelay          ; milliseconds
        DelayCy(pDelay*msecs)   ; convert to cycles
        endm                    ;

DelayUS macro   pDelay          ; microseconds
        DelayCy(pDelay*usecs)   ; convert to cycles
        endm

DelayCy macro   pDelay          ; cycles (Tcy), minimum 16
        local   cycles
        cycles = pDelay
     while cycles > 262032
        movlw   high((262016-16)/4)+1
        movwf   TMRH
        movlw   low((262016-16)/4)
        call    DelayLo-(262016%4)
        cycles -= 262016
     endw
        movlw   high((cycles-16)/4)+1
        movwf   TMRH
        movlw   low ((cycles-16)/4)
        call    DelayLo-(cycles%4)
        endm
;                                                                 *
;  example code for simulation testing;                           *
;                                                                 *
SimTest DelayCy(20*msecs)       ; remember to set 'clock' equate
        nop                     ; put simulator break point here
;                                                                 *
;******************************************************************
;                                                                 *
;  Delay(16..262159 Tcy) subroutine   Mike McLaren, K8LH, Jun'07  *
;                                                                 *
;  12 words, 1 RAM variable, 14-bit core                          *
;                                                                 *
Delay.16
        nop                     ; entry point for delay%4 == 3    |B0
        nop                     ; entry point for delay%4 == 2    |B0
        nop                     ; entry point for delay%4 == 1    |B0
DelayLo addlw   -1              ; subtract 4 cycle loop time      |B0
        skpnc                   ; borrow?  yes, skip, else        |B0
        goto    DelayLo         ; do another loop                 |B0
        nop                     ;                                 |B0
DelayHi addlw   -1              ; subtract 4 cycle loop time      |B0
        decfsz  TMRH,F          ; done?  yes, skip, else          |B0
        goto    DelayLo         ; do another loop                 |B0
        goto    $+1             ; burn off 2 cycles               |B0
        return                  ;
;                                                                 *
;******************************************************************
 
Last edited:
I am using PIC starter programmer

when I programmed it this error shows up
Code:
PICSTART Program\Verify Report
19-Oct-2008, 08:28:21

Device Type: PIC16F84A
Address Range 0-17


Program Memory Errors

Address  Good  Bad

0000:    1683  FFFF
0001:    3000  FFFF
0002:    0085  FFFF
0003:    1283  FFFF
0004:    3002  FFFF
0005:    0085  FFFF
0006:    200B  FFFF
0007:    3000  FFFF
0008:    0085  FFFF
0009:    200B  FFFF
000A:    2804  FFFF
000B:    3011  FFFF
000C:    008C  FFFF
000D:    305D  FFFF
000E:    008D  FFFF
000F:    3005  FFFF
0010:    008E  FFFF
0011:    0B8C  FFFF
0012:    2814  FFFF
0013:    0B8D  FFFF
0014:    2816  FFFF
0015:    0B8E  FFFF
0016:    2811  FFFF
0017:    0008  FFFF


Configuration Memory Errors

Field :		Oscillator
Expected:	XT
Received:	RC

Field :		Power Up Timer
Expected:	On
Received:	Off

The codes which I am using is
Code:
    list      p=16F84A             ; list directive to define processor
    #include <p16F84a.inc>         ; processor specific variable definitions

    __CONFIG   _CP_OFF & _WDT_ON & _PWRTE_ON & _XT_OSC


	cblock	0x0c
	d1
	d2
	d3
	endc

		bsf		STATUS,5
		movlw	00h
		movwf	TRISA
		bcf		STATUS,5

START	movlw	02h
		movwf	PORTA
		call 	Delay2sec
		movlw	00h
		movwf	PORTA
		call 	Delay2sec
		goto	START


Delay2sec
			;1999996 cycles
	movlw	0x11
	movwf	d1
	movlw	0x5D
	movwf	d2
	movlw	0x05
	movwf	d3
Delay2sec_0
	decfsz	d1, f
	goto	$+2
	decfsz	d2, f
	goto	$+2
	decfsz	d3, f
	goto	Delay2sec_0

			;4 cycles (including call)
	return
	END

Any suggestion why this error shows up?
 
Don't worry problem solved I was buring the PIC 16F84a codes into PIC 16F818. Btw. I was using PIC start+.

Thanks for replying
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…