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.

dspic asm sample codes

Status
Not open for further replies.

poppy2008

New Member
hi
i found dspic33fj256gp710 sample codes in assembly,from microchip,
hope will be useful ,turn on led ,with 5 sec delay

Code:
 ******************************************************************************


        .equ __33FJ256GP710, 1
        .include "p33FJ256GP710.inc"

;..............................................................................
;Configuration bits: We will use the MPLAB menu to configure the bits
;..............................................................................

;..............................................................................
;Program Specific Constants (literals used in code)
;..............................................................................

        .equ SAMPLES, 64         ;Number of samples


;..............................................................................
;Global Declarations:
;..............................................................................

        .global _wreg_init       ;Provide global scope to _wreg_init routine
                                 ;In order to call this routine from a C file,
                                 ;place "wreg_init" in an "extern" declaration
                                 ;in the C file.

        .global __reset          ;The label for the first line of code. 

        .global __T1Interrupt    ;Declare Timer 1 ISR name global



;..............................................................................
;Constants stored in Program space
;..............................................................................

        .section .myconstbuffer, code
        .palign 2                ;Align next word stored in Program space to an
                                 ;address that is a multiple of 2
ps_coeff:
        .hword   0x0002, 0x0003, 0x0005, 0x000A




;..............................................................................
;Uninitialized variables in X-space in data memory
;..............................................................................

         .section .xbss, bss, xmemory
x_input: .space 2*SAMPLES        ;Allocating space (in bytes) to variable.


;..............................................................................
;Uninitialized variables in Y-space in data memory
;..............................................................................

          .section .ybss, bss, ymemory
y_input:  .space 2*SAMPLES



;..............................................................................
;Uninitialized variables in Near data memory (Lower 8Kb of RAM)
;..............................................................................

          .section .nbss, bss, near
var1:     .space 2               ;Example of allocating 1 word of space for
                                 ;variable "var1".



;..............................................................................
;Code Section in Program Memory
;..............................................................................

.text                             ;Start of Code section
__reset:
; First initialize the stack pointer and the Stack pointer limit
        MOV #__SP_init, W15       ;Initalize the Stack Pointer
        MOV #__SPLIM_init, W0     ;Initialize the Stack Pointer Limit Register
        MOV W0, SPLIM
        NOP                       ;Add NOP to follow SPLIM initialization
        
;Next write code to setup the FRC clock to be divided by 256
;7.37 Mhz is thus reduced to 14.3Khz or Tcy = 70 us.  
		bset	CLKDIV,#10
		bset	CLKDIV,#9
		bset 	CLKDIV,#8

;********************************************************************************
;Next we set PORT A to be a output port
		bclr		TRISA,#0
;********************************************************************************
; Then light up the LED connected to PORTA bit 0

Again:
		bset 	PORTA,#0
; Add the delay for 0.5 seconds
		repeat 	#7142
		nop
		bclr 	PORTA,#0
		repeat	#7142
		nop
		bra		Again

; Add code to turn off the LED connected to PORTA bit 0


; Copy code written above to delay for 0.5 seconds


; write code to Repeat Loop

done:
        BRA     done              ;Place holder for last line of executed code


;..............................................................................
;Timer 1 Interrupt Service Routine
;Example context save/restore in the ISR performed using PUSH.D/POP.D
;instruction. The instruction pushes two words W4 and W5 on to the stack on
;entry into ISR and pops the two words back into W4 and W5 on exit from the ISR
;..............................................................................

__T1Interrupt:
        PUSH.D W4                  ;Save context using double-word PUSH

        ;<<insert more user code here>>

        BCLR IFS0, #T1IF           ;Clear the Timer1 Interrupt flag Status
                                   ;bit.

        POP.D W4                   ;Retrieve context POP-ping from Stack
        RETFIE                     ;Return from Interrupt Service routine



;--------End of All Code Sections ---------------------------------------------

.end                               ;End of program code in this file
 
Last edited:
Hi poppy2008, where did you find this example code? I'm getting started with the dsPIC33FJ256GP710 and i need template files in ASM because i dont have a C compiler. All template i've found in Micrchip page are written in C language.

Can you help me?

Thanks.
 
Status
Not open for further replies.

Latest threads

Back
Top