⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 close_dog.asm

📁 关掉5045的看门狗功能及对其操作的子程序
💻 ASM
字号:
;close dog_x5045,if ok then runled,else not runled
runled          bit  p1.4
cs_wdt	        bit  p1.3    ;看门狗片选
so	        bit  p1.0    ;串行数据输出
sck	        bit  p1.2    ;串行时钟输入
si              bit  p1.1    ;串行数据输入
;看门狗特征字定义区
x_wren_inst	equ  06h		;wirte enable latch instruction(wren)
x_wrdi_inst	equ  04h		;write disable latch instruction(wrdi)
x_wrsr_inst	equ  01h		;write status register instruction(wrsr)
x_rdsr_inst	equ  05h		;read status register instruction(rdsr)
x_write_inst	equ  02h		;write memory instruction(write)
x_read_inst	equ  03h		;read memory instruction(read)
x_byte_data	equ  08h		;data byte for byte write operation
x_page_data	equ  09h		;Page data for page write or read operation
				;used 15h,16h,17h,18h 4 cells
x_page_addr	equ  0ah		;memory address for page mode operation
				;2 bytes address used 13h 14h cells
x_byte_addr	equ  0ch		;memory address for byte mode operations
				;use 0ch,0dh 2 cells

x_status_reg	equ  00h		;status register
x_max_poll	equ  99h		;maximum number of polls

        org   0000h
	ljmp  start
	org   0003h                    ;外部中断0入口
        reti 
        org   000bh                    ;定时器T0入口
        reti
        org   0013h                    ;外部中断1入口
        reti 
        org   001bh                    ;定时器T1入口
        reti
        org   0023h                    ;串行口中断入口
        reti
        org   002bh                    ;定时器T2入口
        reti

        org   0040h
start:
        mov   sp,#6fh
        mov   p0,#0ffh
        mov   p1,#0ffh
        mov   p2,#0ffh
        mov   p3,#0ffh
        lcall dis_wdog           ;close the watchdog
        clr   runled
        ljmp  $        

;-------------------------------------
; X5045看门狗操作,读、写程序
;-------------------------------------
;---------------------------------------------------------
;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: x_outbyt
;Input: None
;Outputs: None
;Register Usage: A
;

x_wren_cmd:
	clr   sck
	clr   cs_wdt
        nop   ; debug
        nop   ; debug
	mov   a,#x_wren_inst
	lcall x_outbyt
;        nop   ; debug
        nop   ; debug
	clr   sck
	setb  cs_wdt
	ret

;-------------------------------------------------------------
;Name: x_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: x_outbyt
;Input: None
;Outputs: None
;Register: A
;

x_wrdi_cmd:
	clr   sck
	clr   cs_wdt
	mov   a,#x_wrdi_inst
	lcall x_outbyt
	clr   sck
	setb  cs_wdt
	ret

;----------------------------------------------------------------
;Name: x_wrsr_cmd
;Description: Write Status Register
;Function: This routine sends the command to write the WD0, BP0 and BP0
;	   EEPROM bits in the status register
;Calls: x_outbyt,x_wip_poll
;Input: None
;Outputs: None
;Register usage: A
;

x_wrsr_cmd:
	lcall x_wren_cmd
	clr   sck
	clr   cs_wdt
	mov   a,#x_wrsr_inst
	lcall x_outbyt
	mov   a,#x_status_reg
	lcall x_outbyt
	clr   sck
	setb  cs_wdt
	lcall x_wip_poll
	ret

;--------------------------------------------------------------------------
;Name: x_rdsr_cmd
;Description: Read Status Register
;Function: This routine sends the command to read the status register
;Calls: x_outbyt,x_inbyt
;Input: None
;Outputs: A = status register
;Register usage: A
;

x_rdsr_cmd:
	clr   sck
	clr   cs_wdt
	mov   a,#x_rdsr_inst
	lcall x_outbyt
	lcall x_inbyt
	clr   sck
	setb  cs_wdt
	ret

;-----------------------------------------------------------------------
;Name: x_byte_write
;Description: single Byte Write
;Function: This routine sends the command to write a single byte to the
;	   EEPROM memory array
;Calls: x_outbyt,x_wip_poll
;Input: None
;Outputs: None
;Register usage: A,B
;----------------

x_byte_write:
	push  dph
	push  dpl
	mov   dph,x_byte_addr
	mov   dpl,x_byte_addr+1
	clr   sck
	clr   cs_wdt
        nop                           ; debug
        nop                           ; debug
	mov   a,#x_write_inst
	mov   b,dph
	mov   c,b.0
	mov   acc.3,c
	lcall x_outbyt
	mov   a,dpl
	lcall x_outbyt
	mov   a,x_byte_data		;byte write buffer 11h
	lcall x_outbyt
	clr   sck
	setb  cs_wdt
	lcall x_wip_poll
	pop   dpl
	pop   dph
	ret

;--------------------------------------------------------------------
;Name: x_byte_read
;Description: single byte read
;Function: This routine sends the command to read a single byte from the
;	   EEPROM memory array
;Calls: x_outbyt,x_inbyt
;Input: None
;Outputs: A = read byte
;Register usage: A,B
;

x_byte_read:
	push  dph
	push  dpl
	mov   dph,x_byte_addr
	mov   dpl,x_byte_addr+1
	clr   sck
	clr   cs_wdt
	mov   a,#x_read_inst
	mov   b,dph
	mov   c,b.0
	mov   acc.3,c
	lcall x_outbyt
	mov   a,dpl
	lcall x_outbyt
	lcall x_inbyt
	clr   sck
	setb  cs_wdt
	pop   dpl
	pop   dph
	ret

;------------------------------------------------------------------
;Name: x_page_write
;Description: This routine sends the command to write three consecutive bytes
;	      to the EEPROM memory array using page mode
;Calls: x_outbyt,x_wip_poll
;Input: None
;Outputs: None
;Register usage: A,B
;

x_page_write:
	mov   dph,x_page_addr
	mov   dpl,x_page_addr+1
	clr   sck
	clr   cs_wdt
	mov   a,#x_write_inst
	mov   b,dph
	mov   c,b.0
	mov   acc.3,c
	lcall x_outbyt
	mov   a,dpl
	lcall x_outbyt
	mov   a,x_page_data
	lcall x_outbyt
	mov   a,x_page_data+1
	lcall x_outbyt
	mov   a,x_page_data+2
	lcall x_outbyt
	mov   a,x_page_data+3
	lcall x_outbyt
	clr   sck
	setb  cs_wdt
	lcall x_wip_poll
	ret

;-----------------------------------------------------------------
;Name: x_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: x_outbyt,x_inbyt
;Input: None
;Outputs: A = last byte read
;Register usage: A,B
;

x_sequ_read:
	mov   dph,x_page_addr
	mov   dpl,x_page_addr+1
	clr   sck
	clr   cs_wdt
	mov   a,#x_read_inst
	mov   b,dph
	mov   c,b.0
	mov   acc.3,c
	lcall x_outbyt
	mov   a,dpl
	lcall x_outbyt
	lcall x_inbyt			;Read 1st byte
	mov   x_page_data,a
	lcall x_inbyt			;Read 2nd byte
	mov   x_page_data+1,a
	lcall x_inbyt			;Read 3rd byte
	mov   x_page_data+2,a
	lcall x_inbyt			;read 4th byte
	mov   x_page_data+3,a
	clr   sck
	setb  cs_wdt
	ret

;-------------------------------------------------------------
;Name: x_rst_wdog
;Description: Reset WatchDog Timer
;Function: This routine resets the watchdog timer without sending a commmand
;Calls: None
;Input: None
;Outputs: None
;Register usage: None
;

x_rst_wdog:
	clr   cs_wdt
        nop ; debug
        nop ; debug
        nop ; debug
        nop ; debug
	setb  cs_wdt
	ret

;---------------------------------------------------------------
;Name: x_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: x_rdsr_cmd
;Input: None
;Outputs: None
;Register usage: R1,A

x_wip_poll:
	mov   r1,#x_max_poll
x_wip_poll1:
	lcall x_rdsr_cmd
	jnb   acc.0,x_wip_poll2
	djnz  r1,x_wip_poll1
x_wip_poll2:
	ret

;------------------------------------------------------------------
;Name: x_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
;

x_outbyt:
	mov   r0,#08
x_outbyt1:
        nop ; debug
        nop ; debug
	clr   sck
	rlc   a
	mov   si,c
        nop ; debug
        nop ; debug
	setb  sck
	djnz  r0,x_outbyt1
	clr   si
;        nop ; debug
 ;       nop ; debug
	ret

;----------------------------------------------------------------
;Name: x_inbyt
;Description: Receives byte from EEPROM
;Function: This Routine receives a byte, MSB first, from the EEPROM
;Calls: None
;Input: None
;Outputs: A = received byte
;Register usage: R0,A
;

x_inbyt:
	mov   r0,#08
x_inbyt1:
	clr   sck
        nop  ; debug
        nop  ; debug
        setb  sck
        nop ; debug
        nop ; debug
	mov   c,so
	rlc   a
	djnz  r0,x_inbyt1
	ret

;--------------------------------------------------------
;======================================================================

x045_init:
	mov   r0,#128
	mov   x_page_data,#00h
	mov   x_page_data+1,#00h
	mov   x_page_data+2,#00h
	mov   x_page_data+3,#00h
	mov   x_page_addr,#00h
	mov   x_page_addr+1,#00h
x045_i_1:
	push  00
	lcall x_wren_cmd
	lcall x_page_write
	mov   a,x_page_addr+1
	jnc   x045_i_2
	inc   x_page_addr
x045_i_2:
	mov   x_page_addr+1,a
	pop   00
	djnz  r0,x045_i_1
	mov   x_page_addr,#00
	mov   x_page_addr+1,#00
	ret

;------------------------------------------------
dis_wdog:
	lcall x_wren_cmd
	clr   sck
	clr   cs_wdt
	nop
	nop
	mov   a,#x_wrsr_inst
	lcall x_outbyt
	mov   a,#30h
	lcall x_outbyt
	clr   sck
	setb  cs_wdt
	lcall x_wip_poll
	ret

;===========================================

        END

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -