PIC24 Support Libraries
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
memory.s
1 ;********************************************************************
2 ; FileName: memory.s
3 ; Dependencies:
4 ; Processor: PIC24H Family
5 ; Hardware: Explorer 16
6 ; Assembler: ASM30 2.14
7 ; Company: Microchip Technology, Inc.
8 ;
9 ; Software License Agreement
10 ;
11 ; The software supplied herewith by Microchip Technology Incorporated
12 ; (the “Company” for its PICmicro® Microcontroller is intended and ; supplied to you, the Company’s customer, for use solely and ; exclusively on Microchip PICmicro Microcontroller products. The ; software is owned by the Company and/or its supplier, and is ; protected under applicable copyright laws. All rights are reserved. ; Any use in violation of the foregoing restrictions may subject the ; user to criminal sanctions under applicable laws, as well as to ; civil liability for the breach of the terms and conditions of this ; license. ; ; THIS SOFTWARE IS PROVIDED IN AN “AS IS” CONDITION. NO WARRANTIES, ; WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED ; TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A ; PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE COMPANY SHALL NOT, ; IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR ; CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER. ; ;********************************************************************/ .include "p24Hxxxx.inc" .global _LoadAddr,_WriteMem,_WriteLatch,_ReadLatch,_ResetDevice,_Erase ;C called _LoadAddr: ;W0=NVMADRU,W1=NVMADR - no return values mov W0,TBLPAG mov W1,W1 return ;*************************************************************** _WriteMem: ;W0=NVMCON - no return values mov W0,NVMCON mov #0x55,W0 ;Unlock sequence - interrupts need to be off mov W0,NVMKEY mov #0xAA,W0 mov W0,NVMKEY bset NVMCON,#WR nop ;Required nop 1: btsc NVMCON,#WR ;Wait for write end bra 1b return ;*************************************************************** _WriteLatch: ;W0=TBLPAG,W1=Wn,W2=WordHi,W3=WordLo - no return values mov W0,TBLPAG tblwtl W3,[W1] tblwth W2,[W1] return ;*************************************************************** _ReadLatch: ;W0=TBLPAG,W1=Wn - data in W1:W0 mov W0,TBLPAG tblrdl [W1],W0 tblrdh [W1],W1 return ;*************************************************************** _ResetDevice: goto 0xc02 return ;*************************************************************** _Erase: push TBLPAG mov W2,NVMCON mov w0,TBLPAG ; Init Pointer to page to be erased tblwtl w1,[w1] ; Dummy write to select the row mov #0x55,W0 ;Unlock sequence - interrupts need to be off mov W0,NVMKEY mov #0xAA,W0 mov W0,NVMKEY bset NVMCON,#WR nop ;Required nop erase_wait: btsc NVMCON,#WR ;Wait for write end bra erase_wait pop TBLPAG return ;*************************************************************** .end ) for its PICmicro®Microcontroller is intended and ; supplied to you, the Company’s customer, for use solely and ; exclusively on Microchip PICmicro Microcontroller products. The ; software is owned by the Company and/or its supplier, and is ; protected under applicable copyright laws. All rights are reserved. ; Any use in violation of the foregoing restrictions may subject the ; user to criminal sanctions under applicable laws, as well as to ; civil liability for the breach of the terms and conditions of this ; license. ; ; THIS SOFTWARE IS PROVIDED IN AN “AS IS” CONDITION. NO WARRANTIES, ; WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED ; TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A ; PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE COMPANY SHALL NOT, ; IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR ; CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER. ; ;********************************************************************/ .include "p24Hxxxx.inc" .global _LoadAddr,_WriteMem,_WriteLatch,_ReadLatch,_ResetDevice,_Erase ;C called _LoadAddr: ;W0=NVMADRU,W1=NVMADR - no return values mov W0,TBLPAG mov W1,W1 return ;*************************************************************** _WriteMem: ;W0=NVMCON - no return values mov W0,NVMCON mov #0x55,W0 ;Unlock sequence - interrupts need to be off mov W0,NVMKEY mov #0xAA,W0 mov W0,NVMKEY bset NVMCON,#WR nop ;Required nop 1: btsc NVMCON,#WR ;Wait for write end bra 1b return ;*************************************************************** _WriteLatch: ;W0=TBLPAG,W1=Wn,W2=WordHi,W3=WordLo - no return values mov W0,TBLPAG tblwtl W3,[W1] tblwth W2,[W1] return ;*************************************************************** _ReadLatch: ;W0=TBLPAG,W1=Wn - data in W1:W0 mov W0,TBLPAG tblrdl [W1],W0 tblrdh [W1],W1 return ;*************************************************************** _ResetDevice: goto 0xc02 return ;*************************************************************** _Erase: push TBLPAG mov W2,NVMCON mov w0,TBLPAG ; Init Pointer to page to be erased tblwtl w1,[w1] ; Dummy write to select the row mov #0x55,W0 ;Unlock sequence - interrupts need to be off mov W0,NVMKEY mov #0xAA,W0 mov W0,NVMKEY bset NVMCON,#WR nop ;Required nop erase_wait: btsc NVMCON,#WR ;Wait for write end bra erase_wait pop TBLPAG return ;*************************************************************** .end Microcontroller is intended and
13 ; supplied to you, the Company’s customer, for use solely and
14 ; exclusively on Microchip PICmicro Microcontroller products. The
15 ; software is owned by the Company and/or its supplier, and is
16 ; protected under applicable copyright laws. All rights are reserved.
17 ; Any use in violation of the foregoing restrictions may subject the
18 ; user to criminal sanctions under applicable laws, as well as to
19 ; civil liability for the breach of the terms and conditions of this
20 ; license.
21 ;
22 ; THIS SOFTWARE IS PROVIDED IN AN “AS IS”CONDITION. NO WARRANTIES, ; WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED ; TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A ; PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE COMPANY SHALL NOT, ; IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR ; CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER. ; ;********************************************************************/ .include "p24Hxxxx.inc" .global _LoadAddr,_WriteMem,_WriteLatch,_ReadLatch,_ResetDevice,_Erase ;C called _LoadAddr: ;W0=NVMADRU,W1=NVMADR - no return values mov W0,TBLPAG mov W1,W1 return ;*************************************************************** _WriteMem: ;W0=NVMCON - no return values mov W0,NVMCON mov #0x55,W0 ;Unlock sequence - interrupts need to be off mov W0,NVMKEY mov #0xAA,W0 mov W0,NVMKEY bset NVMCON,#WR nop ;Required nop 1: btsc NVMCON,#WR ;Wait for write end bra 1b return ;*************************************************************** _WriteLatch: ;W0=TBLPAG,W1=Wn,W2=WordHi,W3=WordLo - no return values mov W0,TBLPAG tblwtl W3,[W1] tblwth W2,[W1] return ;*************************************************************** _ReadLatch: ;W0=TBLPAG,W1=Wn - data in W1:W0 mov W0,TBLPAG tblrdl [W1],W0 tblrdh [W1],W1 return ;*************************************************************** _ResetDevice: goto 0xc02 return ;*************************************************************** _Erase: push TBLPAG mov W2,NVMCON mov w0,TBLPAG ; Init Pointer to page to be erased tblwtl w1,[w1] ; Dummy write to select the row mov #0x55,W0 ;Unlock sequence - interrupts need to be off mov W0,NVMKEY mov #0xAA,W0 mov W0,NVMKEY bset NVMCON,#WR nop ;Required nop erase_wait: btsc NVMCON,#WR ;Wait for write end bra erase_wait pop TBLPAG return ;*************************************************************** .end CONDITION. NO WARRANTIES,
23 ; WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED
24 ; TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
25 ; PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE COMPANY SHALL NOT,
26 ; IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR
27 ; CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
28 ;
29 ;********************************************************************/
30 .include "p24Hxxxx.inc"
31 
32 .global _LoadAddr,_WriteMem,_WriteLatch,_ReadLatch,_ResetDevice,_Erase ;C called
33 
34 
35 _LoadAddr: ;W0=NVMADRU,W1=NVMADR - no return values
36  mov W0,TBLPAG
37  mov W1,W1
38 
39  return
40 
41 ;***************************************************************
42 _WriteMem: ;W0=NVMCON - no return values
43  mov W0,NVMCON
44  mov #0x55,W0 ;Unlock sequence - interrupts need to be off
45  mov W0,NVMKEY
46  mov #0xAA,W0
47  mov W0,NVMKEY
48  bset NVMCON,#WR
49  nop ;Required
50  nop
51 1: btsc NVMCON,#WR ;Wait for write end
52  bra 1b
53 
54  return
55 
56 ;***************************************************************
57 _WriteLatch: ;W0=TBLPAG,W1=Wn,W2=WordHi,W3=WordLo - no return values
58  mov W0,TBLPAG
59  tblwtl W3,[W1]
60  tblwth W2,[W1]
61 
62  return
63 
64 ;***************************************************************
65 _ReadLatch: ;W0=TBLPAG,W1=Wn - data in W1:W0
66  mov W0,TBLPAG
67  tblrdl [W1],W0
68  tblrdh [W1],W1
69 
70  return
71 
72 
73 ;***************************************************************
74 _ResetDevice:
75 
76  goto 0xc02
77 
78  return
79 
80 ;***************************************************************
81 _Erase:
82 
83 
84  push TBLPAG
85  mov W2,NVMCON
86 
87  mov w0,TBLPAG ; Init Pointer to page to be erased
88  tblwtl w1,[w1] ; Dummy write to select the row
89 
90 
91  mov #0x55,W0 ;Unlock sequence - interrupts need to be off
92  mov W0,NVMKEY
93  mov #0xAA,W0
94  mov W0,NVMKEY
95  bset NVMCON,#WR
96  nop ;Required
97  nop
98 
99 erase_wait:
100  btsc NVMCON,#WR ;Wait for write end
101  bra erase_wait
102 
103  pop TBLPAG
104  return
105 
106 ;***************************************************************
107 .end