完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
MPLAB IDE v8.80 PICC9.83 读写PIC16F877A内部的EEPROM时可以使用头文件中的两个宏定义EEPROM_READ(unsigned char addr)和EEPROM_WRITE(unsigned char addr,unsigned char data),还可以利用宏定义__EEPROM_DATA(1,2,3,4,5,6,7,8)初始化EEPROM内部连续8个地址
__EEPROM_DATA(a, b, c, d, e, f, g, h) asm("tpsect eeprom_data,class=EEDATA,delta=2,space=2"); asm("tdbt" ___mkstr(a) "," ___mkstr(b) "," ___mkstr(c) "," ___mkstr(d) "," ___mkstr(e) "," ___mkstr(f) "," ___mkstr(g) "," ___mkstr(h)) 877A的程序存储器FLASH_ROM的读/写,写操作要求一次性写入4个字,其地址要连续,且地址最低位必须依次为0b00,0b01,0b10,0b11 并且要求芯片的配置位的写使能在相应的程序中允许写 //FLASH_ROM的读、写宏定义调用格式如下: FLASH_WRITE(addr,value); unsigned intFLASH_READ(addr); 宏定义FLASH_READ将读出的FLASH_ROM中指定单元的内容以无符号的整形值返回,addr范围0x0000~0x1FFF, value值范围0x0000~0x3FFF 注意:由于程序存储器是14位,因此读出的结果必须是整型,而不能为字符型 读写PIC16F877A内部的FlashROM时,可以使用头文件中的宏定义 unsigned int FLASH_READ( unsigned int addr )进行读,但当利用宏定义FLASH_WRITE(addr,value )写FlashROM时,编译时会报错 Error [499] ; 0. undefined symbol: _FLASH_WRITE(Flash_ROM.obj) 没有找到这个宏定义的,查看C盘安装文件C:Program FilesHI-TECH SoftwarePICC9.83include中的pic.h头文件 发现在此版本的PICC中,当芯片为PIC16F877A时,FLASH_WRITE()这个函数式没有被使能的, 所以当芯片为PIC16F877A时不能使用宏定义的FLASH_WRITE()函数,以下是pic.h中的定义: /*********************************************************************** **** FLASH memory read/write/erase macros and function definitions **** *********************************************************************** * Notes: * __FLASHTYPE == 0 defined in devices that can only read flash memory - cannot write eg. 16F777 * __FLASHTYPE == 1 defined in traditional devices that can write 1 word at a time eg. 16F877 * __FLASHTYPE == 2 defined in devices that can only write in 4 word blocks eg. 16F877A * __FLASHTYPE == 3 defined in devices requiring 32-word block erasure before writing eg. 16F87 * __FLASHTYPE == undefined if device can neither read nor write program memory */ // macro FLASH_READ returns a word stored at a flash address #if defined(__FLASHTYPE) extern unsigned int flash_read(unsigned short addr); #if EEPROM_SIZE > 0 #define FLASH_READ(addr) (EEADRL=(addr)&0xff, EEADRH=(addr)>>8, WREN=0, EECON1 |= 0x80, RD=1, NOP(), NOP(), (EEDATH << 8) | EEDATA) #else // FLASH_READ without EEPROM #define FLASH_READ(addr) (EEADRL=(addr)&0xff, EEADRH=(addr)>>8, RD=1, NOP(), NOP(), (EEDATH << 8) | EEDATA) #endif #endif // end FLASH_READ // macro FLASH_WRITE used when writing only one word of data #if __FLASHTYPE==2 || __FLASHTYPE==3 /* * This is not available in this version. Contact HI-TECH support for more information. #define FLASH_WRITE(addr,data) do{ unsigned short x=data; flash_copy((const unsigned short *)&x,1,addr); }while(0) extern void flash_copy(const unsigned short * source_addr,unsigned char length,unsigned short dest_addr); */ #elif __FLASHTYPE==1 #define FLASH_WRITE(addr, value) EEADRL=((addr)&0xff); EEADRH=((addr)>>8); EEDATH=((value)>>8); EEDATA=((value)&0xff); EECON1 |= 0x80; WREN=1; EECON2 = 0x55; EECON2 = 0xaa; WR=1; NOP(); NOP(); WREN=0 //extern void flash_copy(const unsigned short * source_addr,unsigned char length,unsigned short dest_addr); #endif // end FLASH_WRITE // macro FLASH_ERASE used to clear a 32-Byte sector of flash #if __FLASHTYPE==3 #define FLASH_ERASE(addr) while(WR)continue; EEADRL=((addr)&0xFF); EEADRH=((addr>>8)&0xFF); EECON1=0x94; CARRY=0;if(GIE)CARRY=1;GIE=0; EECON2=0x55;EECON2=0xAA;WR=1; NOP(); if(CARRY)GIE=1 // library function version extern void flash_erase(unsigned short addr); #endif // end FLASH_ERASE 注意红色部分的内容。 当把芯片类型改为PIC16F877时,编译可以正常通过,运行也正常。 |
|
相关推荐
|
|
只有小组成员才能发言,加入小组>>
求解外围电路实现的是4脚给持续低电平复位并正常工作,高电平不工作的原因
2084 浏览 1 评论
3629 浏览 3 评论
PIC1946程序有一个变量在运行过程中恢复初始值其他变量保持不变
2336 浏览 2 评论
2763 浏览 0 评论
PIC16F1825的RC5引脚,在主程序中操作无效,在中断中可以改变是为什么?
4027 浏览 5 评论
972浏览 0评论
用XC8编译PIC18F25K80时提示下面Error,求怎么解决这个问题
6359浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-2 22:41 , Processed in 0.551814 second(s), Total 75, Slave 57 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号