; Orange programmer module v1.11 ; (c) 2003-2011 Alex Plusov, Valentas ; CHIP=ST95021,256(16),ST95041.hpl ; CHIP=ST95041,512(16),ST95041.hpl ; Serial SPI EEPROM with Positive Clock Strobe ; Tested SOCKET=4 ;"SPI" PINO=SCK,0 ; Serial Clock PINO=SI,1 ; Serial Data Input PINO=CS,2 ; Chip Select PINO=WP,3 ; Write Protect PINO=HOLD,4 ; Hold PINI=SO,1 ; Serial Data Output ;Power pins: ;PINO=Vss,0,4; Ground ;PINO=Vcc,0,8; Supply Voltage CDELAY=1 ; one set delay R9=STATUS,B8 R10="Protect",L,"None,Upper 1/4,Upper 1/2,All" [_SEND] LOOP=(7,0){SI=R0[I],SCK=N} [INIT] HOLD=1 WP=0 CS=1 SCK=1 R10=0 [READ] CS=1 SCK=1 CS=0 LOOP=(12,8){SI=ADR[I],SCK=N} SI=0,SCK=N SI=1,SCK=N SI=1,SCK=N LOOP=(7,0){SI=ADR[I],SCK=N} SI=1 LOOP=(7,0){SCK=0,DATA[I]=SO,SCK=1} CS=1 [READBLOCK] CS=1 SCK=1 CS=0 LOOP=(12,8){SI=ADR[I],SCK=N} SI=0,SCK=N SI=1,SCK=N SI=1,SCK=N LOOP=(7,0){SI=ADR[I],SCK=N} SI=1 LOOP=($BLOCKSIZE){ LOOP=(7,0){SCK=0,DATA[I]=SO,SCK=1} ADR=+1 } CS=1 [_WAITWR] ; Wait for end write memory SCK=1 LOOP=(0,1000){ CS=0 _SEND(00000101b) ; Read Status Register SI=1 R3=0 LOOP=(7,0){SCK=0,R3[I]=SO,SCK=1} CS=1 R3[0]?0{BREAK} ; WIP bit = 0 ? P=10 } [WRITEINIT] HOLD=1 WP=1 ;enable CS=1 SCK=1 CS=0 _SEND(00000110b) ; Write enable CS=1 P=20 CS=0 _SEND(00000001b) ; Write Status Register _SEND(00000000b) ; Status Register CS=1 _WAITWR [WRITE] SCK=1 CS=0 _SEND(00000110b) ; Write enable CS=1 P=20 CS=0,SI=0 LOOP=(12,8){SI=ADR[I],SCK=N} SI=0,SCK=N SI=1,SCK=N SI=0,SCK=N LOOP=(7,0){SI=ADR[I],SCK=N} LOOP=(7,0){SI=DATA[I],SCK=N} CS=1 _WAITWR [WRITEBLOCK] R1=1 WP=1 SCK=1 CS=0 _SEND(00000110b) ; Write enable CS=1 P=20 CS=0,SI=0 LOOP=(12,8){SI=ADR[I],SCK=N} SI=0,SCK=N SI=1,SCK=N SI=0,SCK=N LOOP=(7,0){SI=ADR[I],SCK=N} LOOP=($BLOCKSIZE){ LOOP=(7,0){SI=DATA[I],SCK=N} ADR=+1 } CS=1 _WAITWR ["Read Status"] R9=0 HOLD=1 WP=1 SCK=1 CS=1 CS=0 _SEND(00000101b) ; Read Status Register SI=1 LOOP=(7,0){SCK=0,R9[I]=SO,SCK=1} CS=1 R9=/4,R9=&0x3,R10=R9 GET=("Protected area",R10) ["Write Status"] GET=("Select protection area",R10) RA?0{EXIT} R8=R10,R8=<<2 HOLD=1 WP=1 CS=1 SCK=1 CS=0 _SEND(00000110b) ; Write enable CS=1 P=20 CS=0 _SEND(00000001b) ; Write Status Register _SEND(R8) CS=1 P=20000 R9=0 SCK=1 CS=1 CS=0 _SEND(00000101b) ; Read Status Register SI=1 LOOP=(7,0){SCK=1,R9[I]=SO,SCK=0} CS=1 P=10 R9=&0xF VCC=0 R8?R9{PRINT=S("Status Register write OK !"),P=1000000,EXIT} R8?!R9{PRINT=E("Status Register write ERROR !")}