Engineers Garage

  • Electronics Projects and Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Audio Electronics
      • Battery Management
      • Brainwave
      • Electric Vehicles
      • EMI/EMC/RFI
      • Hardware Filters
      • IoT tutorials
      • Power Tutorials
      • Python
      • Sensors
      • USB
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
    • DesignFast
  • Guest Post Guidelines
  • Advertise
  • Subscribe

AT89S51/52 ISP Programmer – Memory Write

By Himanshu Choudhary December 27, 2011

This tutorial explains how to write the content in the microcontroller’s flash memory. The source microcontroller writes some values in the memory of the target microcontroller. The values that have been written can be checked by reading the buffer of the target microcontroller using a programmer. The values are nothing but the machine language instruction written in the hex file generated by a compiler.
The reader should know the basics of sending and receiving the single byte in programming mode. Refer to 8051 Programmer basics before reading this project.
There are two modes of writing values in a microcontroller. The table below shows the instruction corresponding to memory write operation. In case of write operation the memory needs to be erased first.
Circuit Diagram of 8051 Programmer

 Fig. 1: Circuit Diagram of 8051 Programmer

4. Byte Mode

In this mode the values are written one by one. You need to send the address of the memory location in every instruction whose value is to be written. The first byte of the instruction signifies memory write operation (byte mode). The second and third byte tells the address of the memory location. Some bits of the second byte are don’t care. This is because the maximum size of flash memory for this family is 8K and in order to address the last memory location a maximum of 13 bits is required. The fourth byte contains the data which is to be written in the specified memory location of the target microcontroller.
 
2. Page mode
The memory of the microcontroller is arranged in form of pages. Every page contains 256 bytes arranged in 16 rows and 16 columns. In this mode a chunk of 256 bytes is written in one write instruction. The second byte of the instruction sends the address of the page where the data needs to be written. The 256 bytes of data is sent consecutively from the third byte of the instruction. No instruction is accepted till 265 data bytes are written.
 

Circuit and Algorithm

Circuit Diagram

Circuit Diagram of 8051 Programmer

 Fig. 2: Circuit Diagram of 8051 Programmer

Algorithm
Algorithm for Byte mode:
1.      Power on the circuit.
2.      Send the instruction for programming enable.
3.      Check the 4th byte on MISO pin. If we receive 0x69 this means chip is enabled.
4.      If the serial programming mode is enabled then send the chip erase instruction.
5.      Send the instruction corresponding to memory write (byte mode). It should have the address and data to be written.
6.      Keep repeating step 5 till all the bytes are written in the target microcontroller. 
 
Algorithm for Page write mode:
1.      Power on the circuit.
2.      Send the instruction for programming enable.
3.      Check the 4th byte on MISO pin. If we receive 0x69 this means chip is enabled.
4.      If the serial programming mode is enabled then send the chip erase instruction.
5.      Send first byte to enable page write mode followed by the address of the page.
6.      After the address bytes the 256 data bytes of data is sent on the MOSI pin.
7.      Keep repeating step 6 till all the pages you want to write are written.
 

Code

Code
The following code is used to write the bytes in the memory of the controller which are verified using a programmer. This code writes four bytes using the byte mode.

#include <REG51.h>
#include<intrins.h>
#define port P1

sbit sck=port^0;
sbit res=port^3;
sbit miso=port^1;
sbit mosi=port^2;

bit bit1;
unsigned int i,bitno=0;
unsigned char a,b,c,d;
void delay(unsigned int msec)   // Function for delay
{
	int i,j;
	for(i=0;i<msec;i++)
		for(j=0;j<1275;j++);
}

void sendbit()
{
	mosi=bit1;
	delay(1);
	_nop_();
	sck=1;
	delay(1);
	_nop_();
	sck=0;
}

void sendbyte(unsigned char m)
{
	for(bitno=0;bitno<8;bitno++)
	{
		bit1=m/128;
		m=m<<1;
		sendbit();
	}
}

void main()
{
	i=0;
	sck=0;
	res=1;
	delay(500);

//=======Program enable===========

	a=0xac;
	b=0x53;
	c=0x00;
	d=0x11;
	sendbyte(a);
	sendbyte(b);
	sendbyte(c);
	sendbyte(d);

//==========Erase==================

	a=0xac;
	b=0x82;
	c=0x12;
	d=0x13;
	sendbyte(a);
	sendbyte(b);
	sendbyte(c);
	sendbyte(d);

//===========write=================

	sendbyte(0x40);
	sendbyte(0x00);
	sendbyte(0x00);
	sendbyte(0xEE);

	sendbyte(0x40);
	sendbyte(0x00);
	sendbyte(0x01);
	sendbyte(0x12);

	sendbyte(0x40);
	sendbyte(0x00);
	sendbyte(0x02);
	sendbyte(0x5C);

	sendbyte(0x40);
	sendbyte(0x00);
	sendbyte(0x03);
	sendbyte(0xAB);

	res=1;
	while(1);
}


Filed Under: Tutorials
Tagged With: 8051, isp, memory write circuit & code, microcontroller
 

Next Article

← Previous Article
Next Article →

Questions related to this article?
👉Ask and discuss on EDAboard.com and Electro-Tech-Online.com forums.



Tell Us What You Think!! Cancel reply

You must be logged in to post a comment.

EE TECH TOOLBOX

“ee
Tech Toolbox: Internet of Things
Explore practical strategies for minimizing attack surfaces, managing memory efficiently, and securing firmware. Download now to ensure your IoT implementations remain secure, efficient, and future-ready.

EE Learning Center

EE Learning Center
“engineers
EXPAND YOUR KNOWLEDGE AND STAY CONNECTED
Get the latest info on technologies, tools and strategies for EE professionals.

HAVE A QUESTION?

Have a technical question about an article or other engineering questions? Check out our engineering forums EDABoard.com and Electro-Tech-Online.com where you can get those questions asked and answered by your peers!


RSS EDABOARD.com Discussions

  • Audio Switching
  • Transistor circuit in audio
  • Parametric Analysis in Cadence Virtuoso IC23.1
  • MCU identification?
  • GanFet power switch starts burning after 20 sec

RSS Electro-Tech-Online.com Discussions

  • stud mount Schottky diodes
  • LED circuit for 1/6 scale diorama
  • Can I use this charger in every country?
  • Electronic board faulty?!?
  • using a RTC in SF basic

Featured – Designing of Audio Amplifiers part 9 series

  • Basics of Audio Amplifier – 1/9
  • Designing 250 Milli Watt Audio Power Amplifier – 2/9
  • Designing 1 Watt Audio Power Amplifier – 3/9
  • Designing a Bass Boost Amplifier – 4/9
  • Designing a 6 Watt Car Audio Amplifier – 5/9
  • Design a low power amplifier for headphones- 6/9

Recent Articles

  • Fischer connector system adds ratchet locking system designed for 300g shock resistance
  • Littelfuse introduces tactile switch with enhanced bracket peg design for mounting strength
  • Infineon releases GaN switch with monolithic bidirectional design
  • Sienna Semiconductor data converters feature sample rates from 20 to 250 Msps
  • Delta’s 5,500 W power supplies achieve 97.5% energy efficiency for AI servers

EE ENGINEERING TRAINING DAYS

engineering

Submit a Guest Post

submit a guest post
Engineers Garage
  • Analog IC TIps
  • Connector Tips
  • Battery Power Tips
  • DesignFast
  • EDABoard Forums
  • EE World Online
  • Electro-Tech-Online Forums
  • EV Engineering
  • Microcontroller Tips
  • Power Electronic Tips
  • Sensor Tips
  • Test and Measurement Tips
  • 5G Technology World
  • Subscribe to our newsletter
  • About Us
  • Contact Us
  • Advertise

Copyright © 2025 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy

Search Engineers Garage

  • Electronics Projects and Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Audio Electronics
      • Battery Management
      • Brainwave
      • Electric Vehicles
      • EMI/EMC/RFI
      • Hardware Filters
      • IoT tutorials
      • Power Tutorials
      • Python
      • Sensors
      • USB
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
    • DesignFast
  • Guest Post Guidelines
  • Advertise
  • Subscribe