#include "built_in.h" unsigned short i = 0; unsigned long addr=0x0003dc; unsigned short dataWr[64] = {1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0, 1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0, 1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0, 1,2,3,4}; void Flash_Write_Secto(long address, char *sdata) { unsigned short saveintcon, i, j; saveintcon = INTCON; //--- erase memory TBLPTRL = Lo(address); TBLPTRH = Hi(address); TBLPTRU = Higher(address); //--- required erase sequence EECON1.EEPGD = 1; EECON1.CFGS = 0; EECON1.WREN = 1; EECON1.FREE = 1; INTCON.GIE = 0; EECON2 = 0x55; EECON2 = 0xAA; EECON1.WR = 1; INTCON.GIE = 1; asm TBLRD*- ; //--- write memory FSR0L = Lo(sdata); FSR0H = Hi(sdata); j = 0; while (j <= 7) { i = 0; while (i <= 7) { TABLAT = POSTINC0; asm { TBLWT+* } i++; } EECON1.EEPGD = 1; EECON1.CFGS = 0; EECON1.WREN = 1; INTCON.GIE = 0; EECON2 = 0x55; EECON2 = 0xAA; EECON1.WR = 1; j++; } INTCON.GIE = 1; EECON1.WREN = 0; //--- restore interrupt INTCON = saveintcon; }//~ void main() { PORTB = 0; TRISB = 0; Flash_Write_Secto(addr, dataWr); addr=0x0003dc; for (i = 0; i <= 63; i++) { PORTB = Flash_Read(addr++); }}//~!
В программе PIC 18 Simulator в регистр TABLAT запись проходит и чтение тоже, а в порт B данные не выводит.
Пишу в среде mikroC.
Прикрепленные файлы
-
Flash.rar (663байт)
Количество загрузок:: 44