; Orange programmer module v2.5 ; (c) 2005 CnCLab ; Atmel AT89S5X ; CHIP=AT89S51,4K,89S52.HPL ; CHIP=AT89S52,8K,89S52.HPL ; tested S51, S52 ; S53 have another protocol! ; Atmel Errata Sheet ;The following are known problems with Rev. D of the AT89S51/AT89S52 E.S. ;(Engineering Sample) devices: ;1. Serial (In-System) Programming ;In the Serial Programming mode, there is a need for over-programming in the byte ;mode (up to 10 times per byte); page mode is not functional. ;2. In the Serial Programming mode ;Activating the lock bits does not prevent MOVC from reading out internal code ;memory bytes. ALLPINS=40 INFO="AT89S (SPI Mode)" ;PINO=SCK, 9,9 ;PINO=MISO, 0,8 ;PINO=MOSI, 11,7 ;PINO=RESET,10,10 ;PINI=MISO, 4,8 ; AT89S Adapter PINO=SCK, 0,8 PINO=MOSI, 2,6 PINO=MISO, 1,7 PINO=RESET,3,9 PINI=MISO, 1,7 PINO=XTAL1,12,19 PING=GND,255,20 PINO=VCC,254,40 BUSO=CFREQ,128 ;R9=LOCK,C3 ;R9=LOCK,H R9=Lock,L,"MODE1: Off,MODE2: No Prog,MODE3: No Verify,MODE4: All" CDELAY=5 ; minimum periods for the serial clock (SCK) > 4 XTAL1 clock cycle! [_DOUT] R1=0 LOOP=(7,0){MOSI=R0[I],SCK=1,R1[I]=MISO,SCK=0} [_DIN] R0=0 LOOP=(7,0){SCK=1,R0[I]=MISO,SCK=0} [INIT] ;EO=0,P=10 ;BB on CFREQ=4000000 SCK=0 MISO=Z RESET=0,P=2000 RESET=1,P=20000 ;LOOP=(0,31){ ; 32 attempts _DOUT(0xAC) ;Programming Enable _DOUT(0x53) _DOUT(0x00) _DIN R0?!0x69{PRINT=("ANSWER ERROR: %02lX",R0),EXIT} P=10 [READ] _DOUT(0x20) ;read CODE memory R0=ADR,R0=/256,_DOUT R0=ADR,R0=&0xFF,_DOUT _DIN DATA=R0 [WRITE] R0=DATA,R0?0xFF{RETURN} _DOUT(0x40) ;write CODE memory R0=ADR,R0=/256,_DOUT R0=ADR,R0=&0xFF,_DOUT R0=DATA,_DOUT P=6000 ; 4ms [WRITEEND] P=20000 RESET=1,P=20, RESET=0,P=20000 [ERASE] _DOUT(0xAC) ;Chip Erase _DOUT(0x80) _DOUT(0x00) _DOUT(0x00) P=600000 RESET=1,P=20, RESET=0,P=20000 ["Read Lock"] _DOUT(0x24) _DOUT(0x00) _DOUT(0x00) _DIN PRINT=S("LOCK RD BYTE =%02lX",R0) R0=/4 R0=&7 ;a programmed lock bit reads back as a "1" R9=0 R0[0]?1{R9=+1} R0[1]?1{R9=+1} R0[2]?1{R9=+1} GET=("Lock Bits",R9) ["Write Lock"] GET=("Set Lock Bits",R9) RA?0{EXIT} R9?>0{ _DOUT(0xAC) ;Write Lock Bit 1 _DOUT(0xE1) _DOUT(0x00) _DOUT(0x00) } P=20000 R9?>1{ _DOUT(0xAC) ;Write Lock Bit 2 _DOUT(0xE2) _DOUT(0x00) _DOUT(0x00) } P=20000 R9?>2{ _DOUT(0xAC) ;Write Lock Bit 3 _DOUT(0xE3) _DOUT(0x00) _DOUT(0x00) } P=20000 ;RESET=1,P=20, ;RESET=0,P=20000 ["Read ID"] _DOUT(0x28) ;read ID _DOUT(0x00) _DOUT(0x00) _DIN R1=R0 _DOUT(0x28) ;read ID _DOUT(0x01) _DOUT(0x00) _DIN R2=R0 _DOUT(0x28) ;read ID _DOUT(0x10) _DOUT(0x00) _DIN R3=R0 ;R2?11H{PRINT=("Signature bytes = %02lX %02lX %02lX - 89C1051",R1,R2,R3),EXIT} ;R2?21H{PRINT=("Signature bytes = %02lX %02lX %02lX - 89C2051",R1,R2,R3),EXIT} ;R2?41H{PRINT=("Signature bytes = %02lX %02lX %02lX - 89C4051",R1,R2,R3),EXIT} PRINT=("Signature bytes : %02lX %02lX %02lX",R1,R2,R3) [END] RESET=1 ;EO=1,P=10 ;BB off