Area : ‚áâ஥­­ë¥ á¨á⥬ë Date : Thu Mar 11, 17:38 From : Vladimir L Vasilevsky 2:5020/211.60 To : Aleksandr Butko Subj : W/R on 93C46 ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ Hello Aleksandr! AB> •®â¥«®áì ¯®á¬®âà¥âì ¯à¨¬¥àë ªã᪮¢ ¤«ï ç⥭¨ï/§ ¯¨á¨ ¢ 93C46 ¤«ï AB> 80C31/89C2051. ‚®â ªã᮪ ¨§ à ¡®ç¥© ¯à®£à ¬¬ë: (c) Youry Khapochkin ;==================================================================== ; Read byte from EEPROM by address in B and put result to the ACC ; ; change R2 and R3R4 - Word by location ADDR/2 ; Read_EEPROM: mov A,B rrc A anl A,#00111111b ; mask bit not used in address orl A,#10000000b ; opcode of READ inctruction push IE clr ET2 ; Disable Task switching setb CS_EEPROM ; enable operation lcall Write_Cmd_EEPROM orl SEPCON,#00010000b ; set SEPREN Read_EE_W1: mov A,SEPSTAT jnb ACC.0,Read_EE_W1 mov SEPSTAT,#0 mov R3,SEPDAT orl SEPCON,#00010000b ; set SEPREN Read_EE_W2: mov A,SEPSTAT jnb ACC.0,Read_EE_W2 mov SEPSTAT,#0 mov R4,SEPDAT clr CS_EEPROM pop IE ; Restore Task-Switch status mov A,R3 jb B.0,Read_EE_Even mov A,R4 Read_EE_Even: ret ;==================================================================== ; Write command to the EEPROM (MUST be followed by Data) ; Write_Cmd_EEPROM: push ACC OutSEP #00000001b pop ACC OutSEP A ret ;==================================================================== ; Write Byte in ACC to the EEPROM on address B ; change R2,R3,R4,R5 ; Write_EEPROM: push IE clr ET2 ; Disable Task switching mov R5,A lcall Read_EEPROM clr CS_EEPROM setb CS_EEPROM mov A,#00110000b ; Erase Write ENable command lcall Write_Cmd_EEPROM clr CS_EEPROM setb CS_EEPROM mov A,B rrc A anl A,#00111111b ; Extract Address bits only orl A,#01000000b ; WRITE command lcall Write_Cmd_EEPROM mov A,R5 jb B.0,Write_EE_Even mov R4,A sjmp Write_EE_Odd Write_EE_Even: mov R3,A Write_EE_Odd: OutSEP R3 OutSEP R4 clr CS_EEPROM setb CS_EEPROM clr CS_EEPROM clr C pop IE ; Restore Task switching status ret ;===================================================================== Vladimir --- -- ------------------------------ -- * Origin: ਠ90 £à ¤ãá å ª¨¯¨â ¯àאַ© 㣮«... (2:5020/211.60) Area : ‚áâ஥­­ë¥ á¨á⥬ë Date : Thu Mar 11, 19:40 From : Vladimir L Vasilevsky 2:5020/211.60 To : Aleksandr Butko Subj : W/R on 93C46 ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ Hello Aleksandr! AB> •®â¥«®áì ¯®á¬®âà¥âì ¯à¨¬¥àë ªã᪮¢ ¤«ï ç⥭¨ï/§ ¯¨á¨ ¢ 93C46 ¤«ï AB> 80C31/89C2051. à®èã ¯ à¤®­ã. ।ë¤ã騥 ¯à®æ¥¤ãàë ¡ë«¨ ¤«ï 8051GB á  ¯¯ à â­ë¬ SPI. ‚®â "¯à ¢¨«ì­ ï" ¢¥àá¨ï: (c) Youry Khapochkin Read_EEPROM: push IE clr ET2 ;disable Task Switching clr SCLK mov A,B rrc A anl A,#00111111b ; mask bit not used in address orl A,#10000000b ; opcode of READ inctruction setb CS_EEPROM ; enable operation lcall Write_Cmd_EEPROM mov R2,#16 Read_EE_Read_Word: setb SCLK ; clock CLK clr SCLK mov C,SDAT ; read next bit mov A,R4 ; shift word in R4R5 rlc A mov R4,A mov A,R3 rlc A mov R3,A djnz R2,Read_EE_Read_Word clr CS_EEPROM mov A,R3 jb B.0,Read_EE_Even mov A,R4 Read_EE_Even: pop IE ret ;-------------------------------------------------------------------- ; ; seg code Write_Cmd_EEPROM setb C mov R2,#9 Write_Cmd_EEPROM_Loop mov SDAT,C ; write next bit setb SCLK ; clock CLK clr SCLK rlc A djnz R2,Write_Cmd_EEPROM_Loop setb SDAT ret ;-------------------------------------------------------------------- ; Write Byte in ACC to the EEPROM on address B ; change R2,R3,R4,R5 ; seg code Write_EEPROM: push IE clr ET2 push ACC lcall Read_EEPROM clr CS_EEPROM setb CS_EEPROM mov A,#00110000b ; EraseWriteENable command lcall Write_Cmd_EEPROM clr CS_EEPROM setb CS_EEPROM mov A,B rrc A anl A,#00111111b ; extract Address bits only orl A,#01000000b ; WRITE command lcall Write_Cmd_EEPROM pop ACC jb B.0,Write_EE_Even mov R4,A sjmp Write_EE_Odd Write_EE_Even: mov R3,A Write_EE_Odd: mov R2,#16 Write_EE_Read_Word: mov A,R4 ; shift word in R3R4 rlc A mov R4,A mov A,R3 rlc A mov R3,A mov SDAT,C ; write next bit setb SCLK ; clock CLK clr SCLK djnz R2,Write_EE_Read_Word clr CS_EEPROM setb SDAT ;!! setb CS_EEPROM pop IE Delay 20 ; jnb SDAT,Write_EE_ERROR ; check for time! ; clr C ; sjmp Write_EE_End ; ;Write_EE_ERROR: ; setb C ;Write_EE_End: ; clr CS_EEPROM clr C ret ;==================================================================== Vladimir --- -- ------------------------------ -- * Origin: ਠ90 £à ¤ãá å ª¨¯¨â ¯àאַ© 㣮«... (2:5020/211.60)