MVS1 Guest
|
write_program_memory: only working for bootloader |
Posted: Wed Jun 20, 2007 1:17 pm |
|
|
pic: PIC18F2580
clock: 20MHz
compiler: PCH 4.004
In the past, I have used the bootloader program that comes with CCS and it works. (more specifically, the write_program_memory() works)
Now, I'm trying to use the program memory for somewhat static storage but I can't get this function to work. The address is at a multiple of FLASH_ERASE_SIZE.
The output is
Quote: |
Start
255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 Done
|
My sample code and listing are below
Code: |
#include <18F2580.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=115200, xmit=PIN_C6, rcv=PIN_C7)
void main()
{
int8 count,i;
int32 addr;
int8 data[16] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
int8 data_read[16];
printf("Start\n\r");
count = 16;
addr = 0x1000;
write_program_memory(addr, data, count);
read_program_memory(addr, data_read, count);
for (i = 0; i < count; i++)
{
printf("%u ", data_read[i]);
}
printf("Done\n\r");
while(1);
}
|
Code: |
CCS PCH C Compiler, Version 4.004, 34880 20-Jun-07 11:47
Filename: C:\PicFiles\memprog.lst
ROM used: 494 bytes (2%)
Largest free fragment is 32274
RAM used: 44 (3%) at main() level
49 (3%) worst case
Stack: 2 locations
*
0000: GOTO 00EE
*
0038: MOVFF 2D,01
003C: MOVFF 2C,00
0040: TSTFSZ 2C
0042: INCF 01,F
0044: TBLRD*+
0046: MOVFF FF5,FEE
004A: DECFSZ 00,F
004C: BRA 0044
004E: DECFSZ 01,F
0050: BRA 0044
0052: CLRF FF8
0054: GOTO 01A2 (RETURN)
.................... #include <18F2580.h>
.................... //////// Standard Header file for the PIC18F2580 device ////////////////
.................... #device PIC18F2580
.................... #list
....................
.................... #fuses HS,NOWDT,NOPROTECT,NOLVP
.................... #use delay(clock=20000000)
*
0034: GOTO 0188 (RETURN)
.................... #use rs232(baud=115200, xmit=PIN_C6, rcv=PIN_C7)
....................
.................... void main()
.................... {
*
00EE: CLRF FF8
00F0: BCF FD0.7
00F2: CLRF FEA
00F4: CLRF FE9
00F6: BSF FB8.3
00F8: MOVLW 2A
00FA: MOVWF FAF
00FC: MOVLW 00
00FE: MOVWF FB0
0100: MOVLW A6
0102: MOVWF FAC
0104: MOVLW 90
0106: MOVWF FAB
0108: MOVF FC1,W
010A: ANDLW C0
010C: IORLW 0F
010E: MOVWF FC1
.................... int8 count,i;
.................... int32 addr;
.................... int8 data[16] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
0110: CLRF 0C
0112: MOVLW 01
0114: MOVWF 0D
0116: MOVLW 02
0118: MOVWF 0E
011A: MOVLW 03
011C: MOVWF 0F
011E: MOVLW 04
0120: MOVWF 10
0122: MOVLW 05
0124: MOVWF 11
0126: MOVLW 06
0128: MOVWF 12
012A: MOVLW 07
012C: MOVWF 13
012E: MOVLW 08
0130: MOVWF 14
0132: MOVLW 09
0134: MOVWF 15
0136: MOVLW 0A
0138: MOVWF 16
013A: MOVLW 0B
013C: MOVWF 17
013E: MOVLW 0C
0140: MOVWF 18
0142: MOVLW 0D
0144: MOVWF 19
0146: MOVLW 0E
0148: MOVWF 1A
014A: MOVLW 0F
014C: MOVWF 1B
.................... int8 data_read[16];
....................
.................... printf("Start\n\r");
014E: CLRF 2C
0150: MOVF 2C,W
0152: RCALL 0004
0154: INCF 2C,F
0156: MOVWF 00
0158: MOVF 00,W
015A: BTFSS F9E.4
015C: BRA 015A
015E: MOVWF FAD
0160: MOVLW 07
0162: SUBWF 2C,W
0164: BNZ 0150
....................
.................... count = 16;
0166: MOVLW 10
0168: MOVWF 06
.................... addr = 0x1000;
016A: CLRF 0B
016C: CLRF 0A
016E: MOVWF 09
0170: CLRF 08
.................... write_program_memory(addr, data, count);
0172: MOVFF 09,2D
0176: MOVFF 08,2C
017A: CLRF 2F
017C: MOVLW 0C
017E: MOVWF 2E
0180: CLRF 31
0182: MOVFF 06,30
0186: BRA 0034
.................... read_program_memory(addr, data_read, count);
0188: MOVFF 0A,FF8
018C: MOVFF 09,FF7
0190: MOVFF 08,FF6
0194: CLRF FEA
0196: MOVLW 1C
0198: MOVWF FE9
019A: CLRF 2D
019C: MOVFF 06,2C
01A0: BRA 0038
....................
.................... for (i = 0; i < count; i++)
01A2: CLRF 07
01A4: MOVF 06,W
01A6: SUBWF 07,W
01A8: BC 01D2
.................... {
.................... printf("%u ", data_read[i]);
01AA: CLRF 03
01AC: MOVF 07,W
01AE: ADDLW 1C
01B0: MOVWF FE9
01B2: MOVLW 00
01B4: ADDWFC 03,W
01B6: MOVWF FEA
01B8: MOVFF FEF,2C
01BC: MOVFF 2C,2D
01C0: MOVLW 1B
01C2: MOVWF 2E
01C4: BRA 0080
01C6: MOVLW 20
01C8: BTFSS F9E.4
01CA: BRA 01C8
01CC: MOVWF FAD
.................... }
01CE: INCF 07,F
01D0: BRA 01A4
....................
.................... printf("Done\n\r");
01D2: CLRF 2C
01D4: MOVF 2C,W
01D6: RCALL 001C
01D8: INCF 2C,F
01DA: MOVWF 00
01DC: MOVF 00,W
01DE: BTFSS F9E.4
01E0: BRA 01DE
01E2: MOVWF FAD
01E4: MOVLW 06
01E6: SUBWF 2C,W
01E8: BNZ 01D4
....................
.................... while(1);
01EA: BRA 01EA
.................... }
01EC: SLEEP
Configuration Fuses:
Word 1: 0200 HS NOIESO NOFCMEN RESERVED
Word 2: 1E1E BROWNOUT NOWDT BORV21 PUT WDT32768
Word 3: 8200 PBADEN NOLPT1OSC MCLR RESERVED
Word 4: 0081 STVREN NODEBUG NOLVP BBSIZ1K NOXINST RESERVED
Word 5: C00F NOPROTECT NOCPD NOCPB
Word 6: E00F NOWRT NOWRTD NOWRTC NOWRTB
Word 7: 400F NOEBTR NOEBTRB
| [/quote][/code] |
|