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.

PIC16F84A simple delay probs?

Status
Not open for further replies.

rob.m0gkg

New Member
Hi guys and girls - a newbie here.

Just got into PIC programming to fulfill the needs of a few small projects im working on.

Here I am trying to get a PIC to continuously switch an LED on for 20secs, and then off for 20secs...

I am having a few problems with the delay loop. It seems to work when the interval is 1sec (i.e. 1sec on, 1 sec off) - but when the variables (d1, d2, d3) within the loop are changed to give 20sec, my LED just comes on and stays on?

Prehaps im going the wrong way about things or i've made a newbie error...

Anyone have any ideas?

Here is the code:

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

main

STATUS equ h'03'
TRISA equ h'85'
PORTA equ h'05'

BSF STATUS,5
MOVLW h'00'
MOVWF TRISA
BCF STATUS,5​


Start
Call LEDOn
Call Delay1

Call LEDOff
Call Delay1

goto Start​


LEDOn
MOVLW h'1f'
MOVWF PORTA
return​


LEDOff
MOVLW h'00'
MOVWF PORTA
return​


;*****Delay1 - SUB*****
cblock 0x0C
d1
d2
d3
endc​

Delay1
movlw 0x07
movwf d1
movlw 0x2F
movwf d2
movlw 0x03
movwf d3​
Delay1_0
decfsz d1, f
goto $+2
decfsz d2, f
goto $+2
decfsz d3, f
goto Delay1_0

goto $+1
goto $+1
goto $+1

return​

END

Thanks in advance for help...

Rob
 
Thanks guys - all working now...

Switched the watchdog timer off and all seems fine - I knew from my Delphi experience it would be something simple.

Cheers

Rob
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top