PDA

View Full Version : Help with some maths in assembly



Megahertz
- 30th March 2012, 20:02
Hi, I have this code which I am simulating using Proteus. I am running the PIC @ 4MHz so every instruction is 1uS.
Now my code runs a delay routine 0-255 then inside that routine another routine runs 0-255. Total delay should be 255 x 255 = 65025 mS. But the delay is somewhere between 180-200mS region. Can someone explain why this is happening please? Thanks

PAGE0
CLRF PORTD
CLRF PORTB
PAGE1
CLRF TRISD
CLRF TRISB
PAGE0
MOVLW 0
MOVWF COUNT1
MOVWF COUNT2
MOVWF COUNT3
MOVWF COUNT4


MAIN
BSF RSET
CALL DELAY250
BCF RSET
CALL DELAY250
MOVWF COUNT1
MOVWF COUNT2
GOTO MAIN


DELAY250
CALL DELAY500
INCFSZ COUNT1,f
GOTO DELAY250
BCF STATUS,Z
RETURN
DELAY500
INCFSZ COUNT2,f
GOTO DELAY500
BCF STATUS,Z
RETURN


END

mister_e
- 1st April 2012, 11:38
Start a new ASM project within MPLAB and run MPSIM... see what happen step by step..... then discover WHY it happen. I think you could also do it in Proteus...

Checkout the Piclist as well
http://www.piclist.com/techref/piclist/codegen/delay.htm