• 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.

homeymoore

New Member
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
 

homeymoore

New Member
its probably not the lack of org. the code runs fine, but the leds stay at the first sequence(10111111). and if the first 'call delay' is taken out, the leds stay at the second sequence(01000000).
 

motion

New Member
I don't see any wrong with the program but it sure runs slow on the simulator and would seem like it is not working. Try changing the values that initialize CounterC and CounterB to "1" if you're testing it on a simulator.
 

homeymoore

New Member
it seems every delay code doesnt work, so its probably a hardware problem. i cant see anything wrong with my circuit, could something be wrong with my crystal?
 

motion

New Member
As a precaution, initialize the PCLATH register to 0 at startup. The first "CALL DELAY" might send your program to a random location depending on the PCLATH's value.
 

janethnx

New Member
delay program

-hi? Is your delay program ok? I do need a delay program for my PIC16F84A project.

-tnx
 
Last edited:

janethnx

New Member
delay program

-Thank you for the link you have proposed. Gee.. I still have the difficulty in understanding it. My biggest problem is time. Though i'm eager to learn but i don't have so much time. And way back my Assembly Lesson, i'm not good in it. But I won't give up even if it kills me(joke).

-Thank you so much.
 

AllVol

New Member
-How did you made your circuit in delay program using PI16F84A? Honestly I don't know what to do. Poor me.
Hi.

Don't get discouraged. It's really very simple.

You see, your Pic is operating, if you're using a 4MHz crystal, at 1 millionth of a second per instruction. For example, if you instruct "bsf PORTB,0", a LED on that pin will light... for one-millionth of a second.

What you have to do is get it to stay on for, say, 500,000 millionths of a second.... a lot of big numbers that represent one-half second, which your eye can see.

A delay program does just that... repeats itself however many thousands of times you say until the desired time is reached.

There are several good delay programs on this site, plus there is a calculator available on the internet in which you simply fill in the time you want, and it gives the program back to you.

But the best way is to study why and how these programs work, so you can do it yourself when needed.
 

janethnx

New Member
-Thanks for the encouragement. I came across so many delay programs in this website, but the problem was me.... I don't know how to understand it quickly. My foundation in assembly is very weak. Right now I'm learning how it works but time is running and I don't know how to make things fast. Its my fault anyway. I didn't gave too much attention when the topic is being discussed.
-The delay program I have seen were running, thanks God but they're for minimal time delay. Say seconds. I needed a delay which a minimum of 5 minutes. I don't know its equivalent. That five minutes delay will operate our ac motor(washing machine motor for our grain dryer). It will drive the motor on for five mins and will turn off the motor for five mins too. The process continuous until the grain is dry.
-About the "calculator" you've told me I've seen it too but I didn't understand. (I'm the worst...)
 

eblc1388

Active Member
Hi.

Don't get discouraged. It's really very simple.

You see, your Pic is operating, if you're using a 4MHz crystal, at 1 millionth of a second per instruction. For example, if you instruct "bsf PORTB,0", a LED on that pin will light... for one-millionth of a second.

What you have to do is get it to stay on for, say, 500,000 millionths of a second.... a lot of big numbers that represent one-half second, which your eye can see.
This explanation is close but is not it really is.

After one sets a pin to a certain logic level, the level will stay there until it is deliberately changed by the software.

The clock frequency has nothing to do (yet) with how long it remains lit.

Although we can use repeated instructions to set pin to a certain logic level for certain time, we usually do it by another method(s). We set up the logic level, to turn ON the led and then have the PIC doing a certain times of "NOP" in a loop so that it is simply wasting time. The pin level will remain steady while the PIC is doing NOPs. Then we set the logic level to turn off the LED.

The clock frequency now comes into play because the faster the clock, the less time the loop will end. By using different frequency clocks, and using different values for loop counter, we can get the same delay regardless.

However, the best method is to use the timer resources inside the PIC so we don't end up wasting time in a loop.
 

janethnx

New Member
delay program

-I am not that familiar with NOP, but I came across with the word:confused::confused: through PIC16F84 tutorials in the web.
-Somehow I got your point (since I am not knowledgeable about asm and PIC). Thanks for the instructions. I'll try to follow the logic.


This explanation is close but is not it really is.

After one sets a pin to a certain logic level, the level will stay there until it is deliberately changed by the software.

The clock frequency has nothing to do (yet) with how long it remains lit.

Although we can use repeated instructions to set pin to a certain logic level for certain time, we usually do it by another method(s). We set up the logic level, to turn ON the led and then have the PIC doing a certain times of "NOP" in a loop so that it is simply wasting time. The pin level will remain steady while the PIC is doing NOPs. Then we set the logic level to turn off the LED.

The clock frequency now comes into play because the faster the clock, the less time the loop will end. By using different frequency clocks, and using different values for loop counter, we can get the same delay regardless.

However, the best method is to use the timer resources inside the PIC so we don't end up wasting time in a loop.
 

Nameless1

Member
Or....you can "cheat" and learn / use C?

:p
 
Last edited:

janethnx

New Member
- I have this delay program and its running. But have yet loaded int into a PIC..and had not seen the outcome. Kindly comment.. Its a bit weird...having to call the call delay a hundred times.
;**********************************************************************
; This file is a basic code template for assembly code generation *
; on the PIC16F84A. This file contains the basic code *
; building blocks to build upon. *
; *
; Refer to the MPASM User's Guide for additional information on *
; features of the assembler (Document DS33014). *
; *
; Refer to the respective PIC data sheet for additional *
; information on the instruction set. *
; *
;**********************************************************************
; *
; Filename: hehe.asm *
; Date: *
; File Version: *
; *
; Author: *
; Company: *
; *
; *
;**********************************************************************
; *
; Files Required: P16F84A.INC *
; *
;**********************************************************************
; *
; Notes: *
; *
;**********************************************************************


list p=16F84A ; list directive to define processor
#include <p16F84A.inc> ; processor specific variable definitions

__CONFIG _CP_OFF & _WDT_ON & _PWRTE_ON & _RC_OSC

; '__CONFIG' directive is used to embed configuration data within .asm file.
; The lables following the directive are located in the respective .inc file.
; See respective data sheet for additional information on configuration word.




;***** VARIABLE DEFINITIONS
w_temp EQU 0x0C ; variable used for context saving
status_temp EQU 0x0D ; variable used for context saving




del_0 equ 0x0d
del_1 equ 0x0e


;**********************************************************************
ORG 0x000 ; processor reset vector
goto main ; go to beginning of program


ORG 0x004 ; interrupt vector location
movwf w_temp ; save off current W register contents
movf STATUS,w ; move status register into W register
movwf status_temp ; save off contents of STATUS register


; isr code can go here or be located as a call subroutine elsewhere


movf status_temp,w ; retrieve copy of STATUS register
movwf STATUS ; restore pre-isr STATUS register contents
swapf w_temp,f
swapf w_temp,w ; restore pre-isr W register contents
retfie ; return from interrupt







main

movlw 0xff
tris porta
movlw 0x00
tris portb
clrf portb
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1

start
movlw b'00000001'
movwf portb

movlw b'00000000'
movwf portb
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
movlw b'00000001'
movwf portb
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
movlw b'00000000'
movwf portb
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
movlw b'00000001'
movwf portb
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
call delay1
movlw b'00000000'
movwf portb
call delay1
goto start

delay1

movlw 0xff
movwf del_0
loadan
movlw 0xff
movwf del_1
decn
decfsz del_1,f
goto decn
decfsz del_0,f
goto loadan
return


END ; directive 'end of program'
 

Gayan Soyza

Active Member
Why don't you use a single fix delay instead of calling 100 times??

Delay code generator will give you the required delay that u need.

Code:
Main	bsf	PORTB,0
	call	Del5M
	bcf	PORTB,0
	call	Del5M
	goto	Main
 
Last edited:

janethnx

New Member
delay program with may "call delay"

--I want to make a delay for five minutes and what i did is call delay several times... it runs.. yet i don't know if its for five minutes really I have not able to load it into PIC. But when I added a little more it didn't run.. was it because of PIC is limited? What if I want to make a delay longer that it seems? What should I do?
 
Status
Not open for further replies.

Latest threads

EE World Online Articles

Loading
Top