完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
自编程代码调试已经通过,贴上代码,求解一个擦除范围的问题.手册上说可以按块擦除(8行围一块),但是调试时是都给擦除了.数据手册上这样写不是自相矛盾么.贴上我的代码.读写擦除都正常,就是擦除长度无法控制.
#include "p24fj64ga006.h" _CONFIG2(IESO_OFF&FNOSC_PRIPLL&FCKSM_CSDCMD&POSCMOD_XT/*&OSCIOFNC_OFF*/); _CONFIG1(JTAGEN_OFF&GCP_OFF&GWRP_OFF&COE_OFF&ICS_PGx2&FWDTEN_OFF/*&BKBUG_ON&WINDIS_OFF&FWPSA_PR32&WDTPS_PS1*/); #define UINT32 unsigned long #define UINT16 unsigned int #define UINT8 unsigned char #define FLASH_ERASEPAGE 0x4042 #define FLASH_PROGLINE 0x4001 void delay(unsigned int a) { unsigned char x,y; for(x=a;x>0;x--) for(y=1105;y>0;y--); } void FlashReadData(UINT32 FlashAddr,UINT16 *Dest,UINT8 DataNum) { TBLPAG = ((FlashAddr & 0x7F0000)>>16); FlashAddr = (FlashAddr & 0x00FFFF); for(;DataNum>0;DataNum--) { asm("tblrdl.w [%1],%0":"=r"(*Dest):"r"(FlashAddr)); Dest++; // asm("tblrdl.b [%1],%0":"=r"(*Dest):"r"(FlashAddr+1)); // Dest++; // asm("tblrdh.w [%1],%0":"=r"(*Dest):"r"(FlashAddr)); // Dest++; FlashAddr += 2; delay(1); } } void FlashErasePage(UINT32 FlashAddr) { NVMCON = FLASH_ERASEPAGE; TBLPAG = ((FlashAddr & 0x7F0000)>>16); FlashAddr = (FlashAddr & 0x00FFFF); // asm("tblwtl w0,[w0]"); asm("tblwtl %0, [w0]" : /* no outputs */ : "r"(FlashAddr)); NVMKEY = 0x55; NVMKEY = 0xaa; _WR = 1; Nop(); Nop(); } void FlashWriteData(UINT32 FlashAddr,UINT16 *Dest,UINT8 DataNum) { FlashErasePage(FlashAddr); NVMCON = FLASH_PROGLINE; TBLPAG = ((FlashAddr & 0x7F0000)>>16); FlashAddr = (FlashAddr & 0x00FFFF); for(;DataNum>0;DataNum--) { asm("tblwtl.w %0,[%1]"::"r"(*Dest),"d"(FlashAddr)); Dest++; // asm("tblwth.w %0,[%1]"::"r"(*Dest),"d"(FlashAddr)); // Dest++; FlashAddr += 2; delay(1); } NVMKEY = 0x55; NVMKEY = 0xaa; _WR = 1; Nop(); Nop(); } void main() { int a[]={0x2100,0x0000,0x0000,0x0010}; int aa[]={0x1234,0x5678,0x9abc,0xdef1,0x2345,0x6789, 0x1234,0x5678,0x9abc,0xdef1,0x2345,0x6789, 0x1234,0x5678,0x9abc,0xdef1,0x2345,0x6789, 0x1234,0x5678,0x9abc,0xdef1,0x2345,0x6789, 0x1234,0x5678,0x9abc,0xdef1,0x2345,0x6789, 0x1234,0x5678,0x9abc,0xdef1,0x2345,0x6789, 0x1234,0x5678,0x9abc,0xdef1,0x2345,0x6789, 0x1234,0x5678,0x9abc,0xdef1,0x2345,0x6789, 0x1234,0x5678,0x9abc,0xdef1,0x2345,0x6789 }; int bb[]={0xaaaa,0x5555,0xffff,0x0000,0xabcd,0xabcd}; int cc[]={0,0,0,0,0,0}; AD1PCFG=0XFFFF; TRISB=0; LATB=0X0000; delay(50); FlashReadData(0x5000,cc,6); delay(50); Nop(); Nop(); FlashErasePage(0x5060); delay(50); Nop(); Nop(); FlashWriteData(0x5000,aa,54); delay(50); Nop(); Nop(); FlashWriteData(0x5060,a,4); delay(50); Nop(); Nop(); FlashWriteData(0x5060,bb,6); delay(50); Nop(); Nop(); FlashReadData(0x5000,cc,6); delay(50); Nop(); Nop(); if(*cc==*aa) _RB8=1; FlashErasePage(0x5060); delay(50); Nop(); Nop(); FlashReadData(0x5000,cc,6); delay(50); Nop(); Nop(); if(*cc==*aa) _RB8=1; else _RB8=0; while(1); }
|
|
相关推荐
|
|
只有小组成员才能发言,加入小组>>
求解外围电路实现的是4脚给持续低电平复位并正常工作,高电平不工作的原因
2102 浏览 1 评论
3665 浏览 3 评论
PIC1946程序有一个变量在运行过程中恢复初始值其他变量保持不变
2353 浏览 2 评论
2779 浏览 0 评论
PIC16F1825的RC5引脚,在主程序中操作无效,在中断中可以改变是为什么?
4066 浏览 5 评论
1010浏览 0评论
用XC8编译PIC18F25K80时提示下面Error,求怎么解决这个问题
6395浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-25 21:23 , Processed in 0.723135 second(s), Total 73, Slave 55 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号