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

📄 eeprom.mac

📁 calculator code ,use toshibaor nec LSI
💻 MAC
📖 第 1 页 / 共 2 页
字号:
	$nolist
;*******************************************************************************
;*******************************************************************************
;*                                                                             *
;*              (C)Copyright, CLOVER China Electronics Co.,LTD.                *
;*                          All Rigits Reserved                                *
;*   add:No.58-F Yang Dong Road, LuoFeng Demonstrative Zone Suzhou, China      *
;*                    Tel: 0512-67261886 Fax:0512-67261882                     *
;*                        http://www.clover.co.jp                              *
;*                                                                             *
;*******************************************************************************
;*******************************************************************************
;
;		OBS CPD3212T source program
;		CPU: TOSHIBA TLC-870/C series TMP86CM74A
;		RAM: 2Kbytes(0040h - 083Fh)
;		ROM: 32Kbytes(8000h - FFFFh)
;
;
;=======================================================================
;Sub routines

	?trigger(@)
	@include	"symdef_ram.inc"
	@include	"symdef_sub.inc"
	@include	"macro.inc"
	@include	"define.inc"
	public	ee_to_euro1,ee_to_euro2,ee_to_tax,ee_to_ten,ee_to_wkreg,eeprom_check
	public	w2_to_ee,w2_to_eetx,w2_to_eetx2
	public	country_to_ee,ee_country_read,rate_init_check,ee_rate_init
	public	ee_to_tax2 ;V2.05,euro_country_set
	public	euro_fix_rate_tbl
	extern	init_keybuf,wait_100ms,key_get	;V2.04
	$list
;================================================
;P0DR port
EP_CS	equ	7	;P07
EP_SK	equ	6	;P06
EP_DIO	equ	5	;P05

RATE_L		equ	4	;constant
EE_TEST1	equ	0x00
EE_COUNTRY	equ	0x01	;save country code
EE_EU1		equ	0x02	
EE_EU2		equ	EE_EU1+RATE_L	
EE_EU3		equ	EE_EU2+RATE_L	
EE_EU4		equ	EE_EU3+RATE_L	
EE_EU5		equ	EE_EU4+RATE_L
EE_EU6		equ	EE_EU5+RATE_L
EE_EU7		equ	EE_EU6+RATE_L
EE_EU8		equ	EE_EU7+RATE_L
EE_EU9		equ	EE_EU8+RATE_L
EE_EU10		equ	EE_EU9+RATE_L
EE_EU11		equ	EE_EU10+RATE_L
EE_EU12		equ	EE_EU11+RATE_L
EE_EU13		equ	EE_EU12+RATE_L
EE_TAX		equ	EE_EU13+RATE_L
EE_TAX2		equ	EE_TAX+RATE_L
EE_TEST2	equ	EE_TAX2+RATE_L
;================================================
ROM	section code
;=========================================================================
@define(DIR_OUT)(
		set	(P0CR).EP_DIO	;as output port
		clr	(P0DR).EP_DIO	;
)		
;-----------------------------------------------------------------
@define(DIR_IN)(	
		clr	(P0CR).EP_DIO	;P17 as inupt port
		set	(P0DR).EP_DIO
)
;==========================================================================
@define(CS_EQU_1)(
	set	(P0DR).EP_CS
)
;-----------------------------
@define(CS_EQU_0)(
	clr	(P0DR).EP_CS
)
;-----------------------------
@define(SK_EQU_1)(
	set	(P0DR).EP_SK
)
;-----------------------------
@define(SK_EQU_0)(
	clr	(P0DR).EP_SK
)
;-----------------------------
@define(DIO_EQU_1)(
	set	(P0DR).EP_DIO
)
;-----------------------------
@define(DIO_EQU_0)(
	clr	(P0DR).EP_DIO
)
;-----------------------------
@define(ACCES_ON)(
	set	(FLG_2).4
)
;-----------------------------
@define(ACCES_OFF)(
	clr	(FLG_2).4
)
;-----------------------------
EETIM	equ	30	;v1.20
;========================================================================
;EEPROM 93LC46 1024bit (128 Bytes)
;request: Tcs > 250ns;  Tsk < 1MHz;  Tdio > 100ns
;EEPROM instruction code
;READ			10AAAAAA
;Write Enable		0011xxxx
;WRITE			01AAAAAA
;Write All Register	0001xxxx
;Write Disable		0000xxxx
;ERASE			11AAAAAA
;Erase All Register	0010xxxx
;data flow:------------------------------------------
;write: 16bit data in bc--->a--->EEPROM
;read:  16bit data in EEPTROM--->a--->bc
;used general register: w,a,bc,de
;=========================================================================
ee_enable:	;instruction 0011xxxx send to EEPROM
		@ACCES_ON	;set flag for EEPROM is busying	
		@DIR_OUT	;EP_DIO difined as output
		nop		;V1.34
		nop		;V1.34
		nop		;V1.34
		@CS_EQU_1	;
		call	ee_wait_10_nop	;V1.34
		call	high_out	;outpu high level from port EP_DIO; start bit is high
		ld	a,0y00110000	;instructin Write Enable
		call	data_out
		@CS_EQU_0
		nop		;V1.34
		nop		;V1.34
		nop		;V1.34
		@DIR_OUT		;EP_DIO difined as output
		nop
		@ACCES_OFF		
		ret
;=====================================================
ee_disable:	;instruction 0000xxxx send to EEPROM
		@ACCES_ON		;set flag for EEPROM is busying	
		@DIR_OUT
		nop		;V1.34
		nop		;V1.34
		nop		;V1.34
		@CS_EQU_1
		call	ee_wait_10_nop	;V1.34
		call	high_out	;;outpu high level from port EP_DIO; start bit is high
		ld	a,0y00000000
		call	data_out
		@CS_EQU_0
		nop		;V1.34
		nop		;V1.34
		nop		;V1.34
		nop		;V1.34
		@DIR_OUT			;Low level fix
		nop
		@ACCES_OFF		;
		ret
;=====================================================
high_out:	;output high level from port EP_DIO	
		@DIO_EQU_1	;
		call	ee_wait_10_nop	;V1.34
		@SK_EQU_1		;CS	HHHHHHHHHHH
		call	ee_wait_10_nop	;V1.34
		nop			;SK	_HHHHHH____
		nop			;DIO	___HHH_____
		@SK_EQU_0		;
		nop			;
		nop
		ret			;
;=====================================================
low_out:	;output low level from port EP_DIO
		@DIO_EQU_0	;
		call	ee_wait_10_nop	;V1.34
		nop			;CS	HHHHHHHHHHH
		nop			;SK	_HHHHHH____
		@SK_EQU_1		;DIO	___________
		call	ee_wait_10_nop	;V1.34
		@SK_EQU_0		;
		nop			;
		nop
		ret			;
;=====================================================
data_out:	;8bit data in register "a" sent to EEPROM bit by bit
		ld	w,7		;
data_out0:				;
		shlc	a		;CS	HHHHHHHHHHHHHHHHHHHHHHHH
		j	cc,data_out2	;SK	_HHH__HHH__HHH_//_HHH_
		call	high_out	;DO	__XXXXXXXXXXXXX//XXXX__
		jp	data_out4	;
data_out2:				;
		call	low_out		;
data_out4:				;
		dec	w		;
		jr	f,data_out0	;
		ret			;
;=====================================================
data_in:	;read 8bit data from EEPRM and save into register "a" bit by bit
		ld	w,7		;
data_in0:				;
		@SK_EQU_1		;
		nop
		nop
		nop
		@DIR_IN
		call	ee_wait_10_nop	;V1.34
		test	(P0DR).EP_DIO
		j	t,data_in1	;judge the port EP_DIO is high or low.
		set	cf		;is high
		jp	data_in2	;
data_in1:				;
		clr	cf		;is low
data_in2:				;
		rolc	a		;16bit data read into register wa
		@SK_EQU_0		;CS	HHHHHHHHHHHHHHHHHHHHHHHH
		call	ee_wait_10_nop	;V1.34
		nop			;SK	_HHH__HHH__HHH_//_HHH_
		nop			;DO	__XXXXXXXXXXXXX//XXXX__-->C-->register a
		dec	w		;
		jr	f,data_in0	;
		ret			;
;=====================================================
ee_write:	;the data in register b(high 8bit)c(low 8bit)-->EEPROM
		;                        xxxxxxxx xxxxxxxx
		@ACCES_ON	;set flag for EEPROM is busying		
		ld	w,3
ee_write_x:
		push	w	;V1.05
		@DIR_OUT
		nop		;V1.34
		nop		;V1.34
		nop		;V1.34
		nop		;V1.34
		ld	de,bc		;backup bc in de
		@CS_EQU_1
		nop
		nop
		nop
		nop
		nop
		call	high_out	;start bit is high level
		ld	a,(EP_ADDR)	;EPROM address-->a
		and	a,0y00111111	;EEPROM address only from 00-->63
		or	a,0y01000000	;write instruction is 01xxxxxx
		call	data_out	;instruction for write and address send to EEPROM
		ld	a,b		;the data in c-->a
		call	data_out	;a-->EEPROM
		ld	a,c		;the data in b-->a
		call	data_out	;a-->EEPROM
		@DIO_EQU_0
		call	ee_wait_10_nop	;V1.34
		nop		;V1.34
		nop		;V1.34
		nop		;V1.34
		@CS_EQU_0
		call	ee_wait_10_nop	;V1.34
		@DIR_IN		;set EP_DIO as input port for chect STOP flag
		call	ee_wait_10_nop	;V1.34
		@CS_EQU_1
		call	ee_wait_10_nop	;V1.34
		ld	(EP_TIM),EETIM	;set time for waiting STOP signal. dec EP_TIM in timer interrupt
ee_write0:
		@DIR_IN			;V1.05
		nop
		test	(P0DR).EP_DIO
		j	f,ee_write1		;STOP flag received? yes-->
		ld	a,(EP_TIM)		;not receive STOP flag
		j	ne,ee_write0
		@SEB	(EP_FAIL)		;time out -> fail
		@CS_EQU_0	;V1.34
		@DIR_OUT		;Low level fix
		@ACCES_OFF	
		pop	w	;V1.05
		ret
ee_write1:	;
		@CS_EQU_0		;write into EEPROM finish
		call	ee_wait_10_nop	;V1.34
		call	ee_read		;16bit data read into bc
		pop	w	;V1.05
		cmp	bc,de		;the data read (bc) is same as write (de)
		j	eq,ee_write9
ee_write5:	
		dec	w	; if compare the data is different,double sure by retry write--read 3 times
		j	eq,ee_write8	;
		ld	bc,de		;resume de to bc 
		jp	ee_write_x	;
ee_write8:
		@SEB	(EP_FAIL)	;set flag for EEPROM write fail
ee_write9:
		@ACCES_OFF	;write action finish
		ret
;===========================================================
;;read from EEPROM and save into register bc
;===========================================================
ee_read:		
		@ACCES_ON		;
		ld	(EP_TIM),EETIM
ee_read_0:
		@DIR_OUT
		nop		;V1.34
		nop		;V1.34
		nop		;V1.34
		@CS_EQU_1		;CS output high viltage
		call	ee_wait_10_nop	;V1.34
		call	high_out	;start bit output
		ld	a,(EP_ADDR)	;
		and	a,0y00111111	;address from 0~63
		or	a,0y10000000	;instruction read from EEPROM: 10xxxxxx
		call	data_out	;output read instruction and address
		@DIO_EQU_0
		nop		;V1.34
		nop		;V1.34
		nop		;V1.34
		@DIR_IN			;set EP_DIO as input port
		call	data_in		;16bit data readed from EEEPROM and save in b,c
		ld	b,a		;D8~D15 saved in regiser c
		call	data_in
		ld	c,a		;D0~D7 saved inregister b
		@CS_EQU_0
		call	ee_wait_10_nop	;V1.34
;read one time again
		@DIR_OUT		;
		nop		;V1.34
		nop		;V1.34
		nop		;V1.34
		@CS_EQU_1
		call	ee_wait_10_nop	;V1.34
		call	high_out
		ld	a,(EP_ADDR)
		and	a,0y00111111
		or	a,0y10000000
		call	data_out
		@DIO_EQU_0

⌨️ 快捷键说明

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