The programmer for the 89c51 chip, the picture is a bit small, just look at it, it comes with the program
program:
#include "at89x52.h"
#include "stdio.h"
#include "intrins.h"
#include "ctype.h"
sbit rdy=P3^2;
sbit vpp=P3^3;
sbit p26=P3^4;
sbit p27=P3^5;
sbit p36=P3^6;
sbit p37=P3^7;
sbit prog=P2^7;
void init_serial()
{
SCON=0x50; /*mode 1*/
TMOD=0x20;
TH1=0xfd;
PCON=0x80; /*38400bps*/
TR1=1; /*load tmr1*/
TI=1;
ES=1;}
void init_pro()
{
p26=0;
p27=0;
p36=0;
p37=0;
vpp=1;
prog=1;
}
void sendbyte(unsigned char da) /*send a byte*/
{
while(!TI);
TI=0;
SBUF=da;}
unsigned char IntToAscii(unsigned char a) /*change DEC to ASCII HEX code*/
{
if(a<10) return a+48;
if(a>9) return a+55;}
unsigned int getadr() /*get 5 diti DEC adr*/
{
unsigned char i,a[5];
for(i=0;i<5;i++)
{
while(!RI);
RI=0;
a[i]=SBUF-48;
}
return a[0]*10000+a[1]*1000+a[2]*100+a[3]*10+a[4];}
unsigned char getdata() /*get 2 diti HEX data*/
{
unsigned char d1,d2;
while(!RI);
RI=0;
d1=toint(SBUF);
while(!RI);
RI=0;
d2=toint(SBUF);
return d1*16+d2;}
unsigned int detchip(int adr)
{
P0=0xff;
P1=adr%256;P2=adr/256;
init_pro();
_nop_();_nop_();_nop_();_nop_();_nop_(); /*delay 10 us*/
_nop_();_nop_();_nop_();_nop_();_nop_();
return P0;}
void read()
{
unsigned int adr,maxadr;
unsigned char h,l;
P0=0xff;
maxadr=getadr();
for(adr=0;adr{
P1=adr%256;P2=adr/256;
p26=0;
p27=0;
p36=1;
p37=1;
vpp=1;
prog=1;
h=IntToAscii(P0/16);
sendbyte(h);
l=IntToAscii(P0%16);
sendbyte(l);}
init_pro();}
unsigned int test(unsigned int nn)
{
unsigned int adr,counter=0;
P0=0xff;
for(adr=0;adr{
P1=adr%256;P2=adr/256;
p26=0;
p27=0;
p36=1;
p37=1;
vpp=1;
prog=1;
_nop_();_nop_();_nop_();_nop_();_nop_(); /*delay 10 us*/
_nop_();_nop_();_nop_();_nop_();_nop_();
if(P0!=0xff) counter++;}
init_pro();
return counter;}
unsigned char erase(unsigned int nn,unsigned int p)
{
unsigned int i;
P0=0xff;
p26=1;
p27=0;
p36=0;
p37=0;
vpp=0;
prog=1;
for(i=0;i<50000;i++) _nop_();
switch(p)
{
case 0 : prog=0;
prog=1;
break;
case 1 : prog=0;
_nop_();
prog=1;
break;
case 2 : prog=0;
_nop_();_nop_();
prog=1;
break;
case 3 : prog=0;
_nop_();_nop_();_nop_();
prog=1;
break;
case 4 : prog=0;
_nop_();_nop_();_nop_();_nop_();
prog=1;
break;
case 5 : prog=0;
_nop_();_nop_();_nop_();_nop_();_nop_();
prog=1;
break;
case 6 : prog=0;
_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();
prog=1;
break;
case 7 : prog=0;
_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();
prog=1;
break;
case 8 : prog=0;
_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();
prog=1;
break;
default: prog=0;
for(i=0;i
prog=1;
break;}
_nop_();_nop_();_nop_();_nop_();
_nop_();_nop_();_nop_();_nop_();
vpp=1;
for(i=0;i
if(test(nn)==0) return 's';
else return 'f';}
unsigned char write()
{
unsigned int adr,d,i;
p26=0;
p27=1;
p36=1;
p37=1;
vpp=0;
prog=1;
for(i=0;i<4000;i++) _nop_();
adr=getadr();
d=getdata();
while(1)
{
if(adr>50000) break;
P1=adr%256;P2=(adr/256)|0x80;
P0=d;
TI=0;
SBUF='s';
prog=0;
_nop_();_nop_();_nop_();
prog=1;
adr=getadr();
d=getdata();
while(!rdy);}
init_pro();
return 'f';}
unsigned char lock(unsigned char level)
{
unsigned int i;
vpp=0;
if(level==1) {p26=1;p27=1;p36=1;p37=1;}
if(level==2) {p26=1;p27=1;p36=0;p37=0;}
if(level==3) {p26=1;p27=0;p36=1;p37=0;}
for(i=0;i<4000;i++) _nop_();
prog=1;
_nop_();_nop_();_nop_();_nop_();_nop_(); /*delay 10 us*/
_nop_();_nop_();_nop_();_nop_();_nop_();
prog=0;
_nop_();_nop_();_nop_();_nop_();_nop_(); /*delay 10 us*/
_nop_();_nop_();_nop_();_nop_();_nop_();
prog=1;
_nop_();_nop_();_nop_();_nop_();_nop_();
while(!rdy);
init_pro();
return 'o';}
void main()
{
unsigned char data c;
unsigned int data adr,l,dx;
init_pro();
init_serial();
while(1)
{
init_pro();
scanf("%c",&c);
switch(c)
{
case 'c' : printf("%c",'o');
break;
case 'd' : scanf("%x",&adr);
printf("%x",detchip(adr));
break;
case 't' : scanf("%u",&dx);
printf("%u",test(dx));
break;
case 'r' : read();
break;
case 'e' : scanf("%u,%u",&adr,&dx);
printf("%c",erase(adr,dx));
break;
case 'w' : printf("%c",write());
break;
case 'l' : scanf("%u",&l);
printf("%c",lock(l));
break;
case 'h' : printf("**********Er6y Programmer Help Window***********n");
break;
default : break;}
}
}
Schematic:
Previous article:Application circuit based on 89C51 and 82C53 to control TA8435H
Next article:Interface circuit between X25165 and 89C51
- Popular Resources
- Popular amplifiers
- 西门子S7-12001500 PLC SCL语言编程从入门到精通 (北岛李工)
- Siemens Motion Control Technology and Engineering Applications (Tongxue, edited by Wu Xiaojun)
- How to read electrical control circuit diagrams (Classic best-selling books on electronics and electrical engineering) (Zheng Fengyi)
- MCU C language programming and Proteus simulation technology (Xu Aijun)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- Several issues on key-controlled 8X8LED dot matrix screen displaying graphics program
- FAQ: PolarFire SoC FPGA Secure Boot | Microchip Security Solutions Seminar Series 12
- Some Problems on Measuring AC Current with Current Transformer
- Simulation of staying up late is harmful to health
- [RVB2601 Creative Application Development] + RTC Clock Display Experiment
- From traditional substation to smart substation
- [Raspberry Pi Pico Review] Xiaohui Review
- ST sensor evaluation platform STEVAL_MKI109V3 development board
- Analog Circuit Design Handbook: Advanced Application Guide
- How do you spend the May Day holiday?