ATMEL公司24系列EEPROM编程举例

上传人:公**** 文档编号:389256988 上传时间:2022-09-11 格式:DOCX 页数:22 大小:18.58KB
返回 下载 相关 举报
ATMEL公司24系列EEPROM编程举例_第1页
第1页 / 共22页
ATMEL公司24系列EEPROM编程举例_第2页
第2页 / 共22页
ATMEL公司24系列EEPROM编程举例_第3页
第3页 / 共22页
ATMEL公司24系列EEPROM编程举例_第4页
第4页 / 共22页
ATMEL公司24系列EEPROM编程举例_第5页
第5页 / 共22页
点击查看更多>>
资源描述

《ATMEL公司24系列EEPROM编程举例》由会员分享,可在线阅读,更多相关《ATMEL公司24系列EEPROM编程举例(22页珍藏版)》请在金锄头文库上搜索。

1、作者:尘封往事文章来源:本站原创点击数:惡2043更新时间:2006-1-12 13:07:34NAME Control_AT24Cxx; This collection of routines allows an AT89C2051 microcontroller to read and write the AT24Cxx family of serial CMOS EEPROMS. This version of the code is compatible only with the AT89C2051 due to the location of the data buffer and

2、 stack in RAM. The code may be modified to work with the AT89C1051 by relocating or resizing the buffer and stack to fit into the smaller amount of RAM available in the AT89C1051. Note that the minimum size of the buffer is determined by the page size of the AT24Cxx.All five AT24Cxx device operation

3、s are supported. Byte Write, Current Address Read and Random Read are implemented by the functions WRITE_BYTE, READ_CURRENT and READ_RANDOM, respectively. Page Write and Sequential Read are special cases of functions WRITE_BLOCK and READ_BLOCK, respectively. WRITE_BLOCK and READ_BLOCK process from o

4、ne byte to the number of bytes in a page and transfer data between the AT24Cxx and the RAM buffer.The code supports multiple AT24Cxx devices per bus, each with a unique address determined by the wiring of the address pins (A0, A1, A2). The three-bit programmable address is passed to the WRITE_BYTE,

5、READ_CURRENT, READ_RANDOM, WRITE_BLOCK and READ_BLOCK functions, where it is combined with the AT24Cxx fixed address (FADDR) and used to address a device on the bus. Refer to the AT24Cxx family data sheets for additional information on device addressing.Functions BYTE_FILL, VERIFY_BYTE_FILL, PAGE_FI

6、LL and VERIFY_PAGE_FILL are artifacts from the debug process and serve to illustrate the use of thedevice read and write functions with an AT24C64. To modify the code for adifferent member of the AT24Cxx family, simply redefine the values of SIZE (the number of bytes per device) and PSIZE (the numbe

7、r of bytes per page). To change the fill value, redefine FILL. To change the programmable portion of the device address, redefine PADDR to a value from zero to seven.The code meets all AT24Cxx family timing requirements when executed by an AT89Cx051 microcontroller with a 12 MHz clock. Code modifica

8、tions may be required if a faster clock is substituted.FADDREQU 0a0h; fixed address for AT24Cxx EEPROMsPADDREQU 0 ;programmable address (0.7)SIZEEQU 2000h; bytes per AT24C64PSIZEEQU 32bytes per page for AT24C64FILLEQU 55hexample fill value; Register definitions.index EQU r0 ; buffer pointerkount EQU

9、 r1 ; byte count registerzdata EQU r1 ; data registeraddr_lo EQU r2 ; 2-byte address registeraddr_hi EQU r3 ; Microcontroller connections to AT24Cxx serial bus lines.SCL BIT p1.2 ; serial clockSDA BIT p1.3 ; serial dataDSEG AT 20HORG 40H buffer: DS PSIZE ; storage for read/write dataORG 60H ; stack

10、originstack: DS 20H ; stack depthCSEGORG 0000H ; power on/reset vectorjmp on_resetORG 0003H ; external interrupt 0 vectorreti ; undefinedORG 000BH ; timer 0 overflow vectorreti ; undefinedORG 0013H ; external interrupt 1 vectorreti ; undefinedORG 001BH ; timer 1 overflow vectorreti ; undefinedORG 00

11、23H ; serial I/O interrupt vectorreti ; undefinedORG 0080H ; begin code spaceUSING 0 ; register bank zeroon_reset:mov sp, #(stack-1) ; initialize stack pointerInitialize AT24Cxx serial bus lines.setb SDA ; highsetb SCL ; highcall byte_filljc faultcall verify_byte_filljc faultcall page_filljc faultca

12、ll verify_page_filljc faultfault:jmp $byte_fill:; Fill every byte in an AT24Cxx with the same value.; Writes one address at a time (page mode is not used).; Returns CY set to indicate write timeout.; Destroys A, B, DPTR, XDATA, ADDR_HI:ADDR_LO.mov zdata, #FILL ; set up fill datamov dptr, #0 ; initia

13、lize address pointerx51:mov addr_lo, dpl ; set up addressmov addr_hi, dphmov b, #120 ; retry counterx52:mov a, #PADDR ; programmable addresscall write_byte ; try to writejnc x53 ; jump if write OKdjnz b, x52 ; try againsetb c ; set timeout error flagjmp x54 ; exitx53:inc dptr ; advance address point

14、er; mov a, dpl ; check low byte; cjne a, #(LOW SIZE), x51 ; jump if not lastmov a, dph ; check high bytecjne a, #(HIGH SIZE), x51 ; jump if not lastclr c ; clear error flagx54:retverify_byte_fill:; Verify that all bytes in an AT24Cxx match a fill value.; Reads and verifies one byte at a time (page m

15、ode is not used).; Performs a Random Read function to initialize the internal; address counter and checks the contents of the first address.; Then performs multiple Current Address Read functions to step; through the remaining addressess.; Returns CY set to indicate read timeout or compare fail.Destroys A, B, DPTR.mov dptr, #0 ; initialize address pointer/countermov addr_lo, dpl ; set up addressmov addr_hi, dph ;mov b, #120 ; retry counterx81:mov a, #PADDR ; programmable addresscall read_random ; try to readjnc x82; jump if read OKdjnz b,x81 ; try againjmp x86

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 建筑/环境 > 建筑资料

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号