Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Using AT93C56A as EEPROM with 89c51

Status
Not open for further replies.

Reborn121

Newbie level 5
Newbie level 5
Joined
Jun 29, 2010
Messages
8
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
united states
Activity points
1,340
I need to write a simple program to erase, read, and write a value in assembly language using the EEPROM AT93C56A with the 89c51RB2...can anyone help me get started please? This is really urgent! Thank you for any assistance.
 

Here are working subs for the 93C06, and as the 93C56 belongs to the same family, this may be a good starting point ..

Code:
; Reads and writes 93C06
; P1.0		=		EEProm CS
; P1.1		=		EEProm Clk
; T0			=		EEProm Din/Dout


; EEPROM routines summmary:


;			E_Read...reads a byte from EEProm of a given address...
;			E_Write...writes a byte to EEProm to a given address...
;			Ee_Rd_8b...reads a byte from EEProm at given location
;			Ee_Wr_8b...writes a byte to EEProm at given location...
;			Ee_Clock...time delay for EEloops...

; This reads a byte from EEprom at a given location..

E_Read:		SETB	EECs			; CS is ON...
			LCALL	Ee_Clock
			SETB	EEDin			; DI is H...
			LCALL	Ee_Clock
			MOV	A, EEAddress
			ANL	A, #3Fh
			ORL	A, #80h		; Code and address for read...
			LCALL	Ee_Wr_8b		; Send address...
			LCALL	G_Time
			LCALL	Ee_Rd_8b		; Read a byte..
			CLR	EECs			; CS is OFF...
			RET

; This writes a byte to EEProm..

E_Write:		SETB	EECs				; CS is on..
			LCALL	Ee_Clock
			SETB	EEDin				; Din goes H
			LCALL	Ee_Clock
			MOV	A, #30h			; Code for WE = 11
			LCALL	Ee_Wr_8b
			CLR	EEDin
			CLR	EECs

			LCALL	G_Time

			SETB	EECs
			LCALL	Ee_Clock
			SETB	EEDin
			LCALL	Ee_Clock
			MOV	A, EEAddress
			ANL	A, #1Fh			; 0011 1111
			ORL	A, #40h
			LCALL	Ee_Wr_8b			; Send code and 6bit address to EE
			MOV	A, EEData
			LCALL	Ee_Wr_8b
			CLR	EEDin
			CLR	EECs

			LCALL	G_Time

			SETB	EECs
			JNB	EEDout, $
			CLR	EECs

			LCALL	G_Time

			SETB	EECs				; CS is on..
			LCALL	Ee_Clock
			SETB	EEDin				; Din goes H
			LCALL	Ee_Clock
			MOV	A, #00h			; Code for WDis = 00
			LCALL	Ee_Wr_8b
			CLR	EEDin
			CLR	EECs
			RET

; This reads 8 bits from EEProm...

Ee_Rd_8b:		MOV	R7, #08h
Ee_R_Loop:		LCALL	Ee_Clock
			MOV	C, EEDout
			RLC	A
			DJNZ	R7, EE_R_Loop
			MOV	R7, #7Fh
Rd_T_Loop:		NOP
			NOP
			DJNZ	R7, Rd_T_Loop
			RET

; This writes 8 bits to EEProm...

Ee_Wr_8b:		MOV	R7, #08h
Ee_8_Loop:		RLC	A
			MOV	EEDin, C
			LCALL	Ee_Clock
			DJNZ	R7, Ee_8_Loop
			CLR	EEDin
			MOV	R7, #7Fh
Wr_T_Loop:		NOP
			NOP
			DJNZ	R7, Wr_T_Loop
			RET

; EE_Clock time delay...

Ee_Clock:		SETB	EEClk
			MOV	R6, #10h
Ee_H_Loop:		NOP
			NOP
			NOP
			NOP
			DJNZ	R6, Ee_H_Loop
			CLR	EEClk
G_Time:		MOV	R6, #10h
Ee_L_Loop:		NOP
			NOP
			NOP
			NOP
			DJNZ	R6, Ee_L_Loop
			RET

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

IanP
:D
 

Thanks for your post...i have tried to get as much code together as i could for my application...my specific requirements are to erase the EEPROM, read a value in variable EEADR and store in EEBYT then output the value to port 2 of the micro. Can anyone tell me if im on the right track or offer suggestions,,i know its not complete? Thanks


Code:
.equ sk, p1.0    ;serial clock
.equ di, p1.1    ;data input
.equ do, p1.2    ;data output
.equ cs, p1.3    ;chip select
;__________________________________________

         Mov SCON, #50H       ;serial mode
	 Mov TMOD, #20H       ;timer1 mode2

;__________________________________________

;Read a byte from EEPROM
;__________________________________________

Read:    SETB   cs             ;cs is set
         LCALL  Clock
         SETB   di             ;di is set
         LCALL  Clock
         MOV    A, EEADR
         ANL    A, #3Fh
         ORL    A, EEBYT       ;code and address for read
         LCALL  wr_byt         ;send address
         LCALL  Time
         LCALL  rd_byt         ;read a byte
         CLR    cs             ;cs is set
         RET                   ;return
;___________________________________________
         

;Write byte to EEPROM 
;__________________________________________   

Write:   SETB   cs             ;cs is set
         LCALL  Clock
         SETB   di             ;di is set
         LCALL  Clock
         MOV   A, #30h        
         LCALL   wr_byt
         CLR   di              ;clear di
         CLR   cs              ;clear cs

         LCALL  Time

         SETB   cs             ;cs is set
         LCALL  Clock
         SETB   di             ;di is set
         LCALL  Clock
         MOV    A, EEADR
         ANL    A, #1Fh         
         ORL    A, #40h
         LCALL  wr_byt      
         MOV    A, EEBYT
         LCALL  wr_byt
         CLR    di             ;clear di
         CLR    cs             ;clear cs

         LCALL Time

         SETB  cs              ;cs is set
         JNB   do, $
         CLR   cs              ;clear cs

         LCALL  Time

         SETB   cs             ;cs is set
         LCALL  Clock
         SETB   di             ;di is set
         LCALL  Clock
         MOV    A, #00h         
         LCALL  wr_byt
         CLR    di             ;clear di
         CLR    cs             ;clear cs
         RET                   ;return
;____________________________________________________________

;Clock time delay
;____________________________________________________________

Clock:   SETB  sk              ;clock is set
         MOV   R6, #10h        ;move 10 hex into reg 6

H_Loop:  NOP
         NOP
         NOP
         NOP
         DJNZ  R6, H_Loop
         CLR   sk              ;clear clock

L_Loop:  NOP
         NOP
         NOP
         NOP
         DJNZ  R6, L_Loop
         RET                    ;return

Time:    Mov R6,#10H
;____________________________________________________________
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top