delay assembly code for dspic30f6014a chip

Status
Not open for further replies.

jeffrey soe

New Member
i want to write a program that can light up the LED and after 0.5sec, the LED will off itself.

so i need a delay program program, can anyone help me?

below is part of my programusing dspic30f5014a and dspicdem 1.1 plus development board)

_Init_PortD9:

;clr LATD ;clear all port D latches to 0

bclr LATD, #LATD1 ;set selected latches 1 to 0
bclr LATD, #LATD2 ;set selected latches 2 to 0
bclr LATD, #LATD3 ;set selected latches 3 to 0
bclr LATD, #LATD4 ;set selected latches 4 to 0
bclr LATD, #LATD5 ;set selected latches 5 to 0
bclr LATD, #LATD6 ;set selected latches 6 to 0
bclr LATD, #LATD7 ;set selected latches 7 to 0
bclr LATD, #LATD8 ;set selected latches 8 to 0
bset LATD, #LATD9 ;set selected latches 9 to 1
call Delay

return ;return to calling routine

Delay:

How to continue with the delay code??/
 
why assembler for dsPIC ... that is so much waste of time

What is the speed of your pic?

here's the 0.5sec delay routine if you are running it on 20MHz:
Code:
; Time Delay = 0.49999620s  with  Osc = 20.00000000MHz

delay_0.5_sec
	movlw	D'13'
	movwf	CounterC
delay_0.5_sec_loop
	call	sub_delay_0.5_sec
	decfsz	CounterC,1
	goto	delay_0.5_sec_loop
	return

sub_delay_0.5_sec
	movlw	D'250'
	movwf	CounterB
	movlw	D'188'
	movwf	CounterA
sub_delay_0.5_sec_loop
	decfsz	CounterA,1
	goto	sub_delay_0.5_sec_loop
	decfsz	CounterB,1
	goto	sub_delay_0.5_sec_loop
	return


same thing for 40MHz
Code:
; Time Delay = 0.49999590s  with  Osc = 40.00000000MHz

delay_0.5_sec
	movlw	D'26'
	movwf	CounterC
delay_0.5_sec_loop
	call	sub_delay_0.5_sec
	decfsz	CounterC,1
	goto	delay_0.5_sec_loop
	return

sub_delay_0.5_sec
	movlw	D'250'
	movwf	CounterB
	movlw	D'188'
	movwf	CounterA
sub_delay_0.5_sec_loop
	decfsz	CounterA,1
	goto	sub_delay_0.5_sec_loop
	decfsz	CounterB,1
	goto	sub_delay_0.5_sec_loop
	return

or if you are maybe going 8MHz ??
Code:
; Time Delay = 0.49998750s  with  Osc = 8.00000000MHz

delay_0.5_sec
	movlw	D'6'
	movwf	CounterC
delay_0.5_sec_loop
	call	sub_delay_0.5_sec
	decfsz	CounterC,1
	goto	delay_0.5_sec_loop
	return

sub_delay_0.5_sec
	movlw	D'217'
	movwf	CounterB
	movlw	D'110'
	movwf	CounterA
sub_delay_0.5_sec_loop
	decfsz	CounterA,1
	goto	sub_delay_0.5_sec_loop
	decfsz	CounterB,1
	goto	sub_delay_0.5_sec_loop
	return

The code is generated by PikLoops. Donno if that app exist for operating system that you use PiKLoops Home Page
 
thanks for reply me.

i am using the mplab C30 language to write the program, and i have try to use the code provided, it seem like not work.

do you have any others code?
 
Are you writing the code in assembler or in C (C30 is a C compiler, not assembler)?!?!

What is the speed of your uC?

If you are using C (you just wrote that you use C30) then you just need to use included function:

Code:
//...
//you have to specify the speed your uC is running
//8MHz
#define FCY 8000000UL

//include the definition for __delay_ms()
#include <libpic30.h>

int main(){
...
__delay_ms(500); //half second delay
...
}
 
i am using C30compiler and the code is wrote in assembly.

Besides that, i am using dspicdem 1.1 plus development board and the ICD2 programmer.
 
because i am modified the demo code provided by microchip. the source code are wrote in C and assembly. Here i attach the file for you to have a look, hope you can help me solve the problem.

and please open the SR_calculator_init.s file, my delay is write on that page at the last part.

Hope can hear your good news soon.thank you
 

Attachments

  • code.zip
    46.6 KB · Views: 203
sorry mate, I'm ignoring the asm as much as I can ... explained why already...

anyhow, you can use the __delay32(unsigned long) routine from asm too. The delay_ms would be __delay32(no_milliseconds * FCY / 1000) ..
 
Last edited:
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…