# Programming AT89LP52 microcontroller like an AT89S52

I'm trying to run my code on the new AT89LP52 chip which Microchip (A.k.a. Atmel) believes can be a direct replacement for the AT89S52.

I am able to program the AT89S52 with my programmer and software perfectly fine, and attempting to run that chip in the target board works perfectly fine as well. (Yes, I remove the chip from the programmer board to another board). Of course then I had two 33pF capacitors tied between the crystal connection points and ground.

So now, I tried the AT89S52. From observation, I'm able to write a large string of data (over 2KB) to the chip, I'm able to set fuse values, and I'm able to read a large string of data from the chip. but I can't seem to get it to execute code in the target board.

So I took the "may NOT need capacitors" line from the datasheet and removed the capacitors from my target board (since I'm always using a 22.1184Mhz crystal in the target board) and I tested again, and got no luck.

I'm starting to wonder if I'm injecting the data into the chip improperly. In the AT89S52, there is no half-page bit "s" but in AT89LP52, there is a half-page bit.

Here's pseudocode I use to program AT89S52 after its erased:

set count=0
For page starting with 0...
Output 50h
Output page
For block = 0 to 255
Output data_byte
increment count
if count > data length then end
next block
next page


Here's pseudocode I use to program AT89LP52 after its erased:

set count=0
For page starting with 0...
Output 50h
set mypage=page shifted left 6
Output integer value of mypage divided by 256
Output integer value of mypage mod 256
For block = 0 to 63
Output data_byte
increment count
if count > data length then end
next block
next page


Am I doing something wrong in programming the AT89LP52?

I added datasheet information to both microcontrollers for reference.

Update

I made use of the status byte during programming and for each set of 64 bytes I sent to the new AT89LP52, the results were success each time.

My pseudo code for that....

Output 60h
Output 0h
Output 0h