$TITLE(MCS-51 / XICOR X2444 NOVRAM Serial port Interface Routines) WRDS equ 80H ; Reset write enable latch STO equ 0C0H ; Store into EEPROM SLEEP equ 0A0H ; Enter sleep mode WRITE equ 0E0H ; Write data to RAM WREN equ 90H ; Set write enable latch RCL equ 0D0H ; Recall from EEPROM READ equ 0F0H ; Read data from RAM %OUT(Enter port pin connected to the CE of the NOVRAM) NOVRAM_enable bit %IN ; Port bit to enable NOVRAM chip Novram_internal_data_bytes segment DATA RSEG Novram_internal_data_bytes address_register: DS 1 ; data byte to select RAM location data_high: DS 1 ; MSB of 16 bit data data_low: DS 1 ; LSB of 16 bit data command: DS 1 ; NOVRAM instruction byte $eject Novram_interface_routines segment CODE RSEG Novram_interface_routines Init_NOVRAM: MOV SCON,#00010010B ; Initialise the serial port ; ||||||||__________ clear receive flag ; |||||||___________ set transmit flag ; ||||||____________ clear the 9th bits ; ||||______________ enable serial reception ; |||_______________ set to 0 in Mode 0 ; ||________________ select Mode 0, shift register CLR NOVRAM_enable ; deselect NOVRAM RET NOVRAM: SETB NOVRAM_enable ; select chip MOV A,address_register ; start assembling instruction ANL A,#0FH ; with address ORL A,command ; add in command bits JB ACC.5,NOVRAM_1 ; is data transfer needed? NOVRAM_0: ; NO, JNB TI,$ ; write out command CLR TI MOV SBUF,A JNB TI,$ ; wait for transmission to complete NOVRAM_00: CLR NOVRAM_enable ; deselect chip RET ; and return NOVRAM_1: ; YES, JNB ACC.6,NOVRAM_0 ; except for SLEEP command JB ACC.4,NOVRAM_2 ; is this a write? JNB TI,$ ; YES, write out command CLR TI MOV SBUF,A JNB TI,$ ; wait for transmission to complete CLR TI MOV SBUF,data_low ; write LSB of data JNB TI,$ ; write out command CLR TI MOV SBUF,data_high ; write MSB of data JNB TI,$ ; wait for transmission to complete JMP NOVRAM_00 ; done NOVRAM_2: ; NO, must be a read JNB TI,$ ; write out command CLR TI MOV SBUF,A JNB TI,$ ; wait for transmission to complete CLR TI MOV data_high,SBUF ; put MSB data CLR RI JNB RI,$ ; wait for reception to complete MOV data_low,SBUF ; put LSB data CLR RI JNB RI,$ JMP NOVRAM_00 $eject ;****************************************************************************** WRITE_NOVRAM: ; R0 points to internal RAM to store. ; R2 contains number of bytes to store. ; R3 contains the starting address of the NOVRAM to store. SETB NOVRAM_enable ; select chip JNB TI,$ ; write out command CLR TI MOV SBUF,#WREN JNB TI,$ ; wait for transmission to complete CLR NOVRAM_enable ; deselect chip SETB NOVRAM_enable ; select chip WN_0: MOV A,#write ; assemble command ORL A,R3 JNB TI,$ ; YES, write out command CLR TI MOV SBUF,A JNB TI,$ ; wait for transmission to complete CLR TI MOV SBUF,@R0 ; write LSB of data JNB TI,$ ; CLR TI INC R0 DJNZ R2,WN_1 SJMP WN_2 WN_1: MOV SBUF,@R0 ; write MSB of data INC R0 DJNZ R2,WN_0 ; loop until done JNB TI,$ ; wait for transmission to complete WN_2: CLR NOVRAM_enable ; deselect chip RET ; and return $eject ;****************************************************************************** READ_NOVRAM: ; R0 points to internal RAM to fetch. ; R2 contains number of bytes to fetch. ; R3 contains the starting address of the NOVRAM to fetch. SETB NOVRAM_enable ; select chip RN_0: MOV A,#read ; assemble command ORL A,R3 JNB TI,$ ; YES, write out command CLR TI MOV SBUF,A JNB TI,$ ; wait for transmission to complete CLR TI MOV @R0,SBUF ; put MSB data CLR RI JNB RI,$ ; wait for reception to complete INC R0 DJNZ R2,RN_1 SJMP RN_2 RN_1: MOV @R0,SBUF ; put LSB data CLR RI JNB RI,$ INC R0 DJNZ R2,RN_0 ; loop until done JNB TI,$ ; wait for transmission to complete RN_2: CLR NOVRAM_enable ; deselect chip RET ; and return $eject ;****************************************************************************** RECALL_E2PROM: SETB NOVRAM_enable ; select chip JNB TI,$ ; write out command CLR TI MOV SBUF,#RCL JNB TI,$ ; wait for transmission to complete CLR NOVRAM_enable ; deselect chip RET ; and return ;****************************************************************************** STORE_E2PROM: SETB NOVRAM_enable ; select chip JNB TI,$ ; write out command CLR TI MOV SBUF,#WREN JNB TI,$ ; wait for transmission to complete CLR NOVRAM_enable ; deselect chip SETB NOVRAM_enable ; select chip JNB TI,$ ; write out command CLR TI MOV SBUF,#STO JNB TI,$ ; wait for transmission to complete CLR NOVRAM_enable ; deselect chip RET ; and return ;****************************************************************************** END