OK, brand new to any sort of programming. Got a PICkit 2. I am working with a lesson that came with it. All I need to do is adjust the delay time of the LED cycle. The program cycles through 8 LEDs (driving the outputs high), all LEDs have cycled in just over a second. I need to slow this down to 2-3 seconds for each LED. Here is the code:
#include <p16F887.inc>
__CONFIG _CONFIG1, _LVP_OFF & _FCMEN_OFF & _IESO_OFF & _BOR_OFF & _CPD_OFF & _CP_OFF & _MCLRE_OFF & _PWRTE_ON & _WDT_OFF & _INTRC_OSC_NOCLKOUT
__CONFIG _CONFIG2, _WRT_OFF & _BOR21V
cblock 0x20
Delay1 ; Assign an address to label Delay1
Delay2
Display ; define a variable to hold the display
endc
org 0
Start:
bsf STATUS,RP0 ; select Register Bank 1
clrf TRISD ; make IO PortD all output
bcf STATUS,RP0 ; back to Register Bank 0
movlw 0x80
movwf Display
MainLoop:
movf Display,w ; Copy the display to the LEDs
movwf PORTD
OndelayLoop:
decfsz Delay1,f ; Waste time.
goto OndelayLoop ; The Inner loop takes 3 instructions per loop * 256 loopss = 768 instructions
decfsz Delay2,f
goto OndelayLoop
bcf STATUS,C ; ensure the carry bit is clear
rrf Display,f ; rotate the display right
btfsc STATUS,C ; Did the bit rotate into the carry?
bsf Display,7 ; yes, put it into bit 7.
goto MainLoop
end
I tried adding a 3rd delay directly after:
decfsz Delay2,f
goto OndelayLoop
I added (also added to up top on the header code):
decfsz Delay3,f
goto OndelayLoop
Then the code continued where it left off. It worked. This slowed down the cycle to like a minute or two per each output. Way to slow.
I understand the concept pf the PIC processor speed, how many instructions it can process and/or how delay works with that, but I do not understand how to tweak a delay to a specific time. The way they had it set up in this lesson code, it looks like its a broad time jump. How can I enter in values to play with the delay time for this output cycle?
Any thoughts? Example code? Or can anyone help me modify this code so that I can understand it? Nothing to deep here, just want a logical explanation.
Thanks!
#include <p16F887.inc>
__CONFIG _CONFIG1, _LVP_OFF & _FCMEN_OFF & _IESO_OFF & _BOR_OFF & _CPD_OFF & _CP_OFF & _MCLRE_OFF & _PWRTE_ON & _WDT_OFF & _INTRC_OSC_NOCLKOUT
__CONFIG _CONFIG2, _WRT_OFF & _BOR21V
cblock 0x20
Delay1 ; Assign an address to label Delay1
Delay2
Display ; define a variable to hold the display
endc
org 0
Start:
bsf STATUS,RP0 ; select Register Bank 1
clrf TRISD ; make IO PortD all output
bcf STATUS,RP0 ; back to Register Bank 0
movlw 0x80
movwf Display
MainLoop:
movf Display,w ; Copy the display to the LEDs
movwf PORTD
OndelayLoop:
decfsz Delay1,f ; Waste time.
goto OndelayLoop ; The Inner loop takes 3 instructions per loop * 256 loopss = 768 instructions
decfsz Delay2,f
goto OndelayLoop
bcf STATUS,C ; ensure the carry bit is clear
rrf Display,f ; rotate the display right
btfsc STATUS,C ; Did the bit rotate into the carry?
bsf Display,7 ; yes, put it into bit 7.
goto MainLoop
end
I tried adding a 3rd delay directly after:
decfsz Delay2,f
goto OndelayLoop
I added (also added to up top on the header code):
decfsz Delay3,f
goto OndelayLoop
Then the code continued where it left off. It worked. This slowed down the cycle to like a minute or two per each output. Way to slow.
I understand the concept pf the PIC processor speed, how many instructions it can process and/or how delay works with that, but I do not understand how to tweak a delay to a specific time. The way they had it set up in this lesson code, it looks like its a broad time jump. How can I enter in values to play with the delay time for this output cycle?
Any thoughts? Example code? Or can anyone help me modify this code so that I can understand it? Nothing to deep here, just want a logical explanation.
Thanks!
Last edited: