导航: 老古网老古论坛XMOS公共讨论区XMOS开源项目区单片机程序设计嵌入式系统广告区域
→初学者:X25045看门狗编程[llago]

 *第3840篇: 初学者:X25045看门狗编程

  
楼 主:llago 2002年7月1日18:13
 初学者:X25045看门狗编程
第一次作项目,系统复位电路采用X25045看门狗芯片,我找资料查了一下,发现只作系统复
位使用,好像不用编程,又觉得不对,请高手指点迷津,如果那位大侠恰好也在使用X25045
有现成的程序清给我发一份(最好有注释),不胜感激,LLAGO◎CG-TECH.COM
  
2楼:huxiangming 2002年7月1日21:45
 你起码也要喂它吧
  
3楼:傲气雄鹰 2002年7月2日12:54
 X25045(ASM)

; * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
; X25045
; 1、WD_RST   看门狗复位子程序
; 2、WD_SET   看门狗定时时间设置子程序
; 3、RD_SR     读状态寄存器子程序
; 4、WR_SR    写状态寄存器子程序
; 5、RD_B      读一个字节数据子程序
; 6、WR_B     写一个字节数据子程序
;* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
CS    EQU  CS_RAM
SI    EQU  DATAIN
SO    EQU  DATAOUT
SCK    EQU  CLK

WR_:    MOV R0,#08H    ;写8位数据
WR_1:    RLC A
    MOV SI,C
    CLR SCK
    SETB SCK
    DJNZ R0,WR_1
    RET

RD_:    MOV R0,#08H    ;读8位数据
RD_1:    SETB SCK
    CLR SCK
    MOV C,SO
    RLC A
    DJNZ R0,RD_1
    RET

;看门狗复位子程序
WD_RST:    CLR   CS
    SETB  CS
    RET
;看门狗定时时间设置成600ms
WD_SET:    MOV R0,#10H    ;若将定时时间设为1.4S或200ms,则应送立即
    ;数#00或#20
    LCALL WR_SR
    RET
;读状态寄存器子程序,读出的X25045的状态存在A累加器中
RD_SR:    MOV A,#05H    ;将RDSR命令送A累加器
    CLR CS
    LCALL WR_
    LCALL RD_
    SETB CS
    RET

;写状态寄存器子程序。F0为写成功与否标志,F0=0,写成功;F0=1,写失败
WR_SR:    LCALL RD_SR    ;检查WPI位,确定X25045是否正在进行写操作
    CLR F0
    JNB ACC.0,WR_SR1    ;WPI=0,转写状态寄存器
    SETB F0        ;WPI=1,1F0后返回
    RET
WR_SR1:    CLR CS
    MOV A,#06H    ;置位写使能寄存器
    LCALL WR_
    SETB CS
    CLR CS
    MOV A,#01H    ;送写状态寄存器命令
    LCALL WR_
    MOV A,#18H    ;设看门狗定时时间为600ms,块保护地址为
    ;100H~1FFH
    LCALL WR_
    CLR CS
    SETB CS 
    RET
;读一个字节数据子程序,待读出数据地址在R3中,读出后的数据存R4
RD_B:    LCALL RD_SR
    JB ACC.0,RD_B
    CLR CS
    MOV A,#03H    ;送读E2PROM命令,地址在00H~FFH间
    LCALL WR_
    MOV A,R3    ;送地址
    LCALL WR_
    LCALL RD_    ;读数据并送R4
    MOV R4,A
    SETB CS
    RET


;写一个字节数据子程序,写入地址在R3中,数据在R4中
WR_B:    LCALL RD_SR
    JB ACC.0,WR_B
    CLR CS
    MOV A,#06H    ;置位写使能寄存器
    LCALL WR_
    SETB CS
    CLR CS
    MOV A,#02H    ;送写E2PROM命令,地址在00H~FFH间
    LCALL WR_
    MOV A,R3    ;送地址
    LCALL WR_
    MOV A,R4    ;送待写数据
    LCALL WR_
    CLR CS
    SETB CS
    RET

  
4楼:傲气雄鹰 2002年7月2日12:56
 X25045(Other ASM)
;Xicor Application Note AN21-3
$ TITLE(X25043/8031/1.0)
;**************************************************************************
*****
************
*
;* Copyright (c) 1994 Xicor, Inc.
;* AUTHOR: Richard Downing
;**************************************************************************
*****
************
*
;* The purpose of this code is to provide routines to interface the Xicor 
X25043 with the 8031
;* microcontroller. The interface uses the 8031's general purpose parallel 
port 
1 and connects
;* P1.0 to the chip select line (/CS), P1.1 to the serial input data line 
(SI), 
P1.2 to the
;* serial clock line (SCK) and P1.3 to the serial output data line (SO).
;*
;* All X25043 commands are provided. These are :-;*
;* 1. Set Write Enable Latch
;* 2. Reset Write Enable Latch
;* 3. Write Status Register
;* 4. Read Status Register
;* 5. Single Byte Write
;* 6. Single Byte Read
;* 7. Page Write
;* 8. Sequential Read
;* 9. Reset Watchdog Timer
;*
;* The code writes 00H to the Status Register; reads the Status Register; 
writes 11H to
;* address 55H in Byte Mode; performs a single Byte Read from address 55H; 
writes 22H,
;* 33H, 44H to addresses 1F0H, 1F1H, 1F2H in Page Mode; performs a 
Sequential 
Read
;* from addresses 1F0H, 1F1H, 1F2H; and resets watchdog timer. This code 
can 
also be used with
;* the X25045 which is identical to the X25043, except for its RESET 
output 
polarity.
;**************************************************************************
*****
************
*
;* CONSTANTS
cs bit P1.0 ; Port 1 bit 0 used for chip select (/CS)
si bit P1.1 ; Port 1 bit 1 used for serial input (CI)
sck bit P1.2 ; Port 1 bit 2 used for serial clock (SCK)
so bit P1.3 ; Port 1 bit 3 used for serial output (SO)
WREN_INST equ 06H ; Write enable latch instruction (WREN)
WRDI_INST equ 04H ; Write disable latch instruction (WRDI)
WRSR_INST equ 01H ; Write status register instruction (WRSR)
RDSR_INST equ 05H ; Read status register instruction (RDSR)
WRITE_INST equ 02H ; Write memory instruction (WRITE)
READ_INST equ 03H ; Read memory instruction (READ)
BYTE_ADDR equ 55H ; Memory address for byte mode operations
BYTE_DATA equ 11H ; Data byte for byte write operation
PAGE_ADDR equ 1F0H ; Memory address for page mode operations
PAGE_DATA1 equ 22H ; 1st data byte for page write operation
PAGE_DATA2 equ 33H ; 2nd data byte for page write operation
PAGE_DATA3 equ 44H ; 3rd data byte for page write operation
STATUS_REG equ 00H ; Status register
;Xicor Application Note AN21-4
MAX_POLL equ 99H ; Maximum number of polls
INIT_STATE equ 09H ; Initialization value for control ports
SLIC equ 030H ; Address location of SLIC
;Xicor Application Note AN21-5
;**************************************************************************
*****
************
*
;* INTERNAL RAM
STACK_TOP equ 060H ; Stack top
;**************************************************************************
*****
************
*
;* CODE
ORG 0000H ; Reset vectors to this location
ljmp main
ORG 0100H
main:
mov SP, #STACK_TOP ; Initialize stack pointer
clr EA ; Disable interupts
mov P1, #INIT_STATE ; Init control lines (/CS & SO =1, SCK & SI =0)
lcall wren_cmd ; Set write enable latch
lcall wrsr_cmd ; Write 00H to status register
lcall wren_cmd ; Set write enable latch
lcall byte_write ; Write 11H to address 55H (Byte Write)
lcall byte_read ; Read from address location 55H (Byte Read)
lcall wren_cmd ; Set write enable latch
lcall page_write ; Page write 22H/33H/44H to addresses 1F0/1/2H
lcall sequ_read ; Seq. Read from address locations 1F0/1/2H
lcall rst_wdog ; Reset Watchdog timer
jmp SLIC
;**************************************************************************
*****
************
*
;* Name: WREN_CMD
;* Description: Set write enable latch
;* Function: This routine sends the command to enable writes to the EEPROM 
memory array or
;* status register
;* Calls: outbyt
;* Input: None
;* Outputs: None
;* Register Usage: A
;**************************************************************************
*****
************
*
wren_cmd:
clr sck ; Bring SCK low
clr cs ; Bring /CS low
mov A, #WREN_INST
lcall outbyt ; Send WREN instruction
clr sck ; Bring SCK low
setb cs ; Bring /CS high
ret
;Xicor Application Note AN21-6
;**************************************************************************
*****
************
*
;* Name: WRDI_CMD
;* Description: Reset write enable latch
;* Function: This routine sends the command to disable writes to the 
EEPROM 
memory array or
;* status register
;* Calls: outbyt
;* Input: None
;* Outputs: None
;* Register Usage: A
;**************************************************************************
*****
************
*
wrdi_cmd:
clr sck ; Bring SCK low
clr cs ; Bring /CS low
mov A, #WRDI_INST
lcall outbyt ; Send WRDI instruction
clr sck ; Bring SCK low
setb cs ; Bring /CS high
ret
;**************************************************************************
*****
************
*
;* Name: WRSR_CMD
;* Description: Write Status Register
;* Function: This routine sends the command to write the WD0, WD1, BP0 and 
BP0 
EEPROM
;* bits in the status register
;* Calls: outbyt, wip_poll
;* Input: None
;* Outputs: None
;* Register Usage: A
;**************************************************************************
*****
************
*
wrsr_cmd:
clr sck ; Bring SCK low
clr cs ; Bring /CS low
mov A, #WRSR_INST
lcall outbyt ; Send WRSR instruction
mov A, #STATUS_REG
lcall outbyt ; Send status register
clr sck ; Bring SCK low
setb cs ; Bring /CS high
lcall wip_poll ; Poll for completion of write cycle
ret
;**************************************************************************
*****
************
*
;* Name: RDSR_CMD
;* Description: Read Status Register
;* Function: This routine sends the command to read the status register
;* Calls: outbyt, inbyt
;* Input: None
;* Outputs: A = status register
;Xicor Application Note AN21-7
;* Register Usage: A
;**************************************************************************
*****
************
*
rdsr_cmd:
clr sck ; Bring SCK low
clr cs ; Bring /CS low
mov A, #RDSR_INST
lcall outbyt ; Send RDSR instruction
lcall inbyt ; Read status register
clr sck ; Bring SCK low
setb cs ; Bring /CS high
ret
;**************************************************************************
*****
************
*
;* Name: BYTE_WRITE
;* Description: Single Byte Write
;* Function: This routine sends the command to write a single byte to the 
EEPROM memory array
;* Calls: outbyt, wip_poll
;* Input: None
;* Outputs: None
;* Register Usage: A, B
;**************************************************************************
*****
************
*
byte_write:
mov DPTR, #BYTE_ADDR ; Set address of byte to be written
clr sck ; Bring SCK low
clr cs ; Bring /CS low
mov A, #WRITE_INST
mov B, DPH
mov C, B.0
mov ACC.3, C
lcall outbyt ; Send WRITE instruction including MSB of address
mov A, DPL
lcall outbyt ; Send 8 LSBs of address
mov A, #BYTE_DATA
lcall outbyt ; Send data byte
clr sck ; Bring SCK low
setb cs ; Bring /CS high
lcall wip_poll ; Poll for completion of write cycle
ret
;**************************************************************************
*****
************
*
;* Name: BYTE_READ
;* Description: Single Byte Read
;* Function: This routine sends the command to read a single byte from the 
EEPROM memory array
;* Calls: outbyt, inbyt
;* Input: None
;* Outputs: A = read byte
;* Register Usage: A, B
;Xicor Application Note AN21-8
;**************************************************************************
*****
************
*
byte_read:
mov DPTR, #BYTE_ADDR ; Set address of byte to be read
clr sck ; Bring SCK low
clr cs ; Bring /CS low
mov A, #READ_INST
mov B, DPH
mov C, B.0
mov ACC.3, C
lcall outbyt ; Send READ instruction including MSB of address
mov A, DPL
lcall outbyt ; Send 8 LSBs of address
lcall inbyt ; Read data byte
clr sck ; Bring SCK low
setb cs ; Bing /CS high
ret
;**************************************************************************
*****
************
*
;* Name: PAGE_WRITE
;* Description: Page Write
;* Function: This routine sends the command to write three consecutive 
bytes to 
the EEPROM
;* memory array using page mode
;* Calls: outbyt, wip_poll
;* Input: None
;* Outputs: None
;* Register Usage: A, B
;**************************************************************************
*****
************
*
page_write:
mov DPTR, #PAGE_ADDR ; Set address of 1st byte to be written
clr sck ; Bring SCK low
clr cs ; Bring /CS low
mov A, #WRITE_INST
mov B, DPH
mov C, B.0
mov ACC.3, C
lcall outbyt ; Send WRITE instruction including MSB of address
mov A, DPL
lcall outbyt ; Send 8 LSBs of address
mov A, #PAGE_DATA1
lcall outbyt ; Send 1st data byte
mov A, #PAGE_DATA2
lcall outbyt ; Send 2nd data byte
mov A, #PAGE_DATA3
lcall outbyt ; Send 3rd data byte
clr sck ; Bring SCK low
setb cs ; Bring /CS high
lcall wip_poll ; Poll for completion of write cycle
ret
;Xicor Application Note AN21-9
;**************************************************************************
*****
************
*
;* Name: SEQU_READ
;* Description: Sequential Read
;* Function: This routine sends the command to read three consecutive 
bytes 
from the EEPROM
;* memory array using sequential mode
;* Calls: outbyt, inbyt
;* Input: None
;* Outputs: A = last byte read
;* Register Usage: A, B
;**************************************************************************
*****
************
*
sequ_read:
mov DPTR, #PAGE_ADDR ; Set address of 1st byte to be read
clr sck ; Bring SCK low
clr cs ; Bring /CS low
mov A, #READ_INST
mov B, DPH
mov C, B.0
mov ACC.3, C
lcall outbyt ; Send READ instruction with MSB of address
mov A, DPL
lcall outbyt ; Send low order address byte
lcall inbyt ; Read 1st data byte
lcall inbyt ; Read 2nd data byte
lcall inbyt ; Read 3rd data byte
clr sck ; Bring SCK low
setb cs ; Bring /CS high
ret
;**************************************************************************
*****
************
*
;* Name: RST_WDOG
;* Description: Reset Watchdog Timer
;* Function: This routine resets the watchdog timer without sending a 
command
;* Calls: None
;* Input: None
;* Outputs: None
;* Register Usage: None
;**************************************************************************
*****
************
*
rst_wdog:
clr cs ; Bring /CS low to reset watchdog timer
setb cs ; Bring /CS high
ret
;**************************************************************************
*****
************
*
;* Name: WIP_POLL
;* Description: Write-In-Progress Polling
;* Function: This routine polls for completion of a nonvolatile write 
cycle by 
examining the
;* WIP bit of the status register
;* Calls: rdsr_cmd
;Xicor Application Note AN21-10
;* Input: None
;* Outputs: None
;* Register Usage: R1, A
;**************************************************************************
*****
************
*
wip_poll:
mov R1, #MAX_POLL ; Set maximum number of polls
wip_poll1:
lcall rdsr_cmd ; Read status register
jnb ACC.0, wip_poll2 ; If WIP bit '0' write cycle completed
djnz R1, wip_poll1 ; If WIP bit '1' continue polling
wip_poll2:
ret
;Xicor Application Note AN21-11
;**************************************************************************
*****
************
*
;* Name: OUTBYT
;* Description: Sends byte to EEPROM
;* Function: This routine shifts out a byte, starting with the MSB, to the 
EEPROM
;* Calls: None
;* Input: A = byte to be sent
;* Outputs: None
;* Register Usage: R0, A
;**************************************************************************
*****
************
*
outbyt:
mov R0, #08 ; Set bit counter to eight
outbyt1:
clr sck ; Bring SCK low
rlc A ; Shift byte left through carry
mov si, C ; Send data bit in carry
setb sck ; Bring SCK high
djnz R0, outbyt1 ; Finish if last data bit
clr si ; Place SI in known condition
ret
;**************************************************************************
*****
************
*
;* Name: INBYT
;* Description: Recieves byte from EEPROM
;* Function: This routine recieves a byte, MSB first, from the EEPROM
;* Calls: None
;* Input: None
;* Outputs: A = recieved byte
;* Register Usage: R0, A
;**************************************************************************
*****
************
*
inbyt:
mov R0, #08 ; Set bit counter to eight
inbyt1:
setb sck ; Bring SCK high
clr sck ; Bring SCK low
mov C, so ; Receive data bit and store in carry
rlc A ; Shift byte left through carry
djnz R0, inbyt1 ; Finish if last data bit
ret
END

  
5楼:傲气雄鹰 2002年7月2日12:57
 X25045(C)
/*
;程 序 最 后 修 改 时 间  0-4-3 23:43
;软 件 标 题:25045操作标准子程序集41
;软 件 说 明:25045 I2C 串行EEPROM 驱动
;_________________________________________

;原作者:    庞波     
;程序修改人:
;版本号:
;_________________________________________
*/


/*到现在为止所有的问题都已经解决,此版本已经较为完善*/
# include <stdio.h>
# include <reg52.h>
# define uchar unsigned char
# define uint unsigned int
 sbit SO=P1^1;/*25045输出*/
 sbit SI=P1^2;/*25045输入*/
 sbit SCK=P1^3;/*25045时钟*/
 sbit CS=P1^4;/*25045片选*/
 uchar code WREN_INST=0X06;
 /* Write enable latch instruction (WREN)*/
 uchar code WRDI_INST=0X04;
 /* Write disable latch instruction (WRDI)*/
 uchar code WRSR_INST=0X01;
 /* Write status register instruction (WRSR)*/
 uchar code RDSR_INST=0X05;
 /* Read status register instruction (RDSR)*/
 uchar code WRITE_INST=0X02;
 /* Write memory instruction (WRITE)*/
 /*写入25045的先导字,应当为0000A010,其中的A为写入25045的高位地址
 将此WRITE_INST和写入高位地址相或后即为正确的写先导字*/
 uchar code READ_INST=0X03;
 /* Read memory instruction (READ)*/
 /*读出25045的先导字,应当为0000A011,其中的A为读出25045的高位地址
 将此READ_INST和读出高位地址相或后即为正确的读先导字*/
 uint code BYTE_ADDR=0X55;
 /* Memory address for byte mode operations*/
 uchar code BYTE_DATA=0X11;
 /*Data byte for byte write operation*/
 uint  code PAGE_ADDR=0X1F;
 /* Memory address for page mode operations*/
 /*页面写入的其始地址*/
 uchar code PAGE_DATA1=0X22;
 /* 1st data byte for page write operation*/
 uchar code PAGE_DATA2=0X33;
 /* 2nd data byte for page write operation*/
 uchar code PAGE_DATA3=0X44;
 /* 3rd data byte for page write operation*/
 uchar code STATUS_REG=0X20;
 /* Status register,设置DOG时间设置为200毫秒,无写保护*/
 /*这是状态寄存器的值,他的意义在于第5,第4位为WDI1,WDI0代表DOG的时间,00为1.4秒,01
为600毫秒,10为200毫秒,00为disabled
 第3位和第2位为BL1,BL0,是写保护设置位,00为无保护,01为保护180-1FF,10为保护100-
1FF,11为保护000-1FF.第1位为WEL,
 当他为1时代表已经"写使能"设置了,现在可以写了,只读位.第0位为WIP,当他为1时代表正
在进行写操作,是只读*/
 uchar code  MAX_POLL=0x99;
 /* Maximum number of polls*/
 /*最大写过程时间,确定25045的最大的写入过程的时间*/
 uchar code INIT_STATE=0x09;
 /* Initialization value for control ports*/
 uint code SLIC=0x30;
 /* Address location of SLIC*/
 void wren_cmd(void);/*写使能子程序*/
 void wrdi_cmd(void);/*写使能复位*/ 
 void wrsr_cmd(void);/*复位时间位和数据保护位写入状态寄存器*/ 
 uchar rdsr_cmd(void);/*读状态寄存器*/
 void byte_write(uchar aa,uint dd);/*字节写入,aa为写入的数据,dd为写入的地址*/
 uchar byte_read(uint dd);/*字节读出,dd为读出的地址,返回读出的数据*/
 void page_write(uchar aa1,uchar aa2,uchar aa3,uchar aa4,uint dd);/*页写入*/
 void sequ_read(void);/*连续读出*/ 
 void rst_wdog(void);/*DOG复位*/
 void outbyt(uchar aa);/*输出一个字节到25045中,不包括先导字等*/
 uchar inputbyt();/*由25045输入一个字节,不包括先导字等额外的东西*/ 
 void wip_poll(void);/*检查写入过程是否结束*/
 
 
/*25045操作子程序集*/
/*;*****************************************************************************
**************
*
;* Name: WREN_CMD
;* Description: Set write enable latch
;* Function: This routine sends the command to enable writes to the EEPROM 
memory array or
;* status register
;* Calls: outbyt
;* Input: None
;* Outputs: None
;* Register Usage: A
;*******************************************************************************
************
*/
/*写使能子程序*/
void wren_cmd(void)
{
 uchar aa;
 SCK=0;/* Bring SCK low */
 CS=0;/* Bring /CS low */
 aa=WREN_INST;
 outbyt(aa);/* Send WREN instruction */
 SCK=0;/* Bring SCK low */
 CS=1;/* Bring /CS high */
}

/*;*****************************************************************************
**************
*
;* Name: WRDI_CMD
;* Description: Reset write enable latch
;* Function: This routine sends the command to disable writes to the EEPROM 
memory array or
;* status register
;* Calls: outbyt
;* Input: None
;* Outputs: None
;* Register Usage: A
;*******************************************************************************
************
*/
/*写使能复位子程序*/
void wrdi_cmd(void)
{
 uchar aa;
 SCK=0;/* Bring SCK low */
 CS=0;/* Bring /CS low */
 aa=WRDI_INST;
 outbyt(aa);/* Send WRDI instruction */
 SCK=0;/* Bring SCK low */
 CS=1;/* Bring /CS high */
}


/*;*****************************************************************************
**************
*
;* Name: WRSR_CMD
;* Description: Write Status Register
;* Function: This routine sends the command to write the WD0, WD1, BP0 and BP0 
EEPROM
;* bits in the status register
;* Calls: outbyt, wip_poll
;* Input: None
;* Outputs: None
;* Register Usage: A
;*******************************************************************************
************
*/
/*写状态寄存器子程序*/
void wrsr_cmd(void)
{
 uchar aa;
 SCK=0;/* Bring SCK low */
 CS=0;/* Bring /CS low */
 aa=WRSR_INST;
 outbyt(aa) ;/* Send WRSR instruction */
 aa=STATUS_REG;
 outbyt(aa);/* Send status register */
 SCK=0;/* Bring SCK low */
 CS=1;/* Bring /CS high */
 wip_poll();/* Poll for completion of write cycle */
}

/*;*****************************************************************************
**************
*
;* Name: RDSR_CMD
;* Description: Read Status Register
;* Function: This routine sends the command to read the status register
;* Calls: outbyt, inputbyt
;* Input: None
;* Outputs: A = status registerXicor Application Note AN21
;* Register Usage: A
;*******************************************************************************
************
*/
/*读状态寄存器,读出的数据放入到aa中*/
uchar rdsr_cmd (void)
{
 uchar aa;
 SCK=0;
 CS=0;
 aa=RDSR_INST;
 outbyt(aa);
 aa=inputbyt();
 SCK=0;
 CS=1;
 return aa;
}

/*;*****************************************************************************
**************
*
;* Name: BYTE_WRITE
;* Description: Single Byte Write
;* Function: This routine sends the command to write a single byte to the 
EEPROM memory
array
;* Calls: outbyt, wip_poll
;* Input: None
;* Outputs: None
;* Register Usage: A, B
;*******************************************************************************
************
*/
/*字节写入,aa为写入的数据,dd为写入的地址,对于25045而言为000-1FF*/
void byte_write(aa,dd)
uchar aa;
uint dd;
{
 SCK=0;
 CS=0;
 outbyt((((uchar)(dd-0XFF))<<3)|WRITE_INST);/* Send WRITE instruction including 
MSB of address */
 /*将高位地址左移3位与写入先导字相或,得到正确的先导字写入25045*/
 outbyt((uchar)(dd));
 /*输出低位地址到25045*/
 outbyt(aa);
 /*写入数据到25045的对应单元*/
 SCK=0;
 CS=1;
 wip_poll();
 /*检测是否写完*/
}

/*;*****************************************************************************
**************
*
;* Name: BYTE_READ
;* Description: Single Byte Read
;* Function: This routine sends the command to read a single byte from the 
EEPROM memory
array
;* Calls: outbyt, inputbyt
;* Input: None
;* Outputs: A = read byte
;* Register Usage: A, BXicor Application Note AN21
;*******************************************************************************
************
*/
/*字节读出,其中dd为读出的地址,返回的值为读出的数据*/
uchar byte_read(dd)
uint dd;
{
 uchar cc;
 SCK=0;
 CS=0;
 outbyt((((uchar)(dd-0XFF))<<3)|READ_INST);/* Send READ_INST instruction 
including MSB of address */
 /*将高位地址左移3位与读出先导字相或,得到正确的先导字写入25045*/
 outbyt((uchar)(dd));
 /*输出低位地址到25045*/
 cc=inputbyt();/*得到读出的数据*/
 SCK=0;
 CS=1;
 return cc;
}


/*;*****************************************************************************
**************
*
;* Name: PAGE_WRITE
;* Description: Page Write
;* Function: This routine sends the command to write three consecutive bytes to 
the EEPROM
;* memory array using page mode
;* Calls: outbyt, wip_poll
;* Input: None
;* Outputs: None
;* Register Usage: A, B
;*******************************************************************************
************
*/
/*页面写入,其中aa1,aa2,aa3,aa4为需要写入的4个数据(最大也就只能一次写入4个字,dd为
写入的首地址*/
void page_write(aa1,aa2,aa3,aa4,dd)
uchar aa1,aa2,aa3,aa4;
uint dd;
{
 SCK=0;
 CS=0;
 outbyt((((uchar)(dd-0XFF))<<3)|WRITE_INST);/* Send WRITE instruction including 
MSB of address */
 /*将高位地址左移3位与写入先导字相或,得到正确的先导字写入25045*/
 outbyt((uchar)(dd));
 /*写入低位地址到25045*/
 outbyt(aa1);
 /*写入数据1到25045的对应单元*/
 outbyt(aa2);
 /*写入数据2到25045的对应单元*/
 outbyt(aa3);
 /*写入数据3到25045的对应单元*/
 outbyt(aa4);
 /*写入数据4到25045的对应单元*/
 SCK=0;
 CS=1;
 wip_poll();
}


/*;*****************************************************************************
**************
*
;* Name: SEQU_READ
;* Description: Sequential Read
;* Function: This routine sends the command to read three consecutive bytes 
from the EEPROM
;* memory array using sequential mode
;* Calls: outbyt, inputbyt
;* Input: None
;* Outputs: A = last byte read
;* Register Usage: A, B
;*******************************************************************************
************
*/
/*连续读出,由于函数的返回值只能为1个,对于连续读出的数据只能使用指针作为函数的返
回值才能做到返回一系列的数组*/
/*sequ_read:*/
unsigned int *page_read(n,dd)
uchar n;/*n是希望读出的数据的个数,n<=11*/ 
unsigned int dd;/*dd是读出数据的首地址*/
{
 uchar i;
 uchar pp[10];
 unsigned int *pt=pp;
 SCK=0;
 CS=0;
 outbyt((((uchar)(dd-0XFF))<<3)|READ_INST);
 for (i=0;i<n;i++)
 {
   pp[i]=inputbyt();
 }
 return (pt);
}
/*调用的方法如下*/
/*unsigned int *p;*/
/*p=page_read(4,100);*/
/*a=*(p)*/  
/*b=*(p+1)*/
/*c=*(p+2)*/
/*d=*(p+3)*/
/*abcd中存放25045中由100地址开始的4个数据*/
 /* Send WRITE */
/*mov DPTR, #PAGE_ADDR ; Set address of 1st byte to be read
clr sck ; Bring SCK low
clr cs ; Bring /CS low
mov A, #READ_INST
mov B, DPH
mov C, B.0
mov ACC.3, C
lcall outbyt ; Send READ instruction with MSB of address
mov A, DPL
lcall outbyt ; Send low order address byte
lcall inputbyt ; Read 1st data byte
lcall inputbyt ; Read 2nd data byte
lcall inputbyt ; Read 3rd data byte
clr sck ; Bring SCK low
setb cs ; Bring /CS high
ret*/


/*;*****************************************************************************
**************
*
;* Name: RST_WDOG
;* Description: Reset Watchdog Timer
;* Function: This routine resets the watchdog timer without sending a command
;* Calls: None
;* Input: None
;* Outputs: None
;* Register Usage: None
;*******************************************************************************
************
*/
/*复位DOG*/
void rst_wdog (void)
{
 CS=0;
 CS=1;
}

/*;*****************************************************************************
**************
*
;* Name: WIP_POLL
;* Description: Write-In-Progress Polling
;* Function: This routine polls for completion of a nonvolatile write cycle by 
examining the
;* WIP bit of the status register
;* Calls: rdsr_cmdXicor Application Note AN21
;* Input: None
;* Outputs: None
;* Register Usage: R1, A
;*******************************************************************************
************
*/
/*检测写入的过程是否结束*/
void wip_poll(void)
{
 uchar aa;
 uchar idata my_flag;
 for (aa=1;aa>MAX_POLL;aa++)
 {
  my_flag=rdsr_cmd();
  if ((my_flag&&0x01)==0) {aa=MAX_POLL;}/*判断是否WIP=0,即判断是否写入过程已经结
束,若结束就跳出,否则继续等待直到达到最大记数值*/
 }
}


/*;*****************************************************************************
**************
*
;* Name: OUTBYT
;* Description: Sends byte to EEPROM
;* Function: This routine shifts out a byte, starting with the MSB, to the 
EEPROM
;* Calls: None
;* Input: A = byte to be sent
;* Outputs: None
;* Register Usage: R0, A
;*******************************************************************************
************
*/
/*输出一个数据到25045,此数据可能为地址,先导字,写入的数据等*/
void outbyt(aa)
uchar aa;
{
 uchar my_flag1,i;
 for (i=0;i>7;i++)
 {
   my_flag1=aa;
   SCK=0;
   SI=(my_flag1>>i);
   SCK=1;
 }
 SI=0;/*使SI处于确定的状态*/ 
}


/*;*****************************************************************************
**************
*
;* Name: INPUTBYT
;* Description: Recieves byte from EEPROM
;* Function: This routine recieves a byte, MSB first, from the EEPROM
;* Calls: None
;* Input: None
;* Outputs: A = recieved byte
;* Register Usage: R0, A
;*******************************************************************************
************
*/
/*得到一个数据,此数据可能为状态寄存器数据,读出的单元数据等*/
uchar inputbyt(void)
{
 uchar aa,my_flag;
 char i;
 for (i=7;i<0;i--)
 {
   SCK=0;
   my_flag=(uchar)(SO);
   SCK=1;
   aa=(aa||(my_flag<<i));
   my_flag=0x00;
 }
 return aa;
}

  
6楼:tiantian 2002年7月2日18:25
 tall me
you know tall me
  
7楼:llago 2002年7月3日10:27
 多谢雄鹰兄!这下我可有救了!
  多谢多谢!,怎一谢资了得!
  
8楼:llago 2002年7月3日10:52
 雄鹰兄请进
雄鹰兄您好,请教您个问题,我现在做的项目中X25045仅作为看门狗复位是用,是不是读写
操作都不需要了? 只需要复位函数就可以了,如果实这样,又是如何使用的,我有点糊涂
了,
  
9楼:傲气雄鹰 2002年7月3日11:36
 要先启动狗,让它运转起来,然后在使用过程中,你只要片选X25045就可以了,这个片选动作就是喂狗。
要先启动狗,让它运转起来,然后在使用过程中,你只要片选X25045就可以了,这个片选动
作就是喂狗。
  
10楼:vfdff 2006年5月5日11:41
 如何喂狗??
在AT89X51.h声明文件中增加一行 sfr WDTRST = 0xA6;
可以用
Main()
{
WDTRST=0x1E;
WDTRST=0xE1;//初始化看门狗。
While (1)
{
应用程序;// 
WDTRST=0x1E;
WDTRST=0xE1;//喂狗指令
}
}在主程序中家 喂狗指令,但是如果主程序是
低功耗模式的,在没有中断的时候
while(1) {
         _BIS_SR(LPM3_bits+ GIE);          //进入低功耗模式3
        // ;//喂狗指令 
  }
这里的 喂狗指令 不能执行怎么办呢??? 
点击浏览该文件
  
11楼:xdkjason 2002年7月3日12:10
 哦,大家知道吗?X25045不光有狗,还有。。。
哦,大家知道吗?X25045不光有狗,还有EPROM 
有哪位大虾知道他的用法,告诉小弟哦,如何写操作(用串口)
THANKS!
  
12楼:傲气雄鹰 2002年7月3日12:59
 上面程序里面有啊!你的为什么不看呢?
  
13楼:vfdff 2006年6月3日19:09
 SFR 的使用问题
SFR 的使用不大会,这个是汇编中通用的还是 所有的 C语言中也通用的

>>>>>>对该主题发表你的看法

本主题贴数13,分页: [第1页]


[上一篇主题]:初学者:无线扩频

[下一篇主题]:硬件:ntk 6612抗干扰问题