Pic24 xc16 és asm

Ennek alapján: http://ww1.microchip.com/downloads/en/DeviceDoc/70000157g.pdf 

Ezeket gyakoroljam be:

Ez a legfontosabb tutorial: http://ww1.microchip.com/downloads/en/DeviceDoc/70157C.pdf 

Egy asm tutorial:  https://www.tutorialspoint.com/assembly_programming/assembly_basic_syntax.htm 

Profi:  https://www.youtube.com/watch?v=F_10OjOo0IY  

Pic18-ra de porofi és összetett az egész. Több részes:
Sok videója van: https://www.youtube.com/channel/UCTvz7nXxTc7lfBDLUkaufyA/videos  
Telepítés: https://www.youtube.com/watch?v=KSI6fzOPVz0  
Egy Pic18-as programírási beállítás:  https://www.youtube.com/watch?v=OQ6hZzkvXMw 
  https://www.youtube.com/watch?v=nMSdSYsSMy0&t=315s 
5. megszakítások: https://www.youtube.com/watch?v=MiPxVmj_nHI&list=PLtuqBdbsL-DtSo1a9pS4sLkoaU3Or2pl3&index=5 

Egyszerű talán kezdésnek: https://www.youtube.com/watch?v=nMSdSYsSMy0&t=315s  

egy honlap  :  https://sites.google.com/site/pic24micro/ 

ASM program megnézésre és tanulásra : https://www.youtube.com/watch?v=gT7_01OeVcM 

 

Tanolni több részes: https://www.hobbielektronika.hu/cikkek/pic_programozas_c_nyelven_-_ccs_-_i_lecke.html  
 https://www.hobbielektronika.hu/cikkek/pic_programozas_c_nyelven_-_ccs_-_i_lecke.html?pg=2  

Lehet belőle tanulni HU :  http://megtestesules.info/hobbielektronika/2017/vtalk06.pdf 

Ebből is: https://www.hobbielektronika.hu/forum/pic-programozasa-c-nyelven-c-compiler?pg=92  

 http://www.mogi.bme.hu/letoltes/ALKALMAZOTT%20INFORMATIKAI%20T%C3%81RGYAK/Mikrovezerlok%20alkalmazasa/Gyakorlatok/uMOGI/Seg%C3%A9dletek/Lab_bevez.pdf  

Általásos "C" magyarul: 
Sorozat:  https://infoc.eet.bme.hu/ea03/   
Sorozat:  http://nimbus.elte.hu/~lagzi/C_nyelv/6/6_ora.pdf  
 https://www.tankonyvtar.hu/hu/tartalom/tamop425/0046_c_peldatar/ch06.html   

Künyv: http://titan.physx.u-szeged.hu/~pierre/C_programozas.pdf  
 

 http://calmarius.net/?lang=hu&page=programming%2Fc_crash_course#passing_pointers_as_arguements  

 https://tudasbazis.sulinet.hu/hu/informatika/informatika/informatika-9-12-evfolyam/algoritmizalas-adatmodellezes-programozoi-ismeretek/programozas-a-c-nyelven  
 https://hu.wikipedia.org/wiki/C_(programoz%C3%A1si_nyelv)  

------------ xc16 ------------------------------------------

 https://www.hobbielektronika.hu/forum/pic-programozasa-c-nyelven-c-compiler?pg=92  

 

 

 

;--------------------------- ASM ---------------------------------------------

Doksi:  http://ww1.microchip.com/downloads/en/DeviceDoc/70157D.pdf 

Könyv Pic24 C nyelven: http://www.tech-software.net/temp/twenty.pdf  

Ezt nézzem:   https://www.youtube.com/watch?v=nMSdSYsSMy0 

Már nincs ASM30 (MPLAB X IDE v.3.51) még tartalmazza: https://microchipdeveloper.com/mplabx:work-outside-create-makefiles-asm30   

Ez működik:

/* 
 * File:   Proba__1.c
 * Author: Programozas
 *
 * Created on 2019. december 1., 23:37
 */
#include "xc.h"
#include <stdio.h>
#include <stdlib.h>

/*
 * 
 */
int main(int argc, char** argv) {
   
  //  asm("mov cVariable, WREG"); 
    asm (
    "mov #20 , W1 "
    
    
       );

     EDDIG

 

 

 


;    C:\> pic30-as file.s -p24FJ256GA702
;    2. Placing a ".equ" directive before the ".include":
;    .equ __24FJ256GA702, 1
    .include "p24FJ256GA702.inc"
    
    
reset_vekt   code  0x0 ;
  mbv
  nop
  nop
    
    
    end


Inc fájlok elérhetősége:
c:\Program Files (x86)\Microchip\xc16\v1.35\support\PIC24F\inc\


;------------------------------------------------------------------------------ 
; 
; Product:			ds30 loader 
; 
; File description:	device constants for PIC24F 
; 
; Copyright: 		Copyright 2009-2011 Mikael Gustafsson 
;                                           
;------------------------------------------------------------------------------ 
 
;----------------------------------------------------------------------------- 
;    This file is part of ds30 Loader. 
; 
;    ds30 Loader is free software: you can redistribute it and/or modify 
;    it under the terms of the GNU General Public License as published by 
;    the Free Software Foundation. 
; 
;    ds30 Loader is distributed in the hope that it will be useful, 
;    but WITHOUT ANY WARRANTY; without even the implied warranty of 
;    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
;    GNU General Public License for more details. 
; 
;    You should have received a copy of the GNU General Public License 
;    along with ds30 Loader. If not, see <http:;www.gnu.org/licenses/>. 
;------------------------------------------------------------------------------ 
.ifdef	__24F16KA301 
	.include	"p24F16KA301.inc" 
	.equiv		IS_24F,			1 
	.equiv		VALID_DEV,		1 
	.equiv		FLASHSIZE,		0x2C00 
	.equiv		RAM_START,		0x800 
	.equiv		RAM_SIZEB,		2048 
	.equiv		DEVICEID,		29 
	.equiv		EESIZEB,		512 
	.equiv		HAS_UART2,		1 
.endif 
.ifdef	__24F32KA301 
	.include	"p24F32KA301.inc" 
	.equiv		IS_24F,			1 
	.equiv		VALID_DEV,		1 
	.equiv		FLASHSIZE,		0X5800 
	.equiv		RAM_START,		0x800 
	.equiv		RAM_SIZEB,		2048 
	.equiv		DEVICEID,		35 
	.equiv		EESIZEB,		512 
	.equiv		HAS_UART2,		1 
.endif 
.ifdef	__24F16KA302 
	.include	"p24F16KA302.inc" 
	.equiv		IS_24F,			1 
	.equiv		VALID_DEV,		1 
	.equiv		FLASHSIZE,		0x2C00 
	.equiv		RAM_START,		0x800 
	.equiv		RAM_SIZEB,		2048 
	.equiv		DEVICEID,		36 
	.equiv		EESIZEB,		512 
	.equiv		HAS_UART2,		1 
.endif 
.ifdef	__24F32KA302 
	.include	"p24F32KA302.inc" 
	.equiv		IS_24F,			1 
	.equiv		VALID_DEV,		1 
	.equiv		FLASHSIZE,		0X5800 
	.equiv		RAM_START,		0x800 
	.equiv		RAM_SIZEB,		2048 
	.equiv		DEVICEID,		37 
	.equiv		EESIZEB,		512 
	.equiv		HAS_UART2,		1 
.endif 
.ifdef	__24F16KA304 
	.include	"p24F16KA304.inc" 
	.equiv		IS_24F,			1 
	.equiv		VALID_DEV,		1 
	.equiv		FLASHSIZE,		0x2C00 
	.equiv		RAM_START,		0x800 
	.equiv		RAM_SIZEB,		2048 
	.equiv		DEVICEID,		38 
	.equiv		EESIZEB,		512 
	.equiv		HAS_UART2,		1 
.endif 
.ifdef	__24F32KA304 
	.include	"p24F32KA304.inc" 
	.equiv		IS_24F,			1 
	.equiv		VALID_DEV,		1 
	.equiv		FLASHSIZE,		0X5800 
	.equiv		RAM_START,		0x800 
	.equiv		RAM_SIZEB,		2048 
	.equiv		DEVICEID,		39 
	.equiv		EESIZEB,		512 
	.equiv		HAS_UART2,		1 
.endif 
.ifdef	__24F04KA200 
	.include	"p24F04KA200.inc" 
	.equiv		IS_24F,			1 
	.equiv		VALID_DEV,		1 
	.equiv		FLASHSIZE,		0xB00 
	.equiv		RAM_START,		0x800 
	.equiv		RAM_SIZEB,		512 
	.equiv		DEVICEID,		200 
	.equiv		EESIZEB,		0 
.endif 
.ifdef	__24F04KA201 
	.include	"p24F04KA201.inc" 
	.equiv		IS_24F,			1 
	.equiv		VALID_DEV,		1 
	.equiv		FLASHSIZE,		0x0B00 
	.equiv		RAM_START,		0x800 
	.equiv		RAM_SIZEB,		512 
	.equiv		DEVICEID,		201 
	.equiv		EESIZEB,		0 
.endif 
.ifdef	__24F08KA101 
	.include	"p24F08KA101.inc" 
	.equiv		IS_24F,			1 
	.equiv		VALID_DEV,		1 
	.equiv		FLASHSIZE,		0x1600 
	.equiv		RAM_START,		0x800 
	.equiv		RAM_SIZEB,		1536 
	.equiv		DEVICEID,		202 
	.equiv		EESIZEB,		512 
	.equiv		HAS_UART2,		1 
.endif 
.ifdef	__24F08KA102 
	.include	"p24F08KA102.inc" 
	.equiv		IS_24F,			1 
	.equiv		VALID_DEV,		1 
	.equiv		FLASHSIZE,		0x1600 
	.equiv		RAM_START,		0x800 
	.equiv		RAM_SIZEB,		1536 
	.equiv		DEVICEID,		203 
	.equiv		EESIZEB,		512 
	.equiv		HAS_UART2,		1 
.endif 
.ifdef	__24F16KA101 
	.include	"p24F16KA101.inc" 
	.equiv		IS_24F,			1 
	.equiv		VALID_DEV,		1 
	.equiv		FLASHSIZE,		0x2C00 
	.equiv		RAM_START,		0x800 
	.equiv		RAM_SIZEB,		1536 
	.equiv		DEVICEID,		204 
	.equiv		EESIZEB,		512 
	.equiv		HAS_UART2,		1 
.endif 
.ifdef	__24F16KA102 
	.include	"p24F16KA102.inc" 
	.equiv		IS_24F,			1 
	.equiv		VALID_DEV,		1 
	.equiv		FLASHSIZE,		0x2C00 
	.equiv		RAM_START,		0x800 
	.equiv		RAM_SIZEB,		1536 
	.equiv		DEVICEID,		205 
	.equiv		EESIZEB,		512 
	.equiv		HAS_UART2,		1 
.endif 

 

;                                           
;------------------------------------------------------------------------------ 
 
;----------------------------------------------------------------------------- 
;    This file is part of ds30 Loader. 
; 
;    ds30 Loader is free software: you can redistribute it and/or modify 
;    it under the terms of the GNU General Public License as published by 
;    the Free Software Foundation. 
; 
;    ds30 Loader is distributed in the hope that it will be useful, 
;    but WITHOUT ANY WARRANTY; without even the implied warranty of 
;    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
;    GNU General Public License for more details. 
; 
;    You should have received a copy of the GNU General Public License 
;    along with ds30 Loader. If not, see <http://www.gnu.org/licenses/>. 
;------------------------------------------------------------------------------ 
 
 
;------------------------------------------------------------------------------ 
; Register usage 
;------------------------------------------------------------------------------ 
		;.equiv	MIXED,		W0		;immediate 
		;.equiv	MIXED,		W1		;immediate 
		.equiv	WBUFPTR,	W2		;buffer pointer 
		.equiv	WCNT,		W3		;loop counter 
		.equiv	WADDR2,		W4		;memory pointer 
		.equiv	WADDR,		W5		;memory pointer 
		.equiv	WPPSTEMP1,	W6		;used to restore pps register 
		.equiv	WPPSTEMP2,	W7		;used to restore pps register 
		.equiv	WTEMP1,		W8		; 
		.equiv	WTEMP2,		W9		; 
		.equiv	WDEL1,		W10		;delay outer 
		.equiv	WDEL2,		W11		;delay inner 
		.equiv	WDOERASE,	W12		;flag indicated erase should be done before next write 
		.equiv	WCMD,		W13		;command 
		.equiv 	WCRC, 		W14		;checksum 
		.equiv	WSTPTR,		W15		;stack pointer 
 
 
;------------------------------------------------------------------------------ 
; Includes 
;------------------------------------------------------------------------------ 
		.include "settings.inc"	 
		.include "user_code.inc" 
 
 
;------------------------------------------------------------------------------ 
; Defines 
;------------------------------------------------------------------------------			 
		.equiv	VERMAJ,			4						/*firmware version major*/ 
		.equiv	VERMIN,			0						/*fimrware version minor*/ 
		.equiv	VERREV,			3						/*firmware version revision*/ 
 
		.equiv 	HELLO, 			0xC1		 
		.equiv 	OK, 			'K'						/*erase/write ok*/ 
		.equiv 	CHECKSUMERR,	'N'						/*checksum error*/ 
		.equiv	VERFAIL,		'V'						/*verification failed*/ 
		.equiv  BLPROT,     	'P'                     /*bl protection tripped*/		 
		.equiv  UCMD,     		'U'                     /*unknown command*/		 
		 
		.equiv	PWOK,			0xFE	 
 
		.equiv	BLSTART,		( BLINIT * (FCY / 1000) / (65536 * 7) )				/*count for boot receive delay*/ 
		.equiv	BLDELAY,		( BLTIME * (FCY / 1000) / (65536 * 7) )				/*count for receive delay*/ 
			 
		.equiv	STARTADDR,		( FLASHSIZE - BLPLP * PAGESIZER * ROWSIZEW * 2 )	/*bootloader placement*/		 
		.equiv	BLSTARTROW,		(STARTADDR / ROWSIZEW / 2)	 
		.equiv	BLENDROW,		(STARTADDR / ROWSIZEW / 2 + (BLSIZEP*PAGESIZER) - 1)			 
 
 
;------------------------------------------------------------------------------ 
; Variables 
;------------------------------------------------------------------------------ 
		.equiv	BUFFERSIZE,		(ROWSIZEW*3 + 8/*MAC*/ + 1/*checksum*/) 
		.bss	_buffer, BUFFERSIZE, 8		 
		 
 
;------------------------------------------------------------------------------ 
; Globals 
;------------------------------------------------------------------------------ 
        .global _buffer 
 
 
;------------------------------------------------------------------------------ 
; Send macro 
;------------------------------------------------------------------------------ 
		.macro SendL char 
			mov		#\char, W0 
			rcall 	Send 
		.endm 
		 
 
;------------------------------------------------------------------------------ 
; Reset vector 
;------------------------------------------------------------------------------ 
        .global __reset 
				 
 
;------------------------------------------------------------------------------ 
; GOTO user application 
;------------------------------------------------------------------------------ 
		.section *, code, address(STARTADDR-4) 
usrapp:	nopr						;these two instructions will be replaced 
		nopr						;with a goto to the user application by the pc program 
		 
 
;------------------------------------------------------------------------------ 
; Start of bootloader code 
;------------------------------------------------------------------------------ 
		.section *, code, address(STARTADDR) 
__reset:mov		#__SP_init, WSTPTR	;initalize the Stack Pointer	 
 
      			 
;------------------------------------------------------------------------------ 
; Init  
;------------------------------------------------------------------------------ 
		UserInit					;macro in user_code.inc 
		clr		WDOERASE     			 
		rcall	CommInit 
		 
		 
;------------------------------------------------------------------------------ 
; Receive hello 
;------------------------------------------------------------------------------ 
		mov		#HELLOTRIES, WCNT 
rhello:	mov		#BLSTART, WDEL1 
		rcall 	ReceiveInit 
		sub 	#HELLO, W0 
		bra		z, rhellofinished		 
		; Not hello received 
		dec		WCNT, WCNT 
		bra		z, exit 
		bra		rhello		 
rhellofinished: 
 
 
;------------------------------------------------------------------------------ 
; Send device id and firmware version 
;------------------------------------------------------------------------------ 
		SendL 	( DEVICEID & 0xff ) 
		SendL	( ((DEVICEID&0x100)>>1) + VERMAJ ) 
		SendL	( ((DEVICEID&0x200)>>2) + (VERMIN<<4) + VERREV ) 
		 
 
;------------------------------------------------------------------------------ 
; Main 
;------------------------------------------------------------------------------ 
Main:	SendL 	OK		 
main1:	clr 	WCRC					;init checksum		 
		 
			 
		;---------------------------------------------------------------------- 
		; Receive address 
		;---------------------------------------------------------------------- 
		; Upper byte 
		rcall 	Receive 
		mov 	W0, TBLPAG 
		; High byte, use PR1 as temporary sfr 
		rcall 	Receive		 
		mov.b	WREG, PR1+1 
		; Low byte, use PR1 as temporary sfr 
		rcall 	Receive 
		mov.b	WREG, PR1 
		; 
		mov		PR1, WREG 
		mov		W0,	WADDR 
		mov		W0, WADDR2 
		 
		 
		;---------------------------------------------------------------------- 
		; Receive command 
		;---------------------------------------------------------------------- 
		rcall 	Receive 
		mov		W0, WCMD 
		 
 
		;---------------------------------------------------------------------- 
		; Receive nr of data bytes that will follow 
		;---------------------------------------------------------------------- 
		rcall 	Receive				 
		mov 	W0, WCNT 
		mov		W0, WTEMP1 
	 
 
		;---------------------------------------------------------------------- 
		; Receive data		 
		;---------------------------------------------------------------------- 
		mov 	#_buffer, WBUFPTR 
rcvdata: 
		rcall 	Receive		 
		mov.b 	W0, [WBUFPTR++]		 
		dec		WCNT, WCNT	 
		bra 	nz, rcvdata			;last byte received is checksum			 
			 
				 
		;---------------------------------------------------------------------- 
		; Check checksum 
		;---------------------------------------------------------------------- 
		cp0.b 	WCRC 
		bra 	z, chksumok 
		SendL 	CHECKSUMERR 
		bra 	main1					 
chksumok: 
		 
		 
		;---------------------------------------------------------------------- 
		; 0x00 goto protection 
		;----------------------------------------------------------------------	 
		.ifdef	PROT_GOTO 
			; Only for write command 
			btss	WCMD,	#1		 
			bra		protgotook		 
			; Only first row 
			cp0		TBLPAG 
			bra		nz, protgotook 
			cp0		PR1 
			bra		nz, protgotook			 
			; 
			mov 	#_buffer, WBUFPTR 
			; 1st word upper byte = goto instruction 
			mov.b 	#0x04, W0 
			mov.b	W0, [WBUFPTR++] 		 
			; 1st word  low byte = low address byte 
			mov.b 	#(0xff & STARTADDR), W0 
			mov.b 	W0, [WBUFPTR++]  
			; 1st word high byte = high address byte 
			mov.b 	#(0xff & (STARTADDR>>8)), W0 
			mov.b 	W0, [WBUFPTR++]	 
			;2nd word upper byte = unused 
			clr.b	[WBUFPTR++]	 
			; 2nd word  low byte = upper address byte 
			mov.b 	#(0xff & (STARTADDR>>16)), W0 
			mov.b 	W0, [WBUFPTR++]   
			; 2nd word high byte = unused 
			clr.b 	[WBUFPTR++]   
protgotook: 
		.endif 
			 
		 
		;---------------------------------------------------------------------- 
		; Check command 
		;---------------------------------------------------------------------- 
		mov 	#_buffer, WBUFPTR		; Init pointer	 
		 
					 
		; Erase page 
		.ifdef HAS_PAGES 
			btsc	WCMD,	#0		 
			bra		eraseact		 
		.endif 
		 
		; Write row 
		btsc	WCMD,	#1		 
		bra		blprot 
		 
		; Write EEROM word 
		.if EESIZEB > 0 
			btsc	WCMD, #2 
			bra		eeprom		 
		.endif 
		 
		; Write config byte/word 
		.ifdef CFG_WR_CODE 
			btsc	WCMD, #3 
			bra		config 
		.endif 
		 
		; Else, unknown command 
		SendL   UCMD		 
		bra     main1	 
		 
					 
		;---------------------------------------------------------------------- 
		; "Erase activation" 
		;----------------------------------------------------------------------	 
		.ifdef HAS_PAGES	 
eraseact:	mov		#0xffff, WDOERASE 
			bra		Main 
		.endif 
					 
					 
		;---------------------------------------------------------------------- 
		; Bootloader protection 
		;---------------------------------------------------------------------- 
blprot:	 
		.ifdef PROT_BL 
			; Calculate row number of received address 
			mov		TBLPAG, W1 
			mov		WADDR, W0 
			mov		#(ROWSIZEW*2), WTEMP1 
			repeat	#17 
			div.ud	W0, WTEMP1;		W = received address / (rowsizew*2) 
			; Received row < bl start row = OK 
			mov		#BLSTARTROW, WTEMP1 
			cp		W0, WTEMP1 
			bra		N, blprotok 
			; Received row > bl end row = OK 
			mov		#BLENDROW, WTEMP1 
			cp		WTEMP1, W0 
			bra		N, blprotok		 
			; Protection tripped 
			SendL   BLPROT		 
		    bra     main1 
			; Restore WADDR2 
blprotok:	mov		WADDR, WADDR2 
		.endif 
		 
					 
		;----------------------------------------------------------------------		 
		; Erase page 
		;----------------------------------------------------------------------		 
		.ifdef HAS_PAGES 
			btss	WDOERASE, #0 
			bra		program 
			tblwtl	WADDR, [WADDR]			;set base address of erase block 
			; Erase 
			mov 	#FL_ER_CODE, W0 
			rcall 	Write	 
			; Erase finished 
			clr		WDOERASE 
		.endif 
		 
		 
		;----------------------------------------------------------------------		 
		; Write row 
		;----------------------------------------------------------------------		 
program: 
		; Erase row 
		.ifndef	HAS_PAGES		 
			tblwtl	WADDR, [WADDR]			;set base address of erase block 
			mov 	#FL_ER_CODE, W0 
			rcall 	Write 
		.endif		 
		 
		; Load latches 
		mov 	#ROWSIZEW, WCNT 
latlo:	tblwth.b 	[WBUFPTR++], [WADDR] 	;upper byte 
		tblwtl.b	[WBUFPTR++], [WADDR++] 	;low byte 
		tblwtl.b	[WBUFPTR++], [WADDR++] 	;high byte	 
		dec 	WCNT, WCNT 
		bra 	nz, latlo 
		; Write flash row 
		mov 	#FL_WR_CODE, W0		 
		rcall 	Write		 
		 
		; Verify row 
		.ifdef WRITE_VER 
		mov 	#ROWSIZEW, WCNT 
		mov 	#_buffer, WBUFPTR	 
		; Verify upper byte 
verrow:	tblrdh.b [WADDR2], W0 
		cp.b	W0, [WBUFPTR++] 
		bra		NZ, vfail	 
		; Verify low byte 
		tblrdl.b [WADDR2++], W0 
		cp.b	W0, [WBUFPTR++] 
		bra		NZ, vfail 
		; Verify high byte 
		tblrdl.b [WADDR2++], W0 
		cp.b	W0, [WBUFPTR++] 
		bra		NZ, vfail 
		; 
		dec		WCNT, WCNT 
		bra 	nz, verrow 
		.endif 
		bra		Main 
		 
		 
		;---------------------------------------------------------------------- 
		; Erase, write & verify eeprom word 
		;---------------------------------------------------------------------- 
		.if EESIZEB > 0 
			;Erase eeprom word 
eeprom:		tblwtl	WADDR, [WADDR]				;set base address of erase block 
			mov 	#EE_ER_CODE, W0 
			rcall 	Write	 
			; Load latch 
			tblwtl 	[WBUFPTR], [WADDR] 
			; Write eeprom word 
			mov 	#EE_WR_CODE, W0		 
			rcall 	Write 
			; Verify eeprom word 
			.ifdef EWRITE_VER 
				tblrdl	[WADDR], W0 
				cp		W0, [WBUFPTR] 
				bra		nz, vfail 
			.endif 
			bra		Main 
		.endif 
		 
		 
		;---------------------------------------------------------------------- 
		; Verify fail 
		;---------------------------------------------------------------------- 
vfail:	SendL	VERFAIL 
		bra		main1 
		 
						 
		;---------------------------------------------------------------------- 
		; Write config word, dsPIC30F 
		;----------------------------------------------------------------------		 
		.ifdef CFG_TYPE1 
			; Load latch 
config:		tblwtl 	[WBUFPTR], [WADDR] 
			; Write config word 
			mov 	#CFG_WR_CODE, W0 
			rcall 	Write 
			; Write finished 
			bra		Main 
		.endif 
						 
		;---------------------------------------------------------------------- 
		; Write config byte, PIC24H & dsPIC33FJ 
		;---------------------------------------------------------------------- 
		.ifdef CFG_TYPE2 
config:		tblwtl.b WADDR, [WADDR]		;set base address of erase block 
			; Erase	 
			mov 	#CFG_ER_CODE, W0 
			rcall 	Write 
			; Load latch 
			tblwtl.b [WBUFPTR], [WADDR]			 
			; Write 
			mov 	#CFG_WR_CODE, W0 
			rcall 	Write 
			; Write finished 
			bra 	Main 
		.endif 
 
				 
;------------------------------------------------------------------------------ 
; Write() 
;------------------------------------------------------------------------------ 
Write:	mov 	W0, NVMCON 
		mov 	#0x55, W0 
		mov 	W0, NVMKEY 
		mov 	#0xAA, W0 
		mov 	W0, NVMKEY 
		bset 	NVMCON, #WR 
		nop 
		nop	 
		; Wait for erase/write to finish	 
compl:	btsc	NVMCON, #WR		 
		bra 	compl				 
		return    
	 
	 
;------------------------------------------------------------------------------ 
; User specific exit code go here 
;------------------------------------------------------------------------------ 
exit: 
		   
		 
;------------------------------------------------------------------------------ 
; Exit point, clean up and load user application 
;------------------------------------------------------------------------------	 
		mov 	#__SP_init, WSTPTR	;reinitialize the stack pointer 
		rcall	CommExit		 
		clr		PR1					;clear PR1, was used as temporary sfr 
		 
		UserExit 
 
 
;------------------------------------------------------------------------------ 
; Load user application 
;------------------------------------------------------------------------------ 
        bra 	usrapp 
 
 
;------------------------------------------------------------------------------ 
; Functions 
;------------------------------------------------------------------------------ 
		.include "uart.inc"	 
		 
		 
;------------------------------------------------------------------------------ 
; Validate user settings 
;------------------------------------------------------------------------------ 
				 
		; Internal cycle clock 
		.ifdef IS_24F 
			.if FCY > 16000000 
				.error "Fcy specified is out of range" 
			.endif	 
		.endif 
		.ifdef IS_24FJ 
			.if FCY > 16000000 
				.error "Fcy specified is out of range" 
			.endif	 
		.endif 
		.ifdef IS_24HJ 
			.if FCY > 40000000 
				.error "Fcy specified is out of range" 
			.endif	 
		.endif 
		.ifdef IS_30F 
			.if FCY > 30000000 
				.error "Fcy specified is out of range" 
			.endif	 
		.endif 
		.ifdef IS_33FJ 
			.if FCY > 40000000 
				.error "Fcy specified is out of range" 
			.endif	 
		.endif	 
		 
		; Alternative i/o 
		.ifndef USE_UART1 
			.ifdef USE_ALTIO 
				.error "Alternative i/o is only available for UART 1 
			.endif 
		.endif 
		.ifndef IS_30F 
			.ifdef USE_ALTIO 
				.error "Alternative i/o is only available for dsPIC30F 
			.endif 
		.endif 
	 
;------------------------------------------------------------------------------ 
; End of code 
;------------------------------------------------------------------------------ 
		.end 

Források:
   http://www.pudn.com/Download/item/id/3105781.html    
  
 http://read.pudn.com/downloads785/sourcecode/embedded/3105781/ds30%20Loader/firmware_16-bit/src/ds30loader.s__.htm
   http://read.pudn.com/downloads656/sourcecode/middleware/2666332/ds30_Loader_121109/ds30%20Loader/firmware%2016-bit/src/devices_PIC24F.inc__.htm 
 

C programozói könyv:  http://www.tech-software.net/temp/twenty.pdf