Searching \ for '[PIC]: problems with delays (long newbie posting)' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page:
Search entire site for: 'problems with delays (long newbie posting)'.

Exact match. Not showing close matches.
PICList Thread
'[PIC]: problems with delays (long newbie posting)'
2002\08\05@070329 by Russell McMahon

                                   Tag corrected. Original message from
Jumanji follows

----- Original Message -----
From: "jumanji" <spam_OUTjumanjiTakeThisOuTspamPANDORA.BE>

Hello everybody,

My first post if it works (tried one before but it didn't)
Ok, here we go,
I just got into PICs (with very very limited electronic background tbh, but
I've soldered a LED before so to say) & my programming skills are .. well I
had some basic,pascal,c but so long ago that it is all neglectable.

It took me a while to gather enough info & tools to get started, but now I
have gotten  a few programs running.
Finding its features the most appealing compared to other boards I have been
looking at, I
went for the LAB-X1 experimenter board (PIC16F877-20/P included) together
the EPIC programmer. I didn't want to spend much time on putting together
circuits myself to get to learn programming PICs. I also didn't get the
compiler though. After a while I think I'll be using some C package (still
have to investigate which) to  program them, but at the moment I'm
experimenting with MPASM, I never looked into assembly language before, but
I find it quite interesting, maybe I'll just stick to it after all.
The hardware seems to work ok, it took me a while to get it running, but now
the included test hexfiles load & execute just fine (it seems to me, anyway)
and -more important- I have gotten a few programs working on it.
But... unfortunately (but to be expected), this success didn't last for

I'm trying to control some LEDs (what else :), with the aid of online
examples, like the ones on piclist (great resource btw)
The 'lite-a-led' eperiment was a great success.
The 'flash-a-led' gave me some problems, I found a 'nested-loop'-delay that
I used but somehow it didn't work right. The LED's either were on or off, no
action at all. It was actually a PIC16F84 example & I thought it might have
something todo with that. I messed a bit with the code without knowing what
I was doing (moved the positions of call delay & clear carry flag around
etc), but didn't get anything to work & so I gave up.
The 'move-a-led' also didnt work properly, it uses a similar delay.
I went looking for other delay methods & I found this great 'delay
generator' on the piclist, so I guess the code just had to be correct.
Meanwhile I got to know MPLAB a bit better & yes, the debugger shows that 1
bit of PORTD 'moves'

The experiment is done on a 10 LED bargraph, but 8 r used. The idea is that
1 lit LED 'moves' from position 1 to 8 & repeats (with RLF PORTD or RRF
PORTD) but, it doesn't do that, I get all kind of strange things, like it
moves 1-4 & then resets. When I fill in other delay times I get different
effects, like a skipping a few positions.
Then I used a 0.25sec generated code & to my amazement it works perfect.

I kept this one & extend the program with a BTFSS instruction on the last
bit of PORTD to make it go down again.
But.... it doesn't, it just toggles between position 1 & 8, other delay
values make it just stick on position 1, or skip a few places on the way
I have replaced the delay code with a NOP &  watched PORTD with the
debugger, it seems to work perfect, 1 bit moves from pos1 to pos8 & back.

So I think I should find the problems somewhere else, but I don't
knowwhereto look.
Possible issues I could think of myself to check:
*All ports are configured as output & set Low, delivered clock is 4MHz
(jumper setting)
*Power supply shud be sufficient (using 2warts, 1 for the expboard
15VDC/500mA & 1 for the programmer12VDC/800mA)
*The programmer stays connected & powered while executing the program on the
expboard, I have tried without it on working & nonworking programs, it never
changed anything.
*the LEDs share the PORTD with the LCD controller, but the documentation
says it is to be ignored.
* Maybe it has something todo with 'jitter', I found some thing on
but this gets ways too technical for me.

I would like to ask if there is anybody out there who could point me out wat
todo next? Maybe someppl have similar hardware (&similar problems?)

Further I would like to know, these flashPICs like 877, can they be
reprogrammed a certain limited amount of times, or are they forever
reprogrammable ?

Oh, & did anybody ever order anything from epemag in uk ? I did, I got some
obscure java-order routine inside a webpage.The order was confirmed on the
webpage, but I didn't get any email confirmation, not even after I mailed
them again to ask for it. Epemag doesn't seem very trustworthy to me, are
they to be avoided or has anybody had good experiences with them ?

thanks a bunch in advance & sorry for the long post
best regards

-- hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

-- hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

2002\08\05@161335 by jumanji

Hi, thanks for the answer, I think I understand, is it the CBLOCK 0x20 <----
that you mean?
I didn't put it inthere until today, but it still don't work. (mebbe I have
put it in the wrong place?)

>From: "Jinx" <.....joecolquittKILLspamspam@spam@CLEAR.NET.NZ>
> Could be - RAM starts at 0x0c in the F84 and at 0x20 in the F877.
> Assuming the delay used RAM counters and the addresses weren't
> corrected............

> Post the listing for the bit(s) giving you trouble, probably easily fixed.
> Make sure to include any references to memory, variable and port
> declarations, the problem may not be where you think it is. Curiously
> though, it is always in the last place you look

Hmm.. after I have found something, I usually stop searching, so the place
where I found it is automatically the last place where I have looked ;-)
I will paste my whole prog inhere, its just a mix from bits & parts found on
When I compile this source, it results in a semi-success, the LED moves from
pos1 to pos8, then goes to pos7, quickly to pos6 & then jumps to pos1 &
starts over again.

; This is an experimental program, bits & parts are used from examples found
on WWW.
       Title "LED flasher."
       list P = 16F877
       include ""  ; use definition file for 16F877
       org 0x0000      ; start address = 0000h

; binary used to see individual pin level

       movlw b'00000000'       ; all port pins = low
       movwf PORTA
       movlw b'00000000'
       movwf PORTB
       movlw b'00000000'
       movwf PORTC
       movlw b'00000000'
       movwf PORTD
       movlw b'00000000'
       movwf PORTE

       bsf STATUS,RP0   ; set RAM Page 1 for TRIS registers

; binary used to see individual pin IO status

       movlw b'00000000'       ; all IO pins = outputs
       movwf TRISA
       movlw b'00000000'
       movwf TRISB
       movlw b'00000000'
       movwf TRISC
       movlw b'00000000'
       movwf TRISD
       movlw b'00000000'
       movwf TRISE

       movlw b'00000110'       ; all analog pins = digital
       movwf ADCON1

       bcf STATUS,RP0   ;back to RAM page 0

litLED  BCF STATUS,0  ;Clear the carry flag
MOVLW b'00000001'  ;put value in W
CALL Delay
run RLF PORTD,1  ;Shift the HIGH up the column
CALL Delay
BTFSS PORTD,7         ;Has it reached the top? (check bit 7 of PORTD)
GOTO run  ; if no(0), goto run (if 1 skip 'goto run' performs nop)
runback RRF PORTD,1            ;YES. Shift the HIGH down
       CALL Delay
       BTFSS PORTD,0     ;Has it reached the bottom?
       GOTO runback   ;if no, goto runback
       GOTO run    ;YES. Repeat the cycle


; Delay = 0.25 seconds
; Clock frequency = 4 MHz

; Actual delay = 0.25 seconds = 250000 cycles
; Error = 0 %

cblock 0x20 ;I have added the 0x20 myself

  ;249993 cycles
movlw 0x4E
movwf d1
movlw 0xC4
movwf d2
decfsz d1, f
goto $+2
decfsz d2, f
goto Delay_0

  ;3 cycles
goto $+1

  ;4 cycles (including call)



Thanks again for your help,
Best regards.

PS: this Re: was a re on [PIC] without the colon, dunno if it would matter,
but I put one inthere now, just to be sure.

-- hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

2002\08\05@173821 by sbryden

Sounds like your getting bitten by the watchdog. It has a default delay of
2.3s which at 0.25 seconds per led would get you all the way to the end and
one and a bit back before the chip resets and starts again from the beginning.

You need to disable it, either in the source file or via the programmer.


On Mon, Aug 05, 2002 at 10:12:03PM +0200, jumanji wrote:
{Quote hidden}

-- hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

2002\08\05@182054 by Jinx

face picon face
> > run RLF PORTD,1  ;Shift the HIGH up the column

Modifying the port directly *may* get you in trouble. There's been
quite some discussion on read-modify-write of port latches

It's better practice to use a shadow register and use that. Don't
read the port, but instead just write the shadow to the port, eg

movlw  0x01         ;initialise shadow
movwf  shadow
movf   shadow,w  ;write it to port
movwf  portd
call delay

bcf  status,carry    ;rlf will move the carry flag into bit0 of shadow
rlf  shadow,f           ;modify shadow

movf  shadow,w
movwf portd           ;write it to port
call delay

btfss   shadow,7   ;test for end


-- hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

2002\08\05@184348 by jumanji

thanks again for your answer, I just experimented with WDT, it seems it has
got todo something with that, (see my prev post). However, I will certainly
keep this technique in mind for my final project (I don't know what it's
gonna be, but its gotta be something with LEDs coz I just lov um :)

Best regards!

{Original Message removed}

More... (looser matching)
- Last day of these posts
- In 2002 , 2003 only
- Today
- New search...